- androsjuk
Custom service with multi-level JSON request/response
Using data contracts it is possible to build an arbitraty structure of input arguments and return values. For example, we need to update in one request several records and receive a detailed response about success of an operation for each record.
As an input we will receive a list of record identifiers with parameters to be changed
as an output user can receive a list of operation results for each record.
Following steps need to be performed:
Create data contracts for input and output and build a needed tree.
Create a custom service.
Add service to a service group.
Build module.
Run a request with a RESTful services tool (Postman.)
As an example we will take a sales order with sales order lines. Confirmed shupping date and quantity should be updated on each line.
Input contract:
This contract will be an item in a list of an input contract for a sales order:
Then we will define a response.
First we will create a response data contract for a sales line:
Then a response contract for a service method. This method will contain a list of a sales lines' responses:
A response contract looks like this:
Then we will create a service with 1 method updateOrderLines
Create a new service ruaSalesOrderService.
Add operation updateOrderLines to it.
Create new service group ruaServices
Add ruaSalesOrderService to this group.
To call a D365FO service from extern first we need to obtain an authorization token.
A detailed descriptions can be found here.
Service URL should look like this:
A request JSON names should exactly coinside with a parameter names:
A response will look like this:
In this way we can build an arbitrary hierarchie structure with the help of data contracts.