HOW TO CONNECT TO DYNAMICS 365 ENVIRONMENT USING POSTMAN TO DO WEBAPI CALLS

As a developer, you normally use Console Application, JavaScript, or plugins in XrmtoolBox in order to test specific requests to make sure they are working as expected.

However, and since the introduction of the Web API in Dynamics 365, there are some tools that you can use to consume the needed WEB API requests against Dynamics 365 environment.

My preferred tool to use is Postman, and this is our topic today where we will learn how to connect Postman to Dynamics 365 environment and consume the desired operations like create, update... in order to quickly test and accomplish them.

  1. First, you have to create an App Registration in Azure and enable its options as explained in this post to be able to connect to Dynamics 365 environment through Postman using the OAUTH authentication
  2. Open Postman, and go to the Environments menu, create a new Environment
  3. The environment will contain the different variables that will be used to connect to the Dynamics 365 environment
    • url: This is the URL of the Dynamics 365 environment
    • clientid: This is Application (Client Id) generated when you created the App Registration in Azure (check the above link)
    • version: This is the version of the Dynamics 365 API target
    • discourl: This is the discovery URL of the dynamics 365 environment with the following format : {{url}}/api/discovery/v{{version}}/
    • callback: This is the callback URL you set when you created the App Registration in Azure (check the above link)
    • authurl: This is the authorization URL of you dynamics 365 environment with the following format : https://login.microsoftonline.com/common/oauth2/authorize?resource={{url}}
    Dynamics 365 with postman 1

  4. Once you create the needed variables, go to Collections menu and create new collection that will contain the WEB API requests
  5. In the new collection, add a new GET request to the dynamics 365 API URL that has the following format: https://<ORGURL>/api/data/v9.2/
  6. Within the request page, go to the Authorization tab and set its properties as follow in order to enter the variables for the connection:
    • Type: AOUTH 2.0
    • Add authorization data to: Request Headers
    • Callback URL: This is the callback variable you created previously
    • Auth URL: This is the authurl variable you created previously
    • Client ID: This is the clientid variable you created previously
    Dynamics 365 with postman 2

  7. Once you finish setting the properties, you have to get an access token that will be used to authorize the connection to the environment
    • Click Get New Access Token button
      Dynamics 365 with postman 3

    • Sign-in to your account
    • Once the Authentication is completed, click Proceed
      Dynamics 365 with postman 4

    • The Access token will be generated and can be used. Click Use Token
      Dynamics 365 with postman 5

    • The token is copied to the authorization section
      Dynamics 365 with postman 6

    Note: If you didn't generate an access token, you will receive a 401 unauthorized error in the response
    Dynamics 365 with postman 7

  8. Once the token is generated, you can test different API requests against the Dynamics 365 target environment
    • Get the metadata of the Dynamics 365 environment
      Dynamics 365 with postman 8

    • Execute the WhoAmI request and get the user information
      Dynamics 365 with postman 9

    • Get the Account entity names
      Dynamics 365 with postman 10

    • Get the Account entity MetadataId which is the Guid of the entity in the system from the EntityDefinitions
      Dynamics 365 with postman 11

    • Create account records in Dynamics 365
      Dynamics 365 with postman 12

      Dynamics 365 with postman 13

      Dynamics 365 with postman 14

    • Create and Manage Polymorphic Lookup Attribute as detailed in this post

Hope This Helps!

Comments

  1. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for the informative post. download Postman

    ReplyDelete

Post a Comment

Popular posts from this blog

DYNAMICS 365 FILTER LOOKUP FIELD BASED ON N:N RELATIONSHIP

DYNAMICS 365 LEVEL UP BROWSER EXTENSION - PART 1 - FORMS

DYNAMICS 365 REFERENCE PANEL