
Hi,
I am trying to form GET request for retrieving "customers" entity data, but I get different errors such as 'Unauthorized' (401), 'Not found' (404)
I watched multiple video and read different documentation among which official msdn documentation learn.microsoft.com/.../endpoints-apis-for-dynamics
But I still can't achieve workable result
Here is code via which I try to perform my gain
static async Task GetS2SToken()
{
string ClientId = "XXXXXXXXXXX";
string ClientSecret = "XXXXXXXXXXXXXXXX";
string TenantId = "XXXXXXXXXXXXXXXX";
string URL = "">login.microsoftonline.com/" + TenantId + "/oauth2/v2.0/token";
HttpClient client = new HttpClient();
var content = new StringContent("grant_type=client_credentials" +
"&scope=">api.businesscentral.dynamics.com/.default" +
"&client_id=" + HttpUtility.UrlEncode(ClientId) +
"&client_secret=" + HttpUtility.UrlEncode(ClientSecret));
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
var response = await client.PostAsync(URL, content);
if (response.IsSuccessStatusCode)
{
JObject Result = JObject.Parse(await response.Content.ReadAsStringAsync());
string BearerToken = Result["access_token"].ToString();
string URL2 = $"">api.businesscentral.dynamics.com/.../customers";
HttpClient testclient = new HttpClient();
testclient.DefaultRequestHeaders.Add("Authorization", "Bearer " + BearerToken);
var result = testclient.GetAsync(URL2).GetAwaiter().GetResult();
if (result.IsSuccessStatusCode)
{
Console.WriteLine(await result.Content.ReadAsStringAsync());
}
else
{
Console.WriteLine(result.StatusCode.ToString());
}
HttpClient testclient2 = new HttpClient();
testclient2.DefaultRequestHeaders.Add("Authorization", "Bearer " + BearerToken);
var result2 = await testclient2.GetAsync(URL2);
if (result2.IsSuccessStatusCode)
{
Console.WriteLine(await result2.Content.ReadAsStringAsync());
}
else
{
Console.WriteLine(result2.StatusCode.ToString());
}
}
else
{
Console.WriteLine(response.StatusCode.ToString());
}
}
Please help me to identify how to form the URL
Hi, It looks like the same problem.