Dynamics 365 Online – API Access Token with OAuth 2.0
Summary
In this post, I’m going to demonstrate how to generate Access Tokens using OAuth 2.0, Implicit Grant for Microsoft Dynamics 365 CE.
This is a two-step process. Firstly, you must register the App with Azure Active Directory. Secondly, setup Postman to make HTTP calls.
Register Azure Active Directory App
Register a new App in Azure Active Directory. In my example, I’m using the Redirect URI: https://eax360.com/callback
Take note of the Application ID (client ID). In my example this is:
Display name: Dynamics 365 App Registration
Application (client) ID:a27d5fd4-ffa4-4825-aa06-9bca50499d77
Also, ensure that Access Token has been enabled under the Implicit Grant heading in the Platform configurations section.
This completes the App configuration.
Add API Permissions
Once the above is complete, go to API Permissions and add Dynamics CRM.
On completion of the step above, ensure that you have selected ‘Grant admin consent for {oganisation name}’.
Create a new Client Secret
Once the step above is completed, it’s now time to create a new Client secret. Under Certificate & secrets, create a new secret and take note of the value.
In the example above, my secret is ‘Wsj8[a@16.fA]TXSAp71u=sTw0dDbx8x‘
This completes the App registration.
Postman Environment Setup
In Postman, create a new Environment by clicking on the cog icon. The settings required are as follows:
Variable name | Value |
---|---|
url | https://<add your environment name, like 'myorg.crm'>.dynamics.com |
clientid | 51f81489-12ee-4a9e-aaae-a2591f45987d |
version | 9.0 |
webapiurl | {{url}}/api/data/v{{version}}/ |
callback | https://callbackurl |
authurl | https://login.microsoftonline.com/common/oauth2/authorize?resource={{url}} |
In my example, I will be using the following settings:
Variable name | Value |
---|---|
url | https://tessla.crm11.dynamics.com/ |
clientid | a27d5fd4-ffff-4825-aa06-9bca50499d77 |
version | 9.0 |
webapiurl | https://tessla.api.crm11.dynamics.com/api/data/v9.0/ |
callback | https://eax360.com/callback |
authurl | https://login.microsoftonline.com/common/oauth2/authorize?resource=https://tessla.crm11.dynamics.com/ |
This completes the Postman environment setup.
Generate Access Token
The final step is to retrieve the Access Token. To do this, select the environment, and under Authorisation, select OAuth 2.0.
Under Grant type, select Implicit. The fields that must be completed here are:
- Auth URL
- Client ID
- Callback URL
Enter these values and click Request Token.
At this point, you should be prompted to sign-in. Once the Sign-in stage has been completed, you will be presented with the Access Token. Click on Use Token.
If everything is successful, you should be able to make HTTP requests.
This completes the setup for Postman.
2023 Update
As of 2023, Connecting to Dynamics 365 CE has been simplified through the use of APIM policies.