Call MS CRM Web API outside CRM Applicaiton or with Postman

What is Issue?

MS CRM provides out-of-box Web API which we mostly use in javascript to get data from entities whenever required. But there are many situations where your company uses different applications and CRM is one of them. The data across company can be used in any of these application in real time. So instead of writing custom Web API, if MS CRM provides out-of-box Web API, can we use that in any other application? or is it possible to call MS CRM APIs using postman for testing purpose before used in any other application?

The Reason-

MS CRM provides the way to get data from entities with calling Web API. But mostly we use this API calls within CRM application. When calling Web API within CRM , user is already logged in to the CRM which do not need any extra authorization. When we try to calls these Web API out side CRM it requires authorization to access data from CRM.

Solution-

To Call Web APIs outside MS CRM environment you need to get Bearer token for the user using OAuth2.0 authorization.

Lets take example – WebAPI to get all Accounts- https://xxxxx.crm8.dynamics.com/api/data/v8.2/accounts

Lets generate bearer token to access above WebAPI from Postman-
I am considering You have registered the Azure app and you have Client Id and Client secrete with you for this app.
In Postman- New request add your request –

    1. Go to the Authorization tab
    2. Select Type – OAuth2.0
    3. Click on Get New Access TokenPostMan0
    4. In popup window please enter all required information as below-PostMan
    5. Grant Type – Authorization Code
    6. Enter Callback URL provided in Azure App – Redirect URI
    7. Enter Auth URL –
      https://login.windows.net/common/oauth2/authorize?resource=https://xxxxx.crm8.dynamics.com
    8. Access Token URL –
      https://login.microsoftonline.com/common/oauth2/token
    9. Enter Client Id and Client Secret you have.(Azure App client details).
    10. Click on Request Token.
    11. Microsoft login window will popup. Enter your credentials to login.On successful authentication, It will bring an access token for you.
    12. Select Access Token you have generated just a while before from Available tokens in postman.
    13. Don’t forget to select Add authorization data to – Request HeaderPostMan2
    14. Now you can send the request and test your MS CRM Web APIs.
    15. You can use the Code option in postman to generate code according to your programming needs.PostMan3

You can use the same parameters when generating bearer token for the user using code.

How to get bearer token using Postman-

  1. Use Post Method and URL-
    https://login.microsoftonline.com/common/oauth2/token
  2. Add below details to Body of the request as form-data-
    – grant_type – client_credentials
    – user’s credentials : username and password
    – other details – client_id and client_secret as described above. -resource : your MS CRM url.
  3. PostMan4

Using the bearer token generated you can access MS CRM Web APIs in any application.

Hope this will help…
Enjoy Ms CRM!!!

Follow on Facebook- FB: MSCRM16Tech

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s