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);
}
}