In the previous blog we have seen the GET (Read ) operation and the various query options available along with it of Purchase Contract API.
In this blog we will cover the POST operation and Create a new Purchase contract.
Again navigate to Purchase Contract ODATA API in the API hub.
Select the POST operation of A_PurchaseContract (Purchase Contract Header).
Click on Try out, you will see a sample payload. This sample payload can be edited with the data with which you want to create the Purchase Contract.
The sample payload template have Header Data , Item Data , Conditions Data (This can be removed as the base condition will be created by default with the Net Price) Address and Partner Data.
Kindly note that by default the Contract template is pre filled with value "string" ,so remove the string value or you might get errors related to string not be able to get converted to number errors (depends upon the field). Either remove the fields which are not required or clear out the string value. Also note that all Boolean fields should have the value true or false without the quotes (" ").
It is required to send the X-CSRF-TOKEN for any POST request , to fetch a X-CSRF-TOKEN we can use a GET request and fetch the X-CSRF-TOKEN from the backend.
Select the GET A_PurchaseContract and click on Add and then select Header.
Enter Header Name as X-CSRF-TOKEN and Header Value as FETCH and EXECUTE.
With GET request response in the Request Header we will get CSRF token which then can be used in our POST calls.
Come back to Your POST request , enter CSRF token and execute.
If the contract creation is successful , you will get the 201 response and the response payload will have the newly created contract details.
In the below snapshot you can see that Purchase Contract 4600000351 was created .
If there's an error that can be seen in the response body and then can be corrected.