Companies
A Company is a specific instance of a company or a division for the owner of the tenant. Many companies divide their business into more than one entity and therefore it is necessary to identify what entity we are calling.
To find that out it is best to query the standard BC API endpoint for companies with a GET request to an URL like this:
https://api.businesscentral.dynamics.com/v2.0/{TenantId}/{Environment}/api/v2.0/companies
Resulting payload
{
"@odata.context": "https://api.businesscentral.dynamics.com/v2.0/b9559d9b-8fc8-4233-b617-00a14ef0a761/SalesAndConsulting/api/v2.0/$metadata#companies",
"value": [
{
"id": "3a5e78bc-8efc-ee11-a1fd-002248994096",
"systemVersion": "24.5.23489.23968",
"timestamp": 705979,
"name": "ABU Shopify",
"displayName": "ABU Shopify",
"businessProfileId": "",
"systemCreatedAt": "2024-04-17T07:47:28.287Z",
"systemCreatedBy": "43c90808-9f39-476f-91fa-ae79f3bc0232",
"systemModifiedAt": "2024-04-17T07:50:16.17Z",
"systemModifiedBy": "43c90808-9f39-476f-91fa-ae79f3bc0232"
},
{
"id": "62f9adea-b7f5-ee11-a1ff-000d3ade448a",
"systemVersion": "24.5.23489.23968",
"timestamp": 605583,
"name": "ABU Test",
...
...
The company should be identified by it’s name and then the “id” value is used to identify the company for later API requests.
C# Example using the GetToken() function from the Tokenpage
HttpClient client = new HttpClient();
bearerToken = TokenHelper.GetToken();
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + bearerToken);
var url = "https://api.businesscentral.dynamics.com/v2.0/{TenantId}/{Environment}/api/v2.0/companies";
var res = await client.GetAsync(url);
if (res.IsSuccessStatusCode)
{
Console.WriteLine(await res.Content.ReadAsStringAsync());
}
else
{
Console.WriteLine(res.StatusCode.ToString());
}