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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Not able to receive response from Dynamics API

(0) ShareShare
ReportReport
Posted on by 20

I have used MSAL.Net (followed blog https://msftblog.com/using-msal-net-with-dynamics-365-webapi-in-dotnet-core/) to communicate with Dynamics CRM which is returning the access token & when I give a call to products API I see below message & cannot move ahead.

Failed to call the Web API: Forbidden

Content: {"error":{"code": "0x80072560", "message": "The user is not a member of the organization."}}

However, if I login to dynamics 365 crm & copy the URL (https://{Company}.api.crm8.dynamics.com/api/data/v9.1/products) in the browser I am able to get the response.

Just a background:

Have Azure active subscription & Dynamics 365 30 day trial.

Any help on resolving the above error much appreciated.

Thanks & Regards,

Raghavendra Habbu

I have the same question (0)
  • Suggested answer
    Johao Larios Profile Picture
    1,795 on at

    I have never used that to connect to d365 from .netCore.

    I use this:

     AuthenticationContext authContext = new AuthenticationContext("login.microsoftonline.com/" tenantId, false);

               ClientCredential credential = new ClientCredential(clientId, secret);

               AuthenticationResult result = await authContext.AcquireTokenAsync(serviceUrl, credential);

               if (result == null)

               {

                   throw new InvalidOperationException("Failed to obtain the JWT token");

               }

               string atoken = result.AccessToken;

               using (HttpClient client = new HttpClient())

               {

                   client.BaseAddress = new Uri(serviceUrl);

                   client.Timeout = new TimeSpan(0, 2, 0);  //2 minutes  

                   client.DefaultRequestHeaders.Add("OData-MaxVersion", "OData-MaxVersion");

                   client.DefaultRequestHeaders.Add("OData-Version", "4.0");

                   client.DefaultRequestHeaders.Accept.Add(

                       new MediaTypeWithQualityHeaderValue("application/json"));

                       HttpRequestMessage request =

                       new HttpRequestMessage(HttpMethod.Get, "/api/data/v9.0/opportunities?$select=name");

                   //Set the access token

                   request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", atoken);

                   HttpResponseMessage response = client.SendAsync(request).Result;

                    if (response.IsSuccessStatusCode)

                   {

                       //Get the response content and parse it.  

                       JObject body = JObject.Parse(response.Content.ReadAsStringAsync().Result);

                       //  Guid userId = (Guid)body["UserId"];

                       //  Console.WriteLine("Your system user ID is: {0}", userId);

                       Console.WriteLine(body.ToString());

                       Console.ReadLine();

                   }

               }

  • Dynamics WebApi Subscription Profile Picture
    20 on at

    Thank You Johao. Let me give it a try once again.

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 74

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans