Deploy a REST Endpoint

Description

With the implementation of a REST Enpoint you can easily connect your Application with COGNIGY.AI by using our REST interface.

This tutorial covers the necessary steps for creating and connecting a REST Endpoint. If you want to get information about assigning a Flow to the Endpoint and setting up the Data Management see Endpoints.

One Step Preparation Process

1 Create and Configure a REST Endpoint on COGNIGY.AI

1 Create and Configure a REST Endpoint

:link: On COGNIGY.AI

1.1 Create a REST Enpoint


First you have to create a Endpoint of type "REST" (see figure 1.1).

Figure 1.1: Creation of the REST EndpointFigure 1.1: Creation of the REST Endpoint

Figure 1.1: Creation of the REST Endpoint

1.2 Get the Endpoint URL


Move to the top of the Endpoint Configuration page and copy the Endpoint URL which is displayed above the General Settings (see figure 1.2).

Figure 1.2: REST Endpoint Configuration PageFigure 1.2: REST Endpoint Configuration Page

Figure 1.2: REST Endpoint Configuration Page

Final Step: Connect your Application to the Endpoint

:link: On Application of your choice

Requirements
Endpoint URL

After creating a REST Endpoint you are able to send POST requests to the Endpoint URL gathered in step 1.2. The body of the requests should have the following format:

{
  "userId":"userId",
  "sessionId": "someUniqueId",
  "text":"message text",
  "data": {
    "key": "value"
  }
}

Parameters
userId - a user ID of the end user in form of a string
sessionId - a unique ID that is used to track the current conversation in form of a string
text - message text that should get processed by the assigned flow in form of a string
data - message data that should get processed by the assigned flow in form of an object

๐Ÿ“˜

Sending text and data

You can use the REST Endpoint to send either text or data to your Flow. You can choose to send both, but at least one is required. If invalid text and invalid data is specified, then the REST Endpoint throws an error.

๐Ÿ‘

Session ID

The sessionId is a unique identifier that is used to keep the state of a conversation. This means that you should generate a new unique ID whenever a new conversation starts, and not on every message. For testing purposes, you can use whatever string value you like as the sessionId, and change it whenever you want a new conversation to start.

The response contains the output text, output data and the outputStack, which is an array of all Flow outputs. Since the Rest Endpoint will concatenate all Flow Outputs (e.g. all Say Nodes) into one text / data output, you can use the outputStack for debugging purposes.

{
    "text": "output2",
    "data": {
        "output": 2
    },
    "outputStack": [
        {
            "text": "output 1",
            "data": {
                "output": 1
            }
        },
        {
            "text": "output 2",
            "data": {
                "output": 2
            }
        }
    ]
}

That's it. You should be all set up to use the REST Endpoint you've created with a Flow of your choice.


Did this page help you?