How to create a new account for a legal entity using CreateAccounts, GetPersons and GetAccountTypes
One of the most basic things you probably want to accomplish using the BFS API is to create a new account in BFS for a certain user. In this blog post I will demonstrate how to accomplish this given a few circumstances.
In order to use CreateAccounts you need to provide three inputs:
- Owner (this is the GUID, unique ID of the Legal Entity who should own the account)
- AccountTypeKey (this is a unique string value representing a certain account type)
- BaseCurrencyCode (this tells BFS which currency to use to calculate performance for the account among other things)
Obviously the first problem to solve is getting the unique ID for the Legal Entity. Unique ID's in BFS are called BrickId's. At the time of this writing there is no way to view the BrickId for a LegalEntity in BFS (this is being added shortly) so the only way to do this is via the API method GetPersons.
In my instance of BFS I have a default user with username bnuser and I would like to get the BrickId of this user via GetPersons, see code below.
var client = new BFSServiceReference.bfsapiSoapClient(); var credentials = new BFSServiceReference.Credentials() { UserName = bfsusername, //Username of administrative user in your instance of BFS Password = bfspassword, //Password of the administrative user in your instance of BFS }; var persons = client.GetPersons(new BFSServiceReference.GetPersonRequest() { Credentials = credentials, identify = bfsidentifier, //Identifier is a unique token for your instance of BFS Args = new BFSServiceReference.GetPersonArgs() { UserName = "bnuser", }, Fields = new BFSServiceReference.GetPersonFields() { BrickId = true, UserName = true, FirstName = true, LastName = true, }, }); foreach (var c in persons.Result) { Console.WriteLine(c.BrickId + "," + c.FirstName + "," + c.LastName); }
I now have the BrickId for the user with username "bnuser" and now I need the AccountTypeKey. This I can find within the GUI of BFS by navigating to SystemData->AccountTypes.
The alternative is to get this using the API method GetAccountTypes with the code below.
//Use the GetAccountTypes method to get all AccountTypes in the BFS instance and write //the information in the console var client = new BFSServiceReference.bfsapiSoapClient(); var credentials = new BFSServiceReference.Credentials() { UserName = bfsusername, //Username of administrative user in your instance of BFS Password = bfspassword, //Password of the administrative user in your instance of BFS }; var accounttypes = client.GetAccountTypes(new BFSServiceReference.GetAccountTypeRequest() { Credentials = credentials, identify = bfsidentifier, //Identifier is a unique token for your instance of BFS Fields = new BFSServiceReference.GetAccountTypeFields() { BrickId = true, Key = true, }, }); foreach (var c in accounttypes.Result) { Console.WriteLine(c.BrickId + "," + c.Key); }
83adad04-02db-4dae-a5da-50b15d5fedbc,CapitalInsuranceAccount 95e3bf07-3f18-4f35-9365-1a8339493e78,HouseAccountingAccount 9c296549-41c9-4aef-bd48-e9602584f098,IPSAccount 2848b95f-8bf4-462e-8db3-2020f049e184,HouseSystemAccount 4d639562-1234-4b05-ba97-f4da03542278,HoldingAccount 20af188c-f6be-4fb7-9ae1-9d579143ea32,InheritedIRAAccount 8364af96-6a26-45a9-8e8e-3a3eaf91029e,FundAccount bc610399-c33f-4681-a443-8886947692d8,ISKAccount f2fa06d2-ff2c-4d4a-9a21-cb77157f41c3,CounterpartyAccount cdc125ed-78c6-41a0-b385-f253144539ed,HouseCustodyAccount
For the currency code I will navigate to System Data -> Currencies in the GUI of BFS to see what currencies are available.
I will use SEK as my currency of choice.
With the code below I will create the new account and write the returned account number in the console.
//Create a new account with the CreateAccount method var client = new BFSServiceReference.bfsapiSoapClient(); var credentials = new BFSServiceReference.Credentials() { UserName = bfsusername, //Username of administrative user in your instance of BFS Password = bfspassword, //Password of the administrative user in your instance of BFS }; var response = client.CreateAccounts(new BFSServiceReference.CreateAccountRequest() { Credentials = credentials, identify = bfsidentifier, //Identifier is a unique token for your instance of BFS Entities = new[] { new Account() { AccountTypeKey = "HoldingAccount", Owner = bnuserbrickid, OwnerAccountLabel = "Test", BaseCurrencyCode = "SEK", ExternalReference = "123456789", AccountStatus = 1, RequestReference = "My system reference" } } }); foreach (var c in response.Entities) { Console.WriteLine(c.AccountNo); }
10000685
And this is how it looks in BFS.
Related pages
Terms of License
Change Policy
© 2009 - 2024 Huddlestock Technologies AB All rights reserved