Integrating external APIs¶
Prisme.ai provides differents tools to integrate your asssistant with your own custom API.
Whether they are written in NodeJS, Python, Java or anything else, the only condition is that they can receive & send JSON requests / responses.
In order to call APIs processing data other than JSON, thanks to use the Function resource in order to write your content specific parsing code.
For JSON APIs, the returned response can be of 2 kind :
- raw data that you can store in a variable for future processing in your current workflow (more actions or visual display)
- Prisme.ai workflow which would be directly run by your assistant, including any sort of action, logic or visual block you may use from your own dashboard
Method 1 : API Resource¶
An API Resource should fit with the majority of use cases as it provides several HTTP options (http method, get parameters, request body, http basic auth, http headers, ...).
Unless you customized your request body, your API will receive a default structure contextualizing the current user request (user message, intent name, intent parameters, ...).
In order to process or display the API result, differents cases exist :
- a. The API implementation might be changed to format its response as a Prisme.ai standard workflow
- b. Result is ready-to-process raw data
- c. Result needs to be first transformed
A : Prisme.ai standardized workflow¶
Once the API adapted, there is nothing left to do. Each HTTP call to your API with a properly formatted response will be automatically executed as any other Prisme.ai workflow, allowing you to build complex workflows with more actions, repeat, conditions or visual responses directly from your API.
More information on workflows here.
B : Ready to process raw data¶
The 2 options JSONPathFilter and output of your API resource let you respectively target a JSON path to extract and configure in which variable the extracted result will be saved. From now, every next step of your workflow will be able to use this result into visual messages or further processing.
If the extracted result is a list, we could for example use a repeat block to display each row as a card.
C : Result needs to be first transformed¶
If your returned data format is not directly usable in your workflow, we can use a function resource to prepare and transform data in a ready-to-use format.
As for case B, the JSON response would be saved in a variable configured by output, to which your custom function could access inside its input request parameter.
Method 2 : Function Resource¶
It may happen that API resource options do not allow to properly format your request as expected.
Inside the same function, you could also apply further processing on your request result (like in 1C) before saving it in another variable configured by the function output.
Instead of saving it your result in another variable, the function could also return directly executable workflow exactly like for APIs.
Method 3 : Writing your own proxy webhook¶
This small webhook would receive JSON requests automatically built with method 1, translate them into the appropriate format expected by your backend API and translate / forward its response into any JSON format exploitable by Prisme.ai, like raw data that you could iterate on using repeat blocks or a directly executable workflow.