Send or Receive Form URL Encoded Content

This procedure shows how to implement a flow to send or receive form URL encoded content.

The connectivity::rest function implicitly determines how the content is handled based on the payload. This parameter treats the payload as form data if the content type is application/x-www-form-urlencoded, and automatically converts the JSON key-value pair into form-data.

  1. Open the adapter definition document in Visual Studio Code.
  2. Define the action's input and output schema with key values.
    Sample code:
    "formData": {
          "type": "object",
          "properties": {
            "key1": {
              "type": "string"
            },
            "key2": {
              "type": "string"
            }
          }
        },
  3. Refer to the schema in the action as input and output schema.

    Sample code:

    "sendRecieveFormData": {
          "description": "",
          "displayName": "upload file",
          "execute": "flow:formDataFlow",
          "input": {
            "schemaType": "application/schema+json",
            "schema": {
              "$ref": "#/schemas/formData"
            }
          },
          "output": {
              "schemaType": "application/schema+json",
            "schema": {
              "$ref": "#/schemas/formData"
            }
          }
        },
  4. Create a flow with connectivity::rest parameter and pass the body as input.

    Sample code:

    {
                  "functionRef": {
                    "refName": "httpOutbound",
                    "arguments": {
                      "uri": "${.connectionProperties.baseURL + \"/orders\"}",
                      "method": "POST",
                      "headers":{
                        "content-type":"application/x-www-form-urlencoded"
                      }
                      "body": "${ .input}"
                    }
                  },
                  "actionDataFilter": {
                    "results": "${ .body } }",
                    "toStateData": "${ .output }"
                  }
                }

    Note:

    • In request phase, the connectivity::rest function automatically converts JSON input. For example, {"key1":"value1","key2":"value2"} to key1=value1&key2=value2.
    • If the response media type is application/www-form-urlencoded, in the response phase, the connectivity::rest function automatically converts the response payload. For example, key1=value11&key2=value21 to JSON {"key1":"value11","key2":"value21"}.
Complete sample code:
"flows": {  
   "UploadFileFlow" : {
      "id": "UploadFileFlow",
      "description": "UploadFileFlow",
      "version": "0.1",
      "start": "startState",
      "specVersion": "0.8",
      "functions": [
        {
          "name": "httpOutbound",
          "operation": "connectivity::rest",
          "type": "custom"
        }
      ],
      "states": [
        {
          "actions": [
            {
              "functionRef": {
                "refName": "httpOutbound",
                 "arguments": {
                  "uri": "${.connectionProperties.baseURL + \"/orders\"}",
                  "method": "POST",
                  "headers":{
                    "content-type":"application/x-www-form-urlencoded"
                  }
                  "body": "${ .input}"
                }
              },
              "actionDataFilter": {
                "results": "${ .body } }",
                "toStateData": "${ .output }"
              }
            }
          ],
          "name": "startState",
          "type": "operation",
          "end": true
        }
      ]
    }
}