Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested answer

Multi-tenant application for external tenants API to access Dynamics 365 Business Central company.

(1) ShareShare
ReportReport
Posted on by 8
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;
            }
        }                                            
    }
}

Response:
{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
  Access-Control-Allow-Headers: Origin, X-Requested-With, Authorization
  Access-Control-Allow-Origin: *
  Access-Control-Allow-Credentials: true
  ms-correlation-x: 516b7540-449c-2272-8895-d17e7e9fc0a7
  mise-correlation-id: 7d028162-108e-4ea6-b35c-eab9850c4561
  x-content-type-options: nosniff
  Strict-Transport-Security: max-age=31536000; includeSubDomains
  Access-Control-Expose-Headers: ms-correlation-x
  Date: Tue, 20 Feb 2024 11:27:16 GMT
  Server: Microsoft-HTTPAPI/2.0
  Content-Length: 79
  Content-Language: en-US
  Content-Type: application/json
}}


How to call an API to get company details or items from Dynamics 365 Business Central?
  • Suggested answer
    YUN ZHU Profile Picture
    79,044 Super User 2025 Season 1 on at
    Multi-tenant application for external tenants API to access Dynamics 365 Business Central company.
    Hi, are you able to Get to the data in the API in Postman? Using Postman you can verify that there is no problem with your OAuth settings.
    More details: 
    Using OAuth to connect Business Central APIs and Web Service in Postman
     
    Hope this helps.
    Thanks.
    ZHU
  • Suggested answer
    Nitin Verma Profile Picture
    21,435 Moderator on at
    Multi-tenant application for external tenants API to access Dynamics 365 Business Central company.
    Hi,
    have you added this app id in BC "Entra Application? and given consent?
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,129 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,895 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans