Call SAP Conversational AI API Using OAuth
- How to retrieve an OAuth token for use with SAP Conversational AI API
- How to call SAP Conversational AI API via OAuth
Prerequisites
- You understand the basics of creating a chatbot, as described in the tutorial Build Your First Chatbot with SAP Conversational AI.
- Python
- VS Code with the Python extension by Microsoft, though you can use any Python development environment. See Getting Started with Python in VS Code.
- Flask package for Python
- Requests package for Python
- Flask-Caching package for Python
- You have created a chatbot that you would like to call. If not, create a new chatbot with the Greetings skill.
This tutorial is a companion to the tutorial Call SAP Conversational AI API Using OAuth (Postman), which lets you just test the APIs via a simple Postman collection. Here, you will make a more sophisticated simulation, including building a web server and using caching to store the OAuth token.
What you will build
This tutorial demonstrates the basics for calling the SAP Conversational AI API using an OAuth token, which is the required way for all new chatbots. The request
endpoint of the Runtime API is called, which sends an utterance only to the NLP for understanding, but the principles are the same if you used the dialog
endpoint.
To make things more interesting, you will create a simple web server that:
- Takes an utterance via a URL parameter.
- Retrieves an OAuth token, using the chatbot’s client ID and secret.
- Calls the NLP via the
request
endpoint, sending the OAuth token as authentication.
Best practices call for only retrieving the OAuth once, and then caching it for all subsequent calls. We will use the
flash_caching
package to store the token.