Technical Articles
You now must call chatbot APIs with OAuth – here’s how
Since February, you have had to use an OAuth tokens to access SAP Conversational AI APIs for new bots. It’s simple, and I have written 2 tutorials on how to retrieve and then use the OAuth token to make API calls.
- Call SAP Conversational AI API Using OAuth: Shows how to create a Python web server with Flask, get the OAuth token, cache the token, and then call the API.
- Call SAP Conversational AI API Using OAuth (Postman): Shows how to create a Postman collection of calls that determine when you need to refresh the OAuth token and then how to get it and make API calls. It’s a little more than what you need, but it’s a good chance to understand some of the Postman functionality, how to script, how to string multiple calls together, and how to set up tests.
Quick Call from Postman
I suggest you do the tutorials above. But I also wanted to show you how to use the OAuth functionality of Postman to quickly call the APIs. Here’s how:
- Open Postman and create a new request.
- Set the URL to https://api.cai.tools.sap/v2/request and the method to POST. (Really, you should doublecheck the URL is correct when you get the token for your bot, lower down, there it will show the correct URLs for the SAP Conversational AI request APIs.)
- Set the body to raw with the following JSON (or whatever message you want to send to your bot):
-
{ "text" : "hi" }
- Add headers:
- Add a header called X-Token, and set the value to the request token, which you can find in your bot at Settings → Versions → Request Token. This indicates the version of the bot you want to call.
- Add a header called Content-Type and set to application/json.
- Under Authorization, set the type to OAuth 2.0, and in the form enter the Auth URL, Client ID and Client Secret. These parameters can be find in your bot at Settings → Tokens → OAuth Client.
- Click Send.
You should now get the intents and entities from the NLP.
You can do the same to get the messages for the user using the /dialog API.
Here’s the documentation on how to configure the runtime API calls, including the payload you can send.
And, of course, check out all the SAP Conversational AI tutorials.
Nice blog. It is helpful. Thank you.
Hi Daniel Wroblewski ,
Thanks for the details steps to try api call using postman.
However I am getting unauthorised response on posting for /dialog or /request url.(image attached)
I tried it again and it worked ... except, that when I used the URL I original gave (https://api.cai.tools.sap/train/v2/request) I got a 404 error. I changed it to:
https://api.cai.tools.sap/v2/request
And now I get the response.
Really, you should check where you get the bots token from to get the correct URL. I will update the blog. I looked at your screenshots and everything seems OK (though I don't see the headers and I can't vouch the client ID/secret are correct).
Hi Daniel,
Regarding
Add headers:
Strangely I dont see the request token under versions on the bots I created. Is there some other prerequsites that need to be turned on for that? I am using the community edition,
Sorry Daniel. The Request portion exists and it did not occur to me to use the down arrow. I apologize to have raised a non existant issue.
Thanks and Regards
Sunil
Don't be silly. I will look over the blog/tutorial and see if I can explain it better so it is clearer. Sorry for the confusion.