Skip to main content
Business Central forum
Suggested answer

Multi-tenant application's API to access Dynamics 365 Business Central company.

editSubscribe (1) ShareShare
ReportReport
Posted on by 2
I need to get the API response for a business central company using the multi-tenant app's client ID, and secret key.
I tried the below OAuth API to get the company's response. But I got the message as a bad request.
 
using (HttpClient client1 = new HttpClient())
{
    string companiesEndpoint = https:/api.businesscentral.dynamics.com/v2.0/organizations//+environment_name+/api/v2.0/companies/;
    string Access_Token = Session[/BCAccessToken/].ToString();
    client1.DefaultRequestHeaders.Add(/Authorization/, /Bearer / + Access_Token);
    HttpResponseMessage response1 = await client1.GetAsync(companiesEndpoint);
    if (response1.IsSuccessStatusCode)
    {
        string jsonResponsevalue = await response1.Content.ReadAsStringAsync();
        var Items = JsonConvert.DeserializeObject<dynamic>(jsonResponsevalue);
        JArray signItemtoken1 = (JArray)Items[/value/];
        foreach (var response in signItemtoken1)
        {
            string ComapnyName = response[/name/] != null ? (string)response[/name/] : //;
            string CompanyID = response[/id/] != null ? (string)response[/id/] : //;                                            
            if (ComapnyName == company_name)
            {
                Session[/BCCompanyName/] = CompanyName;
                Session[/BCCompanyId/] = CompanyID;
            }
        }                                            
    }
}
 
How to call an API to get company details or items from Dynamics 365 Business Central?
Attachments
  • gdrenteria Profile Picture
    gdrenteria 2,743 Super User on at
    Multi-tenant application's API to access Dynamics 365 Business Central company.
  • Suggested answer
    Nitin Verma Profile Picture
    Nitin Verma 20,984 Super User on at
    Multi-tenant application's API to access Dynamics 365 Business Central company.
    Are you facing any error?
     

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,080 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 222,601 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans