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)

How to use access token with Organization service?

(0) ShareShare
ReportReport
Posted on by

I have a mobile application (Java), and recently I have managed to implement retrieving an access token for one of my accounts via OAuth2. 

How should I use it with SOAP Organization service? If I have this access token, how can I retrieve the Endpoint Address?

I used to put credentials "cipher value" to xml headers, how can I switch to token now? Where should I put it? 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    You should use it with the Web Api.

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

    "Once you have the access token, you must set the Authorization header of the message request that you are sending to the web service to the access token value and specify the token type of “ Bearer”."

     

    The Soap Endpoint will be deprecated:

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

    "The 2011 endpoint will be removed some time after the release of Dynamics 365 version 9. We plan to provide updates to the Dynamics 365 SDK assemblies and tools over the next several minor releases, retargeting them to use the Web API instead of the 2011 endpoint."

     

  • Community Member Profile Picture
    on at

    When I'm using web API, it returns 401 Unauthorized, though I set Authorization Header to "Bearer <token>"

  • Community Member Profile Picture
    on at

    Are you using CRM on premisse or online?

    Can you post your code?

    I'll try to replicate it with my CRM instance.

  • Community Member Profile Picture
    on at
    byte[] bytesEncoded = Base64.encodeBase64(token.getBytes());
    Map<String, String > headers = new ArrayMap<String, String>();
    headers.put("Authorization", "Bearer " + bytesEncoded);
    headers.put("OData-Version", "4.0");
    headers.put("OData-MaxVersion", "4.0");
    headers.put("Accept", "application/json");
    
    Request request = new Request.Builder().url("https://<my_crm_url>/api/data/v9.0/WhoAmI").headers(Headers.of(headers)).build();
    try{
      response = new OkHttpClient().newCall(request).execute();
      statusCode = response.code();
    } ...
  • Community Member Profile Picture
    on at

    I use CRM Online, I can manage to get token with CRM On-Premise, which is actually one of my another issues..

  • Community Member Profile Picture
    on at

    Actually, I try to access CRM On-Premise with simple Basic Authentication headers, but they too return 401.

    Here's the code for CRM on-Premise:

    String credentials = Credentials.basic(<username>, <password>);
    Map<String, String > headers = new ArrayMap<String, String>();
    headers.put("Authorization", credentials);
    headers.put("Accept", "application/json");
    Request request = new Request.Builder().url("<link to on-premise crm>/api/data/v8.2/").headers(Headers.of(headers)).build();
    try{
       response = new OkHttpClient().newCall(request).execute();
       statusCode = response.code();
    }
    ...


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