Skip to Content
0
Jul 31, 2023 at 04:09 PM

$batch Request in SAP CAP Remote Service Call

411 Views

Hello Experts,

I am working on a CAP solution wherein I want to make multiple GET calls to SAP on-premise. So I decided to go with $batch request instead of individual calls.

The below code snippet shows how I made the call:

                let oSAPConnection = await cds.connect.to('approvalService_sapOthers');

                let oImportedCaseDetails = 
                    await oSAPConnection.send({
                        method: 'POST',
                        path: `/$batch`,
                        headers: { 'Content-Type': 'multipart/mixed;boundary=batch' },
                        data: 
                        `--batch
                        Content-Type: application/http
                        Content-Transfer-Encoding: binary
                        
                        GET LtFscmInfoSet('5406695') HTTP/1.1
                        

                        --batch--`,
                    });

In Package.json,

image.png

However, I am getting the error as follows:

2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR [remote] - Error: Error during request to remote service:
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR In the context of Data Services an unknown internal server error occurred
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at run (/home/vcap/app/node_modules/@sap/cds/libx/_runtime/remote/utils/client.js:306:31)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at async RemoteService.<anonymous> (/home/vcap/app/node_modules/@sap/cds/libx/_runtime/remote/Service.js:295:20)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at async next (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:79:17)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at async RemoteService.handle (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:77:10)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at async importCaseService.<anonymous> (/home/vcap/app/srv/importCaseService.js:46:21)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at async next (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:79:17)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at async importCaseService.handle (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:77:10)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at async /home/vcap/app/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js:52:16 {
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR statusCode: 502,
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR reason: AxiosError: Error during request to remote service:
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDOUT Error Occurred on SAP Connection: Error: Error during request to remote service:
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR In the context of Data Services an unknown internal server error occurred
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at settle (/home/vcap/app/node_modules/axios/dist/node/axios.cjs:1909:12)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at IncomingMessage.handleStreamEnd (/home/vcap/app/node_modules/axios/dist/node/axios.cjs:2989:11)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at IncomingMessage.emit (node:events:525:35)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at endReadableNT (node:internal/streams/readable:1359:12)
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDOUT In the context of Data Services an unknown internal server error occurred
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR code: 'ERR_BAD_RESPONSE',
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR config: {
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR timeout: 0,
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR xsrfCookieName: 'XSRF-TOKEN',
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR xsrfHeaderName: 'X-XSRF-TOKEN',
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR maxContentLength: -1,
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR maxBodyLength: -1,
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR proxy: false,
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR method: 'post',
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR baseURL: 'http://saphoxxxxet:443',
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR url: '/sap/opu/odata/sap/YxxxxATA_SRV/$batch',
2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR data: '--batch\n' + 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR ' Content-Type: application/http\n' + 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR ' Content-Transfer-Encoding: binary\n' + 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR ' \n' + 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR " GET LtFscmInfoSet('5406695') HTTP/1.1\n" + 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR ' \n' + 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR ' \n' + 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR ' --batch--' 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR }, 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR request: { 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR method: 'POST', 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR url: 'http://saphoxxxxet:443/sap/opu/odata/sap/YxxxxATA_SRV/$batch', 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR headers: [AxiosHeaders] 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR }, 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR response: { 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR status: 500, 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR statusText: 'Internal Server Error', 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR headers: [AxiosHeaders], 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR body: [Object] 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR }, 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR correlationId: '55435bd1-7d8d-4eb7-6d8a-f61aa7b10abf' 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR } 2023-07-31T15:34:48.545+0000 [APP/PROC/WEB/0] STDERR } 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR [cds] - Error: SAP Connection Error 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR at importCaseService.<anonymous> (/home/vcap/app/srv/importCaseService.js:70:21) 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR at process.processTicksAndRejections (node:internal/process/task_queues:95:5) 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR at async next (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:79:17) 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR at async importCaseService.handle (/home/vcap/app/node_modules/@sap/cds/lib/srv/srv-dispatch.js:77:10) 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR at async /home/vcap/app/node_modules/@sap/cds/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js:52:16 { 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR code: 400, 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR numericSeverity: 4, 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR id: '1350040', 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR level: 'ERROR', 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR timestamp: 1690817688546 2023-07-31T15:34:48.548+0000 [APP/PROC/WEB/0] STDERR } 2023-07-31T15:34:48.551+0000 [RTR/31] STDOUT hxxxx.cfapps.eu10.hana.ondemand.com - [2023-07-31T15:34:47.604128636Z] "POST /odata/v4/import-case/ImportCase HTTP/1.1" 400 10 85 "-" "PostmanRuntime/7.28.4" "10.0.136.5:30146" "10.36.193.16:61111" x_forwarded_for:"103.28.246.145, 10.0.136.5" x_forwarded_proto:"https" vcap_request_id:"55435bd1-7d8d-4eb7-6d8a-f61aa7b10abf" response_time:0.947239 gorouter_time:0.048076 app_id:"e2b28e07-b36c-435d-92d3-73cab0636550" app_index:"0" instance_id:"3e6e266b-f9d9-4c44-6a04-a388" x_cf_routererror:"-" x_correlationid:"-" tenantid:"-" sap_passport:"-" x_scp_request_id:"1cc70c70-17b4-4981-9668-f5873aede14a-64C7D497-3E32D12" x_cf_app_instance:"-" x_forwarded_host:"-" x_custom_host:"-" x_ssl_client:"-" x_ssl_client_session_id:"-" x_ssl_client_verify:"-" x_ssl_client_subject_dn:"-" x_ssl_client_subject_cn:"-" x_ssl_client_issuer_dn:"-" x_ssl_client_notbefore:"-" x_ssl_client_notafter:"-" x_cf_forwarded_url:"-" traceparent:"-" x_b3_traceid:"55435bd17d8d4eb76d8af61aa7b10abf" x_b3_spanid:"6d8af61aa7b10abf" x_b3_parentspanid:"-" b3:"55435bd17d8d4eb76d8af61aa7b10abf-6d8af61aa7b10abf"
If a batch request is still not supported in CAP, is there any alternative to achieve this? I have checked SAP Cloud-SDK for batch requests. But is there anyone who achieved it through that? If so, kindly share some sample codes.

Attachments

image.png (41.2 kB)