cloud-sdk-js
cloud-sdk-js copied to clipboard
UpdateRequestBuilder sending an empty payload as part of a batch/changeset request
I'm not sure if this is a bug, or possibly the way I am utilizing the generated OData v2 client. I am attempting to perform a batch request on a particular API, and noticed that the PATCH
method is not providing any payload in the changeset body. From the documentation, I'd expect the assignment of the paymentTerms and cashDiscountAmount to be in the payload based on the following statement:
The code above changed the first name of the given business partner. The payload sent to the service with PATCH includes only the first name.
If anyone could guide me on how to properly use the changeset/batch API in addition to updating an entity, it'd be appreciated. I also noticed that etag
and csrf
functionality of the client was not automatically handled, so I had to manually add the appropriate headers to get to this point. I kept that out of the paired-down sample below, but if CSRF handling should be automatic, guidance around how to get the auto-generated clients to handle it would be appreciated as well. The documentation led me to believe it's automatic.
Here's a sample of how I'm using a combination of batch
and changeset
to perform the request.
Dependencies:
"dependencies": {
"@nestjs/axios": "3.0.2",
"@nestjs/common": "10.2.7",
"@nestjs/platform-express": "10.2.7",
"@nestjs/testing": "10.2.7",
"@sap-cloud-sdk/connectivity": "3.15.0",
"@sap-cloud-sdk/http-client": "3.15.0",
"@sap-cloud-sdk/odata-v2": "3.15.0",
"@sap-cloud-sdk/util": "3.15.0",
"axios": "1.6.8",
"bignumber.js": "9.1.2",
"class-transformer": "0.5.1",
"class-validator": "0.14.0",
"moment": "2.29.4",
"rxjs": "7.8.1"
},
Code:
const {
entryViewItemsApi,
operations: { setEditable, setReadOnly },
} = facFinancialDocumentSrv01();
const entry = await entryViewItemsApi
.requestBuilder()
.getByKey('<accounting_document>', '<accounting_document_item>', '<company_code>', '2024', '')
.execute({ destinationName: 'DESTINATION' });
// --- Batch Requests ---
const editableRequestBuilder = setEditable({
accountingDocument: '<accounting_document>',
companyCode: '<company_code>',
fiscalYear: '2024',
});
const readonlyRequestBuilder = setReadOnly({
accountingDocument: '<accounting_document>',
companyCode: '<company_code>',
fiscalYear: '2024',
});
// Set fields on item
entry.paymentTerms = 'CUSTOM';
entry.cashDiscountAmount = new BigNumber(5.00);
const updateRequest = entryViewItemsApi.requestBuilder().update(entry).addCustomHeaders({
'if-match': entry.versionIdentifier,
});
const responses = await batch([
changeset(
editableRequestBuilder,
updateRequest,
readonlyRequestBuilder,
),
]).execute({ destinationName: 'DESTINATION' });
I am getting 415 responses from the server, so I added some middleware to output the request body to console, and noticed that the PATCH
request body is set to {}
when I would've expected it to be:
{"paymentTerms": "CUSTOM", "cashDiscountAmount": "5"}
--batch_a5e4fe59-20d8-4bed-ad1a-4c1b605182d6
Content-Type: multipart/mixed; boundary=changeset_d7a5a14d-b3b4-4ed6-ae30-0c07b96eeaeb
--changeset_d7a5a14d-b3b4-4ed6-ae30-0c07b96eeaeb
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Id: 11b46233-3ac5-419f-b8f4-0a8fe105826a
POST /sap/opu/odata/sap/FAC_FINANCIAL_DOCUMENT_SRV_01/SetEditable?FiscalYear='2024'&CompanyCode='<company_cod>'&AccountingDocument='<accounting_document>' HTTP/1.1
Content-Type: application/json
Accept: application/json
--changeset_d7a5a14d-b3b4-4ed6-ae30-0c07b96eeaeb
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Id: 6ffb551b-a4ee-4d53-998a-74cc63713a8e
PATCH /sap/opu/odata/sap/FAC_FINANCIAL_DOCUMENT_SRV_01/EntryViewItems(AccountingDocument='<accounting_document>',AccountingDocumentItem='<accounting_document_item>',CompanyCode='<company_cod>',FiscalYear='2024',Ledger='') HTTP/1.1
Content-Type: application/json
Accept: application/json
If-Match: W/"'6FB5547479391F921246BEFC9E5092D09E81DC1F'"
{}
--changeset_d7a5a14d-b3b4-4ed6-ae30-0c07b96eeaeb
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-Id: c3e43f42-cc1a-455e-b9b0-e1974fca1dd2
POST /sap/opu/odata/sap/FAC_FINANCIAL_DOCUMENT_SRV_01/SetReadOnly?FiscalYear='2024'&CompanyCode='<company_cod>'&AccountingDocument='<accounting_document>' HTTP/1.1
Content-Type: application/json
Accept: application/json
--changeset_d7a5a14d-b3b4-4ed6-ae30-0c07b96eeaeb--
--batch_a5e4fe59-20d8-4bed-ad1a-4c1b605182d6--
Thanks in advance!