Skip to Content
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

 

 

 

 

 

28 Comments
You must be Logged on to comment or reply to a post.
  • 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

  • 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

  • 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.

     

     

  • 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

    • 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.

  • 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

      • 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