Enterprise Resource Planning Blogs by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
Previous blogs cover the GET and POST operation for the Purchase Contract API.

In this blog we will see the PATCH (Update) and POST (Create a New Item),

It should be noted that the Update operation is only allowed for the contracts which are in approved status. In approval contracts can not be updated and the API will throw an error in the API response for this case.



The purchase contract API supports update request in the form of BATCH requests only. With each Update request it is required to send a X-CSRF-TOKEN without which the request will fail. Process to get the CSRF token from the backend is covered in the previous blog.



The Batch requests also supports the GET calls as depicted above.

Payload to update Header Data (A_PurchaseContract)-

--request-separator

Content-Type: multipart/mixed; boundary=changeset

--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary

PATCH A_PurchaseContract(PurchaseContract='4600000351') HTTP/1.1

Content-Type: application/json

Accept: application/json

{"SupplierRespSalesPersonName" : "Test 1234"}

--changeset--

--request-separator--



A successful response can be seen in the above snapshot and the contract was update successfully.

Kindly note that in the request we had used PATCH with A_PurchaseCOntract (The header node) , for each update request it is required to send the correct key values in the payload.

For each entity key fields can be found here-

https://help.sap.com/viewer/bb9f1469daf04bd894ab2167f8132a1a/1911.500/en-US/f73c465833a40846e1000000...

The fields with Mandatory tags are the keys.

Easiest way to get the keys and it's value is to first perform a GET call or if you have the correct key values you can create your payload accordingly.

If you want to see the format of key data you can check out various GET operations - for example

For Item -



For Partners -



Sample payload for Item update (A_PurchaseContractItem)-

--request-separator

Content-Type: multipart/mixed; boundary=changeset

--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary

PATCH A_PurchaseContractItem(PurchaseContract='4600000351',PurchaseContractItem='10') HTTP/1.1HTTP/1.1

Content-Type: application/json

Accept: application/json

{ "TargetQuantity": "2500" }

--changeset--

--request-separator--

The above request cover the PATCH requests and used to update the existing header or item data.

The request to create a new item uses the POST request in the same batch call. Easiest way to get the payload for an item creation is to use a GET request to fetch the existing Item data.



Copy the response



Change the data as per your requirement , Change the Item number to 20.

Sample Payload-

--request-separator

Content-Type: multipart/mixed; boundary=changeset

--changeset

Content-Type: application/http

Content-Transfer-Encoding: binary

POST A_PurchaseContractItem HTTP/1.1

Content-Type: application/json

Accept: application/json

{

"PurchaseContract": "4600000351",

"PurchaseContractItem": "20",

"PurchasingContractDeletionCode": "",

"PurchaseContractItemText": "sample api Item 20",

"Plant": "1010",

"StorageLocation": "",

"RequirementTracking": "",

"MaterialGroup": "L004",

"SupplierMaterialNumber": "",

"OrderQuantityUnit": "EA",

"TargetQuantity": "31",

"PurgDocReleaseOrderQuantity": "1",

"OrderPriceUnit": "EA",

"OrderPriceUnitToOrderUnitNmrtr": "1",

"OrdPriceUnitToOrderUnitDnmntr": "1",

"ContractNetPriceAmount": "203.00",

"DocumentCurrency": "USD",

"NetPriceQuantity": "1",

"TaxCode": "",

"StockType": "",

"IsInfoRecordUpdated": "",

"PriceIsToBePrinted": true,

"PurgDocEstimatedPrice": false,

"NoDaysReminder1": "0",

"NoDaysReminder2": "0",

"NoDaysReminder3": "0",

"OverdelivTolrtdLmtRatioInPct": "0.0",

"UnlimitedOverdeliveryIsAllowed": false,

"UnderdelivTolrtdLmtRatioInPct": "0.0",

"PurchasingDocumentItemCategory": "0",

"AccountAssignmentCategory": "K",

"MultipleAcctAssgmtDistribution": "",

"GoodsReceiptIsExpected": true,

"GoodsReceiptIsNonValuated": false,

"InvoiceIsExpected": true,

"InvoiceIsGoodsReceiptBased": false,

"IsOrderAcknRqd": false,

"PurgDocOrderAcknNumber": "",

"ShippingInstruction": "",

"ManualDeliveryAddressID": "1438925",

"VolumeUnit": "",

"Subcontractor": "",

"EvaldRcptSettlmtIsAllowed": false,

"Material": "",

"ServicePerformer": "",

"ProductType": "01"

}

--changeset

Content-Type: multipart/mixed; boundary=changeset

Content-Type: application/http

Content-Transfer-Encoding: binary

POST A_PurCtrAccount HTTP/1.1

Content-Type: application/json

Accept: application/json

{

"AccountAssignment": "1",

"PurchaseContractItem": "20",

"PurchaseContract": "4600000351",

"IsDeleted": false,

"Quantity": "100",

"OrderQuantityUnit": "EA",

"MultipleAcctAssgmtDistrPercent": "0.0",

"PurgDocNetAmount": "0.00",

"DocumentCurrency": "EUR",

"GLAccount": "10010000",

"BusinessArea": "",

"CostCenter": "",

"SalesOrder": "",

"SalesOrderItem": "0",

"SalesOrderScheduleLine": "0",

"MasterFixedAsset": "",

"FixedAsset": "",

"OrderID": "",

"GoodsRecipientName": "",

"UnloadingPointName": "",

"ControllingArea": "A000",

"CostObject": "",

"ProfitCenter": "",

"ProjectNetwork": "",

"RealEstateObject": "",

"PartnerAccountNumber": "",

"CommitmentItem": "",

"JointVentureRecoveryCode": "",

"FundsCenter": "",

"FunctionalArea": "",

"SettlementReferenceDate": null,

"TaxCode": "",

"TaxJurisdiction": "",

"NonDeductibleInputTaxAmount": "0.00",

"CostCtrActivityType": "",

"BusinessProcess": "",

"EarmarkedFundsDocument": "",

"GrantID": "",

"BudgetPeriod": "",

"WBSElement": ""

}

--changeset--

--request-separator--

The above payload have 2 POST requests in the same BATCH call -

1. Create a new item and

2 . Create a new Account Assignment for the Item.

If you do not want the Account Assignment for the item , just remove the second POST call.

A successful response will have the newly created items's data.

7 Comments