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:

  1. Select the "My Digital Flows" option from the menu:



  2. Select the domain belonging to your user:



  3. 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.
      1. Name: Name that will show the node in the flow.
      2. 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.
      3. 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.
      4. 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.
      5. 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:



        1. 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.:

          1. Array: msg.payload[0].id

          2. Map: msg.pet[garfield]. Note that, in this case, the literal that acts as a map key has no quotes.

        2. 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:

    For example:


  4. 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:


  5. After selecting your operation to invoke, save the changes by clicking on the "deploy" button: 
  6. As for the response generated by the node, it will follow the following structure
    1. msg.statusCode: Return code of the API operation, or of the invoking node itself in case of error in the parameter insertion.
    2. 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.