web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Which tenant ID do I have to use to get tokens and API responses using OAuth for external tenants?

(1) ShareShare
ReportReport
Posted on by 8
I am trying to get external tenant's company data from the business central.
I am able to generate access token and get the company response from the OAuth API for external tenant login. (Here I have used the App's tenant ID so it gets the app tenant company file)
I need to get the external tenants company file. Is there any API changes in the API using the external tenants ID (which is under 'help & suppot' in the business central).
 
Is there any changes in the below API if I need to get the response for external tenant?
 
 string accessToken = string.empty;
 using (HttpClient client = new HttpClient())
 {
     string tokenEndpoint = https://login.microsoftonline.com// + tenant_Id + //oauth2/v2.0/token/;
     var tokenRequestContent = new FormUrlEncodedContent(new[]
     {
         new KeyValuePair<string, string>(/grant_type/, /authorization_code/),
         new KeyValuePair<string, string>(/code/, code),
         new KeyValuePair<string, string>(/client_id/, client_Id),
         new KeyValuePair<string, string>(/client_secret/, client_secret),
         new KeyValuePair<string, string>(/redirect_uri/, redirectUri),
         new KeyValuePair<string, string>(/scope/, /openid offline_access/),
     });
     HttpResponseMessage responseval = await client.PostAsync(tokenEndpoint, tokenRequestContent);
     if (responseval.IsSuccessStatusCode)
     {
        string jsonResponse = await responseval.Content.ReadAsStringAsync();
        dynamic json = JObject.Parse(jsonResponse);
        accessToken = json.access_token != null ? json.access_token : //;
     }
 }

  using (HttpClient client1 = new HttpClient())
  {
      string companiesEndpoint = /      https:/api.businesscentral.dynamics.com/v2.0// + tenant_Id + //Production/api/v2.0/companies/;
      string Access_Token = accessToken.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);
      }
  }
  • Suggested answer
    Mohana Yadav Profile Picture
    61,252 Super User 2026 Season 2 on at
    string companiesEndpoint = /      https:/api.businesscentral.dynamics.com/v2.0// + tenant_Id + //Production/api/v2.0/companies/;
     
    Did you by any chance miss another / after https:?
  • Gerardo Rentería García Profile Picture
    27,623 Super User 2026 Season 2 on at
  • Suggested answer
    YUN ZHU Profile Picture
    103,829 Super User 2026 Season 2 on at
    Hi, hope the following helps as well.
     
     
    Thanks.
    ZHU

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 728 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 545 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 328 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans