Setup Postman To Call D365 Data Entities

Share this:

If you are writing an integration into D365 you may want to setup Postman to call D365 data entities. This will allow you test the data entities and see what data your receiving application will retrieve without waiting to ask the receiving application to make the call.

The last article, we completed the setup steps needed to allow Postman to make the call. We also wrote down the pieces of information we will need to setup Postman. In this article we will setup Postman to call D365 Data Entities.

Before we actually make the call to the data entity. We will need to do two things first:

  1. Create Get Token Request in Postman. This will get an access_token needed to access D365.
  2. Store the Access Token In An Environment Variable.

What You Will Need

In order to use Postman you will need the following pieces.

  1. Download and install Postman. https://www.postman.com/downloads/
  2. The Directory ID, found in the last article.
  3. The Client ID, found in the last article.
  4. The Client Secret ID, found in the last article.
  5. The URL of the D365 environment you wish to connect to.

Create Get Token Request In Postman

Open Postman.

Click the ‘New’ button in the top right corner. Select ‘Request’.

Create Postman Request

In the Dialog that open, enter in a Request name. Then click Save.

Save Postman request

In the main window, change the request type to be ‘Post’.

Set Postman request type

Then enter in the URL to be the following. Replace <Directory ID> to be your Directory ID found in the Azure Portal.

https://login.microsoftonline.com/<Directory ID>/oauth2/v2.0/token

Next, select the ‘Headers’ tab and specify the following values. Most should be defaulted in. However you will need to set the Host to login.microsoftonline.com.

Postman get access token headers

Click on the Body tab and specify the following Key Value pairs.

Postman get access token body
  1. The client_Id should be the Client ID found in Azure Portal.
  2. The client_secret should be the Client Secret ID found in the Azure Portal.
  3. The grant_type should be the text ‘client_credentials‘.
  4. The Scope should be set to the URL of your D365 instance that you wish to connect to, followed by the text ‘/.default
https://<D365 URL>/.default

Click the ‘Save’ button in the top right to save the request.

Click the ‘Send’ button. If you have setup the request correctly, you will see something similar in the response body. The access_token value will contain a long string. And the Status will be 200 OK.

Postman get access token response

Store the Access Token In An Environment Variable

We will need to use the access_token value from the last step, whenever we make a call to D365. This token expires in about an hour. While we could regularly copy and paste the long string into our request, there is an easier way. We can have postman store it in an environment variable.

In Postman, click the New button. Then select ‘Environment’.

Postman create environment variable

In the dialog that opens specify a name for the environment. In the first line, enter the text ‘access_token’ under the variable column. Then click the Add button.

Postman manage environment variable

Now go back and select the ‘Get Token’ request.

Select the ‘Tests’ tab.

Postman request Tests

Enter the following code. This takes the access_token value in the response of this request, and stores it in the environment variable named ‘access_token’.

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("access_token", jsonData.access_token);

Push ‘Save’.

Next, in the top right corner, select the name of your environment from the drop down.

Postman set environment

Then click ‘Send’ on the ‘Get Token’ request. This will cause the access_token in the response to be stored in the environment variable named ‘access_token’.

Setup Postman Request To D365 Data Entity

Finally, we can make a request to the D365 Data entity.

In Postman, click the ‘New’ button. Then select ‘Request’.

Postman new request

Set the request type to ‘Get’.

Specify the following text in the URL field. Replace <D365 URL> with the URL you use to access the D365 environment.

https://<D365 URL>/data/CustomersV2

In the Headers tab, specify the following Key Value Pairs.

Postman request Headers Bearer

Most of the pairs will default in. However, you will need to set the Authorization value to the text ‘Bearer {{access_token}}’. This tells Postman to replace the text ‘access_token’ with the value in the access_token environment variable.

If you do not setup an environment variable, manually copy and paste the long access_token value from the first call into this field. Note, keep the ‘Bearer {{ }}’ text.

Click ‘Save’

Click ‘Send’

If you set things up correctly, you will get a response with a Status of 200 Ok. And you will see customer data returned as JSON text in the response.

Postman request response

Conclusion

Congratulations! You have successfully setup Postman to call D365 Data Entities. In this case we called the CustomersV2 data entity. Change the URL to query other data entities. Adding the filter parameter to the URL further will allow you to filter the results being returned.

Peter Ramer
Peter Ramer is a part of the Managed Application Services team at RSM working on Microsoft Dynamics 365. He focuses on the Retail and Commerce industries. When he is not solving problems and finding ways to accelerate his clients' business, he enjoys time with his three kids and amazing wife.

Share this:

23 thoughts on “Setup Postman To Call D365 Data Entities

Add yours

  1. I am trying to hit CustomersV3 through post method and i followed same procedure as you mention, but i am getting error.

    “Message”: “Authentication failed.”,
    “StackTrace”: null,
    “ExceptionType”: “System.InvalidOperationException”

    I tried all possibilities even though not able resolve the issue. Would you advise ?

  2. I find it much better to get the token in a pre-request script on the collection. This then saves the value of the token in each environment before every call (if the token has expired). Saves a lot of 401 errors

  3. Hi, in that part of the instruction

    The client_Id should be the Client ID found in Azure Portal.
    The client_secret should be the Client Secret ID found in the Azure Portal.
    The grant_type should be the text ‘client_credentials‘.
    The Scope should be set to the URL of your D365 instance that you wish to connect to, followed by the text ‘/.default‘

    There is probably an error: there is
    The client_secret should by Client Secret ID found in the Azure Portal
    Shouldn’t be ?
    The client_secret should by Client Secret Value

      1. Thankyou for response.
        Yes I followed this and getting token sucessfully. But when sending Get request to D365 entity getting this error.

  4. Thankyou for response.
    Yes I followed this and getting token sucessfully. But when sending Get request to D365 entity getting this error.

    1. Have you setup a clientID and client secret in azure, and included those in your call? Also make sure you use the auth token in your get call. Also, the auth token expires in a few hours so make sure to make the call to get the auth token. Then use it in the get call fairly soon after that. If you wait awhile you need to get a new auth token.

      1. Hi Peter,

        Thank you for response.
        Yes I have setup app in Azure and I am able to get token first and then sending request to D365 with token and I am sending get request just after getting token but getting error. Any idea?

        1. It looks like it is an invalid operation exception. Are you trying to get a base Microsoft data entity? Or is it a custom one? If it is custom you should make sure it is marked as public, and that it is published, and you are using the correct name as listed in the properties of the data entity. I think to really help I would need to know the url, the body, and the headers (with access token not actually shown) to understand if all the required pieces are there.

  5. In this article you explained about GET request and fetched data from the entity.
    Can you please provide me any resource or link about the POST or PATCH request to update record in entity. I tried but not succeed.

  6. Thank you very much for this great post, i tried this method but i get
    {
    “@odata.context”: “https://usnconeboxax1aos.cloud.onebox.dynamics.com/data/$metadata#CustomersV2”,
    “value”: []
    }

    any idea?

  7. Hi,

    I am able to generate the access token successfully.
    When i am trying to get the customer list and details it is showing the below message:

    {
    “@odata.context”: “https://ex-sdboxfef479a06b388a7fdevaos.axcloud.dynamics.com/data/$metadata#CustomersV2”,
    “value”: []
    }

  8. Hi Peter,

    Need your help in below error,

    1. Token generated successfully
    2. https:///data/CustomersV2 – In this step, I am getting below error..
    {
    “Message”: “Authentication failed.”,
    “StackTrace”: null,
    “ExceptionType”: “System.InvalidOperationException”
    }

    Thanks,
    MG

    1. You need http:///data/CustomersV2. Make sure this looks right and make sure the web call type is GET for this second call.

  9. Probably too late but anyways

    Make sure that the user you mapped on system administrator > setup > Azure active directory applications is pointing to any dataentity that have info
    (settings > user options > preferences > Startup > Company)
    Or define the entity to use on your get call

Leave a Reply

Your email address will not be published. Required fields are marked *

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑