Skip to Content
Technical Articles
Author's profile photo Daniel Wroblewski

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 (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 SettingsVersionsRequest 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 SettingsTokensOAuth 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.

 

Assigned Tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Allen Chew
      Allen Chew

      Nice blog. It is helpful. Thank you.

      Author's profile photo Praveer Sen
      Praveer Sen

      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)

       

      Please suggest, am I missing any value.
      Best Regards,
      Praveer
      Author's profile photo Daniel Wroblewski
      Daniel Wroblewski
      Blog Post Author

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

      Author's profile photo Sunil Joseph
      Sunil Joseph

      Hi Daniel,

       

      Regarding

      Add headers:

      • Add a header called X-Token, and set the value to the request token, which you can find in your bot at SettingsVersionsRequest Token. This indicates the version of the bot you want to call.

       

      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,

       

      Author's profile photo Sunil Joseph
      Sunil Joseph

      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

      Author's profile photo Daniel Wroblewski
      Daniel Wroblewski
      Blog Post Author

      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.