Search code examples
javaauthenticationdynamics-crmadaldynamics-crm-2016

Dynamics CRM 2016.Web API Auth. I have token, now what?


Using ADAL libs for java I managed to get Access,Refresh and ID Tokens using my office365 credentials.

Now my intention is using REST Web APIs, my intention is to create an entity, as a proof of concept. Based on my experience with other venders and REST APIs, once you have a valid token, you just add it as a Authorization header like:

Authorization=Bearer 709709JHKLJHKJLhHKHKJHKH...etc

Is something similar to this in Dynamic CRM 2016?

Here here is nice info about composing a POST http request, but I am missing the Authorization part... Any idea guys?


Solution

  • Here is a valid GET request to pull back accounts.

    GET https://<CRM DOMAIN>.com/api/data/v8.1/accounts HTTP/1.1
    Authorization: Bearer:<TOKEN GOES HERE>
    Host: <CRM DOMAIN>.com
    

    And here is a valid POST

    POST https://<CRM DOMAIN>.com/api/data/v8.1/accounts HTTP/1.1
    Content-Type: application/json; charset=utf-8
    Accept: application/json
    Authorization: Bearer:<TOKEN GOES HERE>
    Host: <CRM DOMAIN>.com
    Content-Length: 224
    
    {
        "name": "Sample Account",
        "creditonhold": false,
        "address1_latitude": 47.639583,
        "description": "This is the description of the sample account",
        "revenue": 5000000,
        "accountcategorycode": 1
    }