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 CRM (Archived)

Calling WebAPI results in 401 Unauthorized Error [C#]

(1) ShareShare
ReportReport
Posted on by

Hi there

I'm using this sample:

https://msdn.microsoft.com/en-us/library/mt779074.aspx

I put in my credentials and try to connect to a CRM 2016 Organization but always get 401 Unauthorized.

IIS Authentication; Enabled: Anonymous, ASP.NET, Basic, Windows; Disabled: Digest, Forms.

Fiddler Screenshot:

fiddlo.png

Any help is much appreciated, really struggling with this one.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hello,

    Did you also register the app in AD as per: msdn.microsoft.com/.../dn531010.aspx

    Besides the credentials you also need to specify the client id

    Hope this helps

    Radu

  • Community Member Profile Picture
    on at

    No, is this really needed for on-prem connections?

    I was following this guide:

    https://msdn.microsoft.com/en-us/library/mt770369.aspx#bkmk_prerequisites

    "Access to Dynamics Dynamics 365 Online or on-premises (or later). For all Dynamics 365 installation types, a user account with privileges to perform CRUD operations is required.

    In order to run samples against Dynamics 365 (online), you must register your application with Azure Active Directory to obtain a client ID and redirect URL. For more information, see Walkthrough: Register a Dynamics 365 app with Azure Active Directory."

    No mentioning of registering through Azure AD when using on-premises.

  • Radu Chiribelea Profile Picture
    6,667 on at

    Hi,

    Are you using IFD? If so, I believe you need to register the app.

    Regards,

    Radu

  • Radu Chiribelea Profile Picture
    6,667 on at

    If you are not using IFD, are the SPNs set up properly?

  • Community Member Profile Picture
    on at

    I am actually using IFD, mistake on my part. After setting it up correctly it is now working fine. You sir are a gentleman and a scholar, thank you very much.

    Only thing left now is to somehow pass the credentials while calling the API so I can execute a Console Application without having to fill up the username/passwort prompt.

  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hi Kim,

    Thank you for your feedback. I am glad that i could assist you.

    This should be possible with ADFS 2016 if i'm not mistaken.

    Please check a similar thread here: community.dynamics.com/.../268326 - maybe the code there can give you a starting point.

    Hope this helps

    Radu

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 CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans