Setup Postman To Call D365 Services

Share this:

In this article we will look at how to setup Postman to call D365 services. In past articles we looked at how to use Postman to call D365 Data entities, and this is great when you just need to push in data. However, sometimes you need to need to be able to call D365 code to process the data, or to retrieve some data within the system.

In this article we will start with just an example that calls existing D365 code. However in further articles I will go into more detail of show how to write your own custom x++ service classes.

What are the Steps?

  • First, we setup Postman to take the data we want to send into D365, and send it to a method on a class in D365.
  • Secondly, we write the x++ classes in D365 that will be parse the data in the JSON message, and turn it into a populated x++ class object.
  • Thirdly, we write the code in D365 that read the values out of that class object or objects, run some process, and finally return a response.

Setup Postman To Call A Method On A Class

In a previous article I explained how to install Postman, get an access token, and make a request to a data entity. Please follow the steps in that article to install Postman, make a call to get the access token, and store the access token in an environment variable. Next, we will create a request to call a method in a D365 class.

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

Enter a name for the request, and then click Ok.

Setup the URL of the Request

Change the request type to ‘Post’.

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

https://<D365 URL>/api/services/SysTestServices/SysTestService/getTestRunResult

Let’s break down this URL into it’s parts.

  • https:// – This specifies we are making a secure call.
  • <D365 URL> – This should be replaced by the URL used to access your D365 environment. For example: https://usnconeboxax1aos.cloud.onebox.dynamics.com
  • api/services – This text tells D365 that we are calling a service.
  • SysTestServices – This is the name of the service group we are calling.
  • SysTestService – This is the name of the service we are calling.
  • getTestRunResult – This is the name of the method we are calling on the service/class.

Setup The Headers

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

Postman service call

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.

Setup The Body

In Postman, specify the following text in the ‘Body’ tab.

{
	"_testGuid" : "EAC159B6-F481-4EBC-A7B6-FCB69B188E87"
}

It will look like this in Postman.

The text that you put in the Body is the data that you are sending into D365. So the name/value pairs that you send in will change depending on what parameters the method you are calling uses. In this case, the method ‘getTestRunResult’ on the SysTestService class takes a single parameter. The parameter is named ‘_testGuid’. And the value is of type ‘guid’. So we need to make sure your Body matches this contract. See the method definition below.

If our method definition took in multiple parameters, we would need to send in multiple parameters in the body. I will show you how this looks later.

Calling the D365 custom code.

Click ‘Save’

Click ‘Send’

If you set things up correctly, you will get a response with a Status of 200 OK. And the Body of the response will show ‘null’. This may not be a very useful response in this case. But we have made a successful call!

Conclusion

You have successfully setup Postman to call D365 services. In this case, we called an existing service class and method. In the next article I will explain how to call your own custom service class and return back information from within D365.

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:

21 thoughts on “Setup Postman To Call D365 Services

Add yours

  1. Excellent post. I was checking continuously this blog and I
    am impressed! Extremely useful information. I care for such information a lot.
    I was looking for tthis certain information for a very long time.Thank you
    and good luck.

  2. Nice post. I was checking continuously this blog
    and I’m impressed! Very useful information specially the last part 🙂 I care for such info a lot.
    I was looking for this particular informatiion for a long time.

    Thank you and best off luck.

  3. My brother recommended I might like this blog. He was totally right. This post actually made my day. You can not imagine just how much time I had spent for this info! Thanks!

  4. Good day! Would you mind if I share your blog with my twitter group?
    There’s a lot of people that I think would
    really enjoy your content. Please let me know.
    Thank you

  5. Nice blog…I’m new to using D365 with json..please suggest on best practice when the payload for a ‘POST’ into D365 has multiple parameters…for eg. …should the below payload be assigned to a string that will be used as parameter in the service…is this the D365 way…thanks in advance

    payload eg.:
    **********
    {
    “USER_LEAVE_APPROVE”: {
    “IT_ID”: {
    “item”: [{
    “USRKEY”: 90101,
    “USRTYPE”: “ABDC”,
    “TARSYS”: “TARGET”
    }]
    },
    “I_TASK”: “LEAVE_APPROVE”,
    “I_LEAVE_REJECT”: “”
    }
    }

    1. The best practice is to send any JSON string in the body of a message. Then you can let D365 serialize that json string into an x++ object automatically for you if you setup the properties with the right attributes. This then lets you use a class and properties inside x++ instead of just a raw string that you have to parse yourself.
      If you only have a single string value and not a whole json string to pass in to D365, then you could use a url parameter.

  6. Thanks for sharing!
    For some reason, instead of a Null response, i got the following structure, which is sometimes useful for discovering, but i would like to see the data response for my request.
    Any hint on what am i doing wrong?

    {
    “Parameters”: [
    {
    “Name”: “_testGuid”,
    “Type”: “Guid”
    }
    ],
    “Return”: {
    “Name”: “return”,
    “Type”: “SysTestResultInfo”
    }
    }

  7. hello,
    i need to modify the entity “WorkflowWorkItems” on D365FO, so i can add another column to it.
    Is there any way to customize it? Or create a new entity with the same information, so I can access through third party application?
    Currently, I get this response through postman using the url “https://{MYDynamics365URL}/data/WorkflowWorkItems”:

    {
    “@odata.context”: “https://{MYDynamics365URL}/data/$metadata#WorkflowWorkItems”,
    “value”: [
    {
    “@odata.etag”: “W/\”JzEsNTYzNzE1MDU4MCc=\””,
    “Id”: “fe650654-c339-4438-bf94-a1a05596cf93”,
    “DataSourceName”: “”,
    “Status”: “Pending”,
    “ConfigurationId”: “6a04ed3a-9b30-4e31-85bb-655fc7752c2c”,
    “MenuItemName”: “PurchReqTable”,
    “CompanyId”: “”,
    “EscalationLevel”: 0,
    “Subject”: “Purchase Order approval”,
    “CommentId”: “00000000-0000-0000-0000-000000000000”,
    “Description”: “000215\n\n”,
    “WorkflowWorkItem_WorkitemType”: “”,
    “RefTableId”: 24769,
    “Context”: “”,
    “Type”: “WorkItem”,
    “OriginalCorrelationId”: “00000000-0000-0000-0000-000000000000”,
    “IsRead”: “No”,
    “StepId”: “f665f228-a2de-460f-b74d-da98068d322f”,
    “IsClaimed”: “No”,
    “SubWorkflowId”: “00000000-0000-0000-0000-000000000000”,
    “ParentCorrelationId”: “00000000-0000-0000-0000-000000000000”,
    “ActivityId”: “d963d6c0-9136-4b85-8773-67cb191bb41e”,
    “WorkflowWorkItem_Name”: “”,
    “ElementId”: “7a7798bb-b11d-466e-8086-d5eb1cb35f66”,
    “RootCorrelationId”: “223917c1-6da7-4ce1-904d-15e65c7ae31b”,
    “DocumentClassId”: 27542,
    “NotificationId”: 5637145527,
    “CorrelationId”: “223917c1-6da7-4ce1-904d-15e65c7ae31b”,
    “DueDateTime”: “2023-12-21T10:33:00Z”
    }
    ]
    }
    I need to add another field like “WorkItemID”, so I can get more information about the workitem. (for example: if it is purchase order it will be “PO-000214” or if it is purchase requisition it will be “PR-000214”, and so on..)
    I need the response to be like this:

    {
    “@odata.context”: “https://{MYDynamics365URL}/data/$metadata#WorkflowWorkItems”,
    “value”: [
    {
    “@odata.etag”: “W/\”JzEsNTYzNzE1MDU4MCc=\””,
    “Id”: “fe650654-c339-4438-bf94-a1a05596cf93”,
    “WorkItemID”: “PO-00001111”,
    “DataSourceName”: “”,
    “Status”: “Pending”,
    …………………………………………………………..
    ..
    ..
    }
    ]
    }

    How can I do that please?

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 ↑