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

Business Central 365 How to form URL for GET request via C# code

(0) ShareShare
ReportReport
Posted on by 130

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 

pastedimage1668633916348v2.png 

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

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    99,074 Super User 2026 Season 1 on at

    Hi, It looks like the same problem.

    (+) Business Central 365 c# Oauth implementation - Dynamics 365 Business Central Forum Community Forum

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,926 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,158 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 533 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans