Invoke a GET API

This procedure shows how to create a flow to invoke a GET API.

The sample code implements a procedure that uses connection properties to retrieve API host information.

Prerequisites:

The action is defined in the schema. The header and parameters (query/path) are input to the action.

  1. Open the adapter definition document in Visual Studio Code.
  2. In the flows code section of the document, define the flow with a single state of Operation type.

    Sample code:

    "flows": {  
       "postOrdersFlow" : {
          "id": "postOrdersFlow",
          "description": "postOrdersFlow",
          "version": "0.1",
          "start": "startState",
          "specVersion": "0.8",
          "functions": [
             
          ],
          "states": [
            {
              "actions": [
                
              ],
              "name": "startState",
              "type": "operation",
              "end": true
            }
          ]
        }
    }
  3. Define a function with a unique name, of type custom, and operation connectivity::rest.

    Sample code:

    "functions": [
            {
              "name": "postOrdersFunction",
              "operation": "connectivity::rest",
              "type": "custom"
            }
          ]
  4. Add an action to the state where:
    • The action refers to the function created in step 2.
    • Arguments to function define the HTTP method, URI, parameters (template and query), and body.
    • Response passes through, and the result is set to output.

    Sample code:

    {
                  "functionRef": {
                    "refName": "postOrdersFunction",
                    "arguments": {
                     "uri": "${.connectionProperties.baseURL + \"/customers/{customer_id}\"}",
                      "method": "GET",
                      "headers": "${ .input.headers }",
                      "parameters": "${ .input.parameters }"
                    }
                  },
                  "actionDataFilter": {
                    "results": "${ { body: .body, headers: .headers } }",
                    "toStateData": "${ .output }"
                  }
                }
Complete sample code:
"flows": {   
   "getCustomersCustomerIdFlow" : {
      "id": "getCustomersCustomerIdFlow",
      "description": "getCustomersCustomerIdFlow",
      "version": "0.1",
      "start": "startState",
      "specVersion": "0.8",
      "functions": [
        {
          "name": "getCustomersCustomerIdFunction",
          "operation": "connectivity::rest",
          "type": "custom"
        }
      ],
      "states": [
        {
          "actions": [
            {
              "functionRef": {
                "refName": "getCustomersCustomerIdFunction",
                "arguments": {
                  "uri": "${.connectionProperties.baseURL + \"/customers/{customer_id}\"}",
                  "method": "GET",
                  "headers": "${ .input.headers }",
                  "parameters": "${ .input.parameters }"
                }
              },
              "actionDataFilter": {
                "results": "${ { body: .body, headers: .headers } }",
                "toStateData": "${ .output }"
              }
            }
          ],
          "name": "startState",
          "type": "operation",
          "end": true
        }
      ]
    }
}