cancel
Showing results for 
Search instead for 
Did you mean: 

How to use fields from oData $Batch call response in SAP CAI

nilesh0916
Discoverer
0 Kudos
448

Dear Experts,

Greetings!

I am building chatbot interaction in SAP CAI.

I am reusing api designed for fiori use and need to make $batch call to get required data from SAP. This $batch returned lots of addition $batch call related information besides json response contained in it. I am not able to use this $batch call response using syntax {{api_service_response.default.body.d.fieldname}}. How to use STATUS field value from $batch call response. Highly appreciate your help in making this work.

Thank you in advance.

Nilesh

my $batch call response is like this:

--0019833333333

Content-Type: multipart/mixed; boundary=00198C6D80DA8DAD05DA0CBAD2C2FBF01

Content-Length: 3104

--00198C6D80

Content-Type: application/http

Content-Length: 7777

content-transfer-encoding: binary

HTTP/1.1 201 Created

Content-Type: application/json

Content-Length: 7777

dataserviceversion: 2.0

accept: application/json

user-agent: PostmanRuntime/7.28.4

accept-encoding: gzip, deflate, br

b3: 99999999

cookie:

...

...

traceparent: 99999

tracestate: 9999999999

x-b3-spanid: 999999999

x-b3-traceid: 99999999999

x-cf-applicationid: 9999999999

x-cf-instanceid: 999999999999

x-cf-instanceindex: 999

x-dynatrace: FW4;-99999999999999999

x-dynatrace-application: v=2;

x-dynatrace-requeststate: agentId=999999999

x-forwarded-for: 99.999.99.99

x-forwarded-port: 9997

x-forwarded-proto: https

x-request-start: 4466777

x-ruxit-forwarded-for: 177.55.54.55

x-scp-request-id: 55555556677

x-vcap-request-id: 44556666

sap-client: 999

host: dxxxxxx:9999

location: https://dxxxxxx:9999/sap/opu/odata/sap/ZOD_XXXXXXXXX_SRV/SxxxxxSet('--vbeln---')

{“d”:{“__metadata”:{“id”:“https://dxxxxxx:9999/sap/opu/odata/sap/ZOD_XXXXXXXXX_SRV/SxxxxxSet('--vbeln---')”,“uri”:“https://dxxxxxx:9999/sap/opu/odata/sap/ZOD_XXXXXXXXX_SRV/SxxxxxSet('--vbeln---')”,“type”:“ZOD_XXXXXXXXX_SRV.SxxxxxSet”},“IHREZ”:“R0000000346",“VBELN”:“--vbeln---",“AUART”:“FR”,“SELECT”:false,“EBELN”:“”,“LIFSK”:“Released”,“SO_DATE”:null,“IDOC_DATE”:null,“IDOC”:“”,“RCVPRN”:“”,“REC”:“”,“STATUS”:“Action successful Genarated Idoc number : ---idoc no-----”,“SxxxxxToXPUDet”:{“__deferred”:{“uri”:“https://dxxxxxx:9999/sap/opu/odata/sap/ZOD_XXXXXXXXX_SRV/SxxxxxSet('--vbeln---')/SxxxxxToUDet”}}}}}

--00198C6D80--

--0019833333333--

Accepted Solutions (1)

Accepted Solutions (1)

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos

SAP Conversational AI's Consume External Service expects a JSON object back, but if you give something else it will still give you the answer in

{{api_service_response.default.body}}

So you can then do some string manipulation. You could take the string, split it at ["STATUS":], then split it again at the next comma, and take the first value in the list. The start of the coding would be the following, which would give you the start of the data you want: "Action successful Genarated ....

{{itemAt (split api_service_response.test.body "STATUS\":") 1}}

Of course you'd have to be sure of the text format. You could also create a webhook, and there you could do whatever you want to parse the response, and return to the chatbot a message/memory update.

nilesh0916
Discoverer
0 Kudos

Hi Daniel, Thank you so much for your help. It worked as expected.👍

Answers (0)