Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

OAuth 2.0 token for D365 F&O Odata Rest call

(0) ShareShare
ReportReport
Posted on by 30

Hi,

  I am trying to invoke D365 F&O Odata rest API call with grant type as authorization_code but I keep getting response code as 401 (Unauthorized).

  Has anyone tried Authorization Code Grant Flow for Dynamics 365 F&O before? If yes, please share the link or step to do it?

  FYI, I have tried calling Rest API with client type as "Client credential" as mentioned in below link and its working fine.

  docs.microsoft.com/.../third-party-service-test

  However ask is to integrate it via OA Auth 2.0 for better security

Regards,

Satyajeet Kumar

  • Willi K. Profile Picture
    5 on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    This is not Version 2.0 of OAuth. What you are sharing is Version 1 of the OAuth.

  • Community Member Profile Picture
    on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Hi Satyajeet

    Step for get authorization.

    1. get access to from this url : login.microsoftonline.com/your tanent id/oauth2/token.

    2. when you get access token already put it to header request as bearer token.

    Example

    exam-post-man.jpg

  • Sagnik Majumder Profile Picture
    792 on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Hi Satyajeet, if this solves your problem, can you please mark this as Answer?

  • Suggested answer
    Sagnik Majumder Profile Picture
    792 on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Hi Satyajeet,

    I faced the same issue as you are, and the reason being a trailing '/' at the D365 url which I was using. I was using the Client Credentials grant flow. Please check if you also have a trailing '/' in the D365 url or the AAD Tenant url.

  • Suggested answer
    Anup Shah MSFT Profile Picture
    on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Multiple reasons for getting 401. One more reason is, it depends on what parameters were used to get the token. For example when getting the token using grant_type=client_credentials, if no resource url was specified or the resource url has a trailing '/' or the resource url is different to what D365FO is hosted on then the access will still fail. D365FO checks for the resource url and compares the value with the url hosted for D365. If they don't match you ca get an HTTP 401.

  • satyajeet Kumar Profile Picture
    30 on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Yes, Sukrut. It is defined.

    As mentioned earlier, I am able to invoke API in case Grant Type is "Client credential" as mentioned below

    docs.microsoft.com/.../third-party-service-test

    However I am facing issue when calling same API after generating the token via standard OAuth 2.0 authentication.

    docs.microsoft.com/.../services-home-page

  • Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Do you have application ID added in Azure active directory applications form in Sys admin module ?

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Hi Satyajeet,

    You don't need to create another admin. I hope you are logging in with your email Id and not the admin user. In that case, you can assign change the user in the form Azure active directory application form in D365 F&O.

    You can also change the admin email Id using the admin user provisioning tool, if you have deployed a Dev Box. But, since this is in Azure, let's not do that right now.

  • satyajeet Kumar Profile Picture
    30 on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Hi Gunjan,

      I can't edit the email of Admin user , may be due to the fact that I deployed D365 on Azure

      subscription.

      Plus, system not allowing to create a new admin like user having my email address.

      Anyway, we will try raise support ticket with MS for same issue.

    Regards,

    Satyajeet

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: OAuth 2.0 token for D365 F&O Odata Rest call

    Hi Satyajit,

    We haven't exposed the API before, so don't think that is needed.

    Could you please change the Azure app registration from admin user to your user Id In D365 F&O? Alternatively, you could set your user up as the admin as well since you are the owner of the subscription where Azure is hosted.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,099 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,880 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans