While answering questions on Microsoft community forum, I have seen lot people struggle to understand how to pass parameters to service operations in D365 FO. In today’s blog post we will see step by step process to  pass paraments to  test a D365 FO custom service from Postman.

For the demonstration I am taking a standard service available in Project management and accounting module called “ProjectWbsService”. If you are working on an implementation which is using Project operations and deployment options three, this service is very handy. Learn more about project operations and its deployment types on this link (https://learn.microsoft.com/en-us/dynamics365/project-operations/environment/determine-deployment-type#deployment-types )

In my recent projects, we were ab building a power app and the requirement was to send resources defined on a project. While researching on any out of the box options I found the service “ProjectWbsService” which has lot of inbuilt useful service operations related to PMA module. One of them getProjectResources which returns resources who are going to perform tasks on a that project or project specific resources. Let’s take a look at step by step process to call this service operation using postman.

  1. For setting up postman use this link – https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/third-party-service-test
  2. Once the postman is set up get URL for your custom service you are going to call using postman

URL should look like this – FO env URL/api/services/ProjectServices/ProjectWbsService/getProjectResources

3. Get token and specify both token and content type in the header tab.

4. Now comes to passing parameters to the service operation. This is where most of the confusion comes from or there are limited sources available on the web which will guide you.

Parameter can be a variable or a data contract object. Let’s first see how you can pass variable as a parameter. In the example, which I have taken getProjectResources method excepts two parameters as shown below.

As you can see, this operation requires Project Rec Id and company as parameters. To send those using postman you will need to form a simple JSON with these parameter as pass it in the body, as shown below. Remember, you are going to pass declared variable name in the body not the actual type or extended data type name.

5. Let see how to call a service operation which expects Data contract class as input instead of variables.

Here is an example of service operation which expects data contract class

You should create the JSON Body for this class as shown below. Remember parameter name which you have used in your service class  “partInvPurchHeaders”  is  very important element of the JSON body you are going to form.

In some scenarios we use nested contract classes. For example, one contract accepting another contract class. Here is example, In the service operation I shown above which excepts “InvHeaderContract” has data member attribute which is another contact class “partInvHeaderDetailContract”.

In such a scenario’s, JSON should have two key elements “partInvPurchHeaders” which is nothing but parameter for service operations  and another one is “partInvPurchHeader” which is another data contract which is data member attribute of first contract class. Look at the example below to understand how the JSON is formed. Rest of the element of the JOSN like Currency , Invoice Number etc are data member attributes of contract class partInvPurchHeader.

Hope this article helps you to understand how the parameters need to be passed for custom service operation in Dynamics 365 for finance and operations. Enjoy!