Form-data in Request Method

The Request API can be used for form-data requests and the content-type used is: application/x-www-form-urlencoded.

Sample request:

config/requests.json

{
  "examplePostCall": {
    "schema": {
      "protocol": "https",
      "method": "POST",
      "host": "example.com",
      "path": "/form",
      "headers": {
        "Content-Type": "application/json"
      }
    }
  }
}

manifest.json

{
  "platform-version": "3.0",
  "modules": {
    "common": {
      "requests": {
        "examplePostCall": {}
      }
    },
    "support_ticket": {
      "location": {
        "ticket_sidebar": {
          "url": "index.html",
          "icon": "styles/images/icon.svg"
        }
      }
    }
  },
  "engines": {
    "node": "18.16.1",
    "fdk": "9.0.3"
  }
}

app/scripts/app.js

async function foo() {
  let body = {
    form: {
      name: "Tony Stark",
      age: 50,
      occupation: ["CEO", "Consultant", "Benefactor", "Mentor"],
    },
  };
  
  await client.request.invokeTemplate("examplePostCall", {
    body: JSON.stringify(body)  // Required: must be a string
  });
}request.invokeTemplate("examplePostCall", {body});
}