web
You’re offline. This is a read only version of the page.
close
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

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);
      }
  }
I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,001 Super User 2025 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
    25,225 Most Valuable Professional on at
  • Suggested answer
    YUN ZHU Profile Picture
    95,595 Super User 2025 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,010

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,270 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,085 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans