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)

WEB API Authentication: 401 Unauthorized

(0) ShareShare
ReportReport
Posted on by 325

Hi All,

I'm using cURL to test Dynamics WEB API but I'm having 401 error. I was able to successfully post using the WEB API samples provided by Microsoft but our client requires to use cURL. We can get the access token and send a GET message but not POST. I think we need to provide the Dynamics Credential. Can anyone know the exact header to use?

Thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Michel van den Brink Profile Picture
    4,697 on at

    Hello,

    Authenticating with the WebApi works the same way for GET, POST, PATCH and all other verbs.

    Getting a 401 on your request is pretty strange, when that same token does work on a different request. It might be that your token has just expired? Access tokens have a pretty short lifespan (by design)

    Always get your access token first, via Azure AD (login.microsoftonline.com) and make sure it it's valid before you do every request, if not refresh it.

    Send the access token in the 'Authorization' header on every request, GET, POST, or other.

    GET example:

    curl -X GET \
      https://organizationname.crmX.dynamics.com/api/data/v8.2/accounts \
      -H 'authorization: Bearer eyJ0eXAiOiJKV...'


    POST example:

    curl -X POST \
      https://organizationname.crmX.dynamics.com/api/data/v8.2/accounts \
      -H 'authorization: Bearer eyJ0eXAiOiJKV...' \
      -H 'content-type: application/json' \
      -d '{	"name":"New Account Record" }'

    Hope this helps you on your way!

  • PDCM Profile Picture
    325 on at

    Hi Michel,

    Thanks for your reply.

    Yeah. That's how I'm doing it and I can make GET work but not POST. Seems it needs the Dynamics Credential to know the privilege in accessing/creating records. Is there something that needs to be done in AD setup to make sure the POST works?

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