Technical Articles
SAP CAI Chatbot Integration with ERP just have become Super Easier! for ABAPer
Hello Everyone,
Welcome to my another interesting blog on recently released SAP Conversational AI new features “Consume API Service”. In this blog i would try to discuss what is the benefit, how to use this feature, why chatbot integration just become super easier using this feature specially for ABAPer.
So what is Consume API Service ?
For example you are designing a chatbot which will give you purchase requisition status from ECC or S/4HANA system then before “Consume API Service” we used to build a wrapper service based on node.js or python or java which as Webhook. And this wrapper normally we used to host either on SAP Cloud Platform Cloud Foundry or some other cloud provider like AWS, GCP. At the same time if some one is from ABAP background and dont know how to build wrapper using node.js or python is quite challenging to build such chatbot completely for him/her/others. But this Consume API service is just making everyone’s job easy, don’t need to build any wrapper direct calling odata can give you instant result.
After releasing this feature i am like 😛
So How is the Technical Architecture?
If you look at the Architecture, we don’t node.js based Webhook application which normally runs on SAP Cloud Platform Cloud Foundry. I have used oData provisioning service because odata service need to be exposed into internet and my conversational AI is developer version which doesn’t come as SAP Cloud Platform Service. if you are having productive SAP Conversational AI which comes as Cloud Platform Subscription then you can directly connect cloud connector, don’t need any oData provisioning service.
What is the benefit?
You don’t need to build any wrapper node.js, don’t need to run any express Application or Python application which work as a Webhook. Direct integration with oData service.
How to use this Feature?
Let’s discuss the main thing which we are waiting for. I am not going to discuss here how to build SAP oData service which will fetch purchase requisition status. Rather we will focus on how we can call the odata service directly.
Lets break this whole integration into small step.
Step 1: Exposing backend oData through cloud connector and oData provisioning service (Prerequisite)
As a prerequisite you need to setup your cloud connector and oData provisioning service for exposing your On Premise oData into internet.
Please have a look at the very informative blog for how you can expose your backend odata into internet through Cloud connector and oData provisioning service (Formarly Known as Gateway as Service)
Step 2: Analyzing Postman or oData response
So i have already exposed odata service which is exposed through cloud connector and oData provisioning service and below is my postman call response. (i have passed Accept : Application/json in header to get json Response and Authentication type is basic your SCP P/S/D/C/I username and Passowrd)
This odata service is very simple which return a status for a purchase requisition as you can see. Here i am passing purchase requisition number as filter. Now if you look at the JSON response and if i want to access requisition status then its pretty easy which is d.results[0].ProcStat.
Step 3: Building Chatbot and use Consume API service feature
If you are very new to Chatbot development and still wondering how to build your first chatbot then look at this awesome tutorial
so in this case i have designed my intent and skill like below
And Skill is like below
So this pr variable is going to store purchase requisition number and which we will be using it as filter parameter in action of the skill. Now go to action and click on add new message group then click on connect external service -> Consume API service.
As it is GET call, select type as GET and use {{memory.pr.scalar}} as filter parameter. In Authentication use your SCP username and password
Now lets analyze the response of this API service.
This response part is non editable, and api_service_response variable is going to hold whole response from your odata. So this is how it looks like.
"api_service_response": {"default" : { "body":{odata response in json}}}
So if you want to access the purchase requisition status then below is how its look like {{api_service_response.default.body.d.results[0].ProcStat}}
so we just have to just add another text type send message below of this action to send purchase requisition status to user and then clear memory step like below.
Step 4: Test your chatbot
That’s it, i hope you learned something cool, if you enjoyed this blog please like, share and comment.
Regards,
Sudip
Great blog, keep up the good work!
Thank you so much for such comment 🙂
Great blog, was long waiting for this. Thank you so much
Great to know, I hope you enjoyed this blog
Hi Sudip Ghosh,
I tried consuming a oData Service in a Chatbot by following the steps which you have mentioned in the blog, but my oData Service is throwing below error and failing to load the service, Can you please let me what could be the reason for this.
Regards,
Krish
Hello Krish,
First make sure your odata service is reachable over internet, can you share the postman response format of your odata service.
Regards,
Sudip
Hi Sudip Ghosh
My oData service is reachable over internet from the postman, but when i try to consume the same odata service in Action(Chat Bot) its throwing me the above error. Can you please help me out with this.
Regards,
Krish
can you post here url and header of your api consume in sap cai
Hi Sudip,
Below is the url..
https://gwaas-p1942647343trial.hanatrial.ondemand.com/odata/IWBEP/GWSAMPLE_BASIC/SalesOrderSet/?$filter=SalesOrderID eq '0500000000'
Regards,
Krish
Please add in header another field Accept : application/json
Hi Krishnakanth Gajula,
Did you fix this issue? I am also facing the same issue and same error message.
Please help if you fix the same error message.
Thanks in advance.
Regards,
Sandip
Hi Sudip,
I have added Accept : application/json in header but HTTPS call is throwing error message.
Surprisingly ODATA with HTTPS is working in web browser but its failing and throwing error message with HTTPS.
Please help.
Thanks,
Alok
Hi Sudip,
Can you give an example on how to make a post request call using CONSUME API SERVICE? Because before making a POST call, we need to fetch the x-csrf-token using a GET call. How do we fetch the token and pass it to the POST call?
Regards,
Sangita Purkayastha
i didnt try it for POST based call, I guess it is only made for get call, if you want to create some thing then you have to handle it in get entity set method only as there is no scope i can see for fetching csrf as of now
Hi Sangita,
you can make POST calls using the "Consume API Service", but it is currently not possible to extract a x-csrf-token and cookie headers of a previous GET call. This is something we're planning to support in future.
Currently the only option would be to have a service (e.g. node.js) that would make the GET call, extract the x-csrf-token and cookie as header and return it in the body. Then in your skill you can first call this service to fetch the token and cookie and use them for any "Consume API Service" actions by referencing the corresponding {{api_service_response}} variable.
You might also want to check if your OData service can be accessed with another authentication type, which does not require cookies and x-csrf-token, as these are usually only required for browser-based communication scenarios and not for server-to-server communication.
Regards
Jonas
Jonas Brand Thank you so much for clarifying, I really appreciate this 🙂
Are there any updates on this features?
Hi Jonas,
Is there any update on this feature of extracting x-csrf token?
Thanks
Hi all,
in the meantime there was an "Include headers" option added in the "Response" tab of an API service configuration, which allows when enabled to access the headers via {{api_service_response.namespace.headers}} variable.
See https://help.sap.com/viewer/a4522a393d2b4643812b7caadfe90c18/latest/en-US/6791b54dc72c4b64ad9883c2470001fb.html for details.
Regards
Jonas
As ABAPer, it will help me a lot. Javascript at SAP WEB IDE was killing me!
Anyway, I need to try some stuff, for example we have quickreplies (buttons) developed at node.js side with the oData information. I guess the Odata service developed in ABAP will not be enough to skip this transformation.
Try it and let me know, other people tried and made it working
Nice blog.. I tried it out and was glad to see my bot working 🙂
Hello Dinu,
I am glad that you tried and it is working.
Regards,
Sudip
Hi Sudip,Amazing blog, couldn't stop my self trying this out.But Unfortunately it is not working for me..I always get "No Reply" from bot.I can access my service in postman after odata provisioning.Please guide
Hello Hitesh,
Please can you share screenshot of your header details and also authentication part
Header
Ahhh! check your object properly where is your array number [0] , check mine one {{api_service_response.default.body.d.results[0].ProcStat}}
Thanks a lot such quick response.Path is correct.I even hardcoded the PO number.
Seems it is not connecting to resource, i tried with an amazon service also.NO idea what is wrong here. In monitoring i see "There are no entries here"
You can try adding {{api_service_response.default.status_code}} and {{api_service_response.default.body}} to a "Send message" action to see what the service returns. If these are completely empty, it means that the call itself failed, then please check the debug log for details (switch on "Debug" in the top of the "Test your bot").
Also make sure you did not set any namespace in "Response" tab.
Hello Jonas Brand and Sudip Ghosh ,
I have tried both - {{api_service_response.default.status_code}} and {{api_service_response.default.body}} in 'Send Message'
and I am getting status as '200' but nothing in 'body'. Where are all going wrong . I can see many people have this issue.
Amit
Hello Jonas Brand and Sudip Ghosh
I understand the issue now -> we are passing Sales Order ID as '0500000483' but bot is removing 0 from the beginning. How to tackle this situation ?
I have checked the response in the memory variable it is removing '0' from the beginning. Thus it is not returning any result.
I am using #number in 'Required Information' to save SalesOrderID in memory of Bot.
It would be helpful if you could guide us.
Amit
Hi Sudip,
I want to print this long text in the chat box as multi-line
'''''
Overall Picking / Putaway Status is : Completely processed \n Overall Goods Movement Status is : Not yet processed \n
"""
but \n is not working any suggestions please
Hi Sudip,
My url of odata service is of http and in cai chat bot we can only use https or use destination so any suggestion or anything that can work on
Thanks in advance
create a wrapper in api management and make it https
Hi Sudip,
If my Odata service required authentication then ?every time i am accessing it from browser i need to enter my login id for that then how to add that credential in this. do I have to add it in header? or in basic authentication tab. I am getting timed out error every time.
Thanks
Hi Sudip ,
Can you please elaborate more on how can we make it https ?
I am facing issue and have tried various options but not able to test the chatbot , any help will be highly appreciated .
Regards & Thanks,
Ashwani Rohilla
Create a wrapper HTTPS API using API management and use that wrapper API URL with https. it would work if you don't have SSL installed.
Hello Sudip,
Thank you for this great blog, I tried it and it is working, but I have a question here.
I want to create a list as response and want to display more than 4 rows of list, manually I can achieve it by giving results[0], results[1]..etc are there any dynamic way to display the results in array?
Thanks in advance
HI Sudip,
This is very nice blog for new learns form ABAP.
I have one doubt why we have to connect HANA cloud connector and Odata Provisioning.Why can't access directly to Odata service in SAP CAI .
My scenario like we are using azure gatway to connect the OnPrimes HANA systems.
Postman it is success
Postman response
But if we trying in CAI I got below path building failed error .
"https://XXXXXXXXXcloudapp.azure.com:2010/sap/opu/odata/sap/ZCDS_OD_VIEW2_CDS/ZCDS_OD_VIEW2\": PKIX path building failed: Details: unable to find valid certification path to requested target; nested exception is Details: PKIX path building failed: Details: unable to find valid certification path to requested target",
CAI Action
Please help me on this.
Thanks ,
Satish
If your odata service is already exposed to internet then you dont need cloud connector and odata provisioning.
Hi Sudip,
Your blog made me excited to try it. But facing an issue which I'm unable to solve. Hence I'm stuck. Please help.
My Cloud Connector is reachable.
I'm able to access service catalogs from WebIDE while creating Fiori App.
The problem is with ODATA Provisioning.
I have enabled OData provisioning in my Neo trial account. I have also assigned the GW_Admin and GW_User role to my s-user. Still, when I try to access the "Destination" tab under Configure Service, it shows me "UNAUTHORIZED!" - 401 error. Can you please help me in setting up this?
I have already refered to :
https://help.sap.com/viewer/a7c6d8a0bd1f415887f6246d8cf8e68e/Cloud/en-US/9737448d0cc4429cae53921b882e2206.html
And Note - 2669874 - ODATA Provisioning Administration Error - You do not have sufficient authorization to access this page
Hello,
Did you solve your problem?
I'm heaving the same issue.
Thanks.
Hi Sudip,
I am getting below error. Can you please help?
Regards,
Jayant
Hi Sudip ,
I also followed the similar steps and tried to add ES5 data, but once I click on yes I am not getting any responses.Could you please suggest.
Responce Error
Hello Sudip and thanks a lot for your blog.
I can run the https URL for my OData Provisioning Service but when running it from Postman i always have the message:
Hello Sudeep,
I am facing issue in this step-
Step 1: Exposing backend oData through cloud connector and oData provisioning service (Prerequisite)
I read the blog you shared in link but i am not able to see Neo account on my HCP home page.
Can you please guide me on this step.
Thanks ,
Rashika
Neo is no more.. so you need extension factory service to do the same
Hi Sudip, I also faced somewhat same problem. I was unable to locate the OData provisioning on the HCP. After some analysis, came to know about the Serverless runtime service which has OData provisioning as a part. Your views on using serverless runtime?
Hello Sudeep,
Can you help me with some steps or share any document to expose my on premise odata service to internet using Extension factory service as you said?
And also i am using the trial version of CAI , do i need the enterprise edition in order to connect my CAI bot to my Odata service?
I contacted you on linked earlier but you were on vacation that time.
Can you spare some time anytime soon to help me in this topic. It will be really helpful.
Thanks & Regards,
Rashika