2025 Jan 25 8:18 PM - edited 2025 Jan 25 8:44 PM
Hello Experts
I’m facing an issue with my custom Managed RAP OData V4 service integrated with a Node.js CAPM-based custom Fiori app. The app is a read-only report running in the SAP BTP environment.
To address payload query length issues, we have enabled the POST operation, and token handling for the remote service is configured as follows:
Remote service CSRF-token handling
To add POST support for this CDS-based root entity, I implemented a Behavior Definition to handle the create operation with Behavior Pool Class (with minimal code).
Now service metadata shows the supported formats.
However, the payload, upon reaching the backend S/4HANA system, results in the following error:
Error: "The resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request."
Despite the metadata correctly showing application/json as a supported format, the error persists. Simplifying the scenario, a single GET request (outside of the batch request) with Accept: application/json works perfectly. However, the issue arises specifically with the batching mechanism for the POST operation.
I came across @Andre_Fischers blog on Function Import, which discusses this concept, but I am unclear on how to apply it within the RAP framework.
How can I address the issue with the batching mechanism for POST requests? Is there something specific in the RAP framework or the request construction that I might be overlooking?
Any insights, examples, or suggestions would be greatly appreciated!
Thank you in advance for your support!
NW ABAP Gateway (OData) ABAP RESTful Application Programming Model Node.js SAP Fiori Elements SAP Cloud Application Programming Model
Request clarification before answering.
I finally able to fix it! I was using the wrong event handler to modify the request headers, which prevented the Accept: multipart/mixed header from being correctly applied to batch requests.
this.before('READ', 'remotesrv', async (req) => {
// Determine if the request is a BATCH request
const isBatchRequest = req.path.includes('/$batch');
if (isBatchRequest) {
try {
// Set the Accept header to multipart/mixed
req.headers['Accept'] = 'multipart/mixed';
delete req.headers['accept']; // Remove any existing 'accept' header
} catch (error) {
console.error('Error while manipulating headers:', error);
req.error(500, 'Error during header manipulation');
}
}
});
After switching to the correct event handler, the issue is now fixed, and the batch request is successfully processed with the expected headers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I’ve identified the root cause of the batch failure. The POST BATCH request (which consists of a GET call) expects the following header on the outer HTTP request:
Accept:multipart/mixed
Now, I need to ensure that these headers are applied only to batch requests and not to regular GET requests.
I’ve attempted to set this condition in my service.js file, but the implementation is only setting Content-Type to multipart/mixed, not the Accept header.
Service.js:
const cds = require('@sap/cds') // Importing the CDS framework
// Export the service implementation
module.exports = cds.service.impl(async function () {
const remotesrv = await cds.connect.to('<remote service>');
this.on('READ', 'remotesrv', async req => {
try {
// Determine if the request is a BATCH request
const isBatchRequest = req.path.includes('/$batch') || req.path.length > 800;
// Prepare headers dynamically
const headers = {
'Accept': isBatchRequest ? 'multipart/mixed' : 'application/json',
'Accept-Encoding': 'gzip, deflate',
'x-api-key': process.env.APIKEY,
};
// Send the request to the external service
return await remotesrv.send({
query: req.query,
headers,
});
} catch (error) {
console.error('Error while sending request:', error);
req.error(500, 'Error during external service call');
console.log('main service query', req.query);
}
});
Is there a better approach to reliably differentiate batch requests and ensure the correct headers are applied? anything at the package.json setting for remote service ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 6 | |
| 6 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.