How to invoke REST APIs from the FlowEngine.
This tutorial will explain how to orchestrate REST API operations from the platform's FlowEngine.
With the new "OnesaitPlatform Rest API invoker" node, you will be able to invoke the different operations registered in the API Manager.
Let's see how you can use that node. To do this, follow the next steps:
- Select the "My Digital Flows" option from the menu:
- Select the domain belonging to your user:
- Once you are in the domain, drag a "OnesaitPlatform Rest API invoker"-type node to the flow, then double-click on it to see its properties.
- Name: Name that will show the node in the flow.
- REST APIs available: List of APIs that your user has available. Once an API is selected, the "REST API" and "REST API Version" fields will be filled in automatically.
- Operations available: List of operations of the selected API. Once an operation is selected, the "REST API Operation" and "Operation Method" fields will be filled in automatically.
- Timeout: Time in milliseconds that the node will wait to get a response from the invoked operation. If the runtime is longer than indicated, a "Connection timeout "error will be displayed.
- Operation input params: This is a dynamic list that will show all the parameters (path, query, body, header or multipart) required by the operation that we have selected. There are two ways to pass the values ​​to these parameters:
- msg.: Through the content of a message field (msg) received from the preceeding node. For example:
This way, the use of operators to access positions within an array or a map is allowed, e.g.:- Array: msg.payload[0].id
- Map: msg.pet[garfield]. Note that, in this case, the literal that acts as a map key has no quotes.
- Array: msg.payload[0].id
- String: Using a static value that you can type, for example:
NOTE: If one of the parameters is a file (multipart/form-data), the value must be retrieved from an incomming message field as follows:
Â
Â
The buffer must be the same type as the "File in"Â node in the default palette from Node-RED:
- msg.: Through the content of a message field (msg) received from the preceeding node. For example:
For example:
- Once you have finished filling in the required fields, you will see that the number of outputs of the node changes from one to several. Each node output will represent a statusCode that the operation has defined. In addition, one extra output will be added (labeled "??? - Other status code") where messages with statusCode other than other outputs will arrive. If you hover the cursor on the output pins, you will see the statusCode and a description:
- After selecting your operation to invoke, save the changes by clicking on the "deploy" button:Â
- As for the response generated by the node, it will follow the following structure
- msg.statusCode: Return code of the API operation, or of the invoking node itself in case of error in the parameter insertion.
- msg.payload: Operation's response (body response). It will always try to parse object. If this is not possible (depending on the operation of the selected API), it will remain as a String.