Runtimes
Web triggers
Async functions
Product REST APIs
Fetch APIs

Web triggers

Web triggers are incoming HTTPS calls that invoke a function, such as from a third-party webhook implementation. Web triggers are configured in the app’s manifest and the URL to call is created through the Forge CLI.

The request is serialized to JSON and passed to the function in the format described below. The function that is invoked is responsible for parsing the JSON data.

The HTTP response is formed from the JSON format described below. If the function result is not compatible with the JSON format, then an error response with status code 500 is sent.

See the web trigger module for more details.

Basic usage

Handler

Your handler should be defined as a function.

1
2
export const trigger = () => {
  return {
    statusCode: 200,
    headers: {},
    body: 'Hello, world!',
  }
}

Manifest definition

A web trigger module should be declared in the app manifest.

1
2
modules:
  webtrigger:
    - key: example
      function: my-function
  function:
    - key: my-function
      handler: index.trigger

Generating a URL

There are two ways to generate a webtrigger URL. If you are an administrator of an installation, you can run forge webtrigger via the CLI webtrigger command. Alternatively, you can programatically generate webtrigger URLs via the SDK.

Request

PropertyTypeRequiredDescription
bodystringHTTP request body.
headersobject

HTTP headers sent by the caller.

Format: nameOfTheHeader: array of strings

Example: "Content-Type”: ["application/json”]

methodstringYesHTTP method used by the client. For example: GET, POST, PUT, or DELETE.
pathstringYesPath of request sent by the caller.
queryParameters{ [key: string]: string[] }Parsed values from the query string on the request URL.
*anyAdditional properties are provided to support forward compatibility.

Example

1
2
{
  "method": "POST",
  "headers": {
    "Accept": [
      "*/*"
    ],
    "Postman-Token": [
      "5249865e-4106-447d-aa17-52df5e57c2b9"
    ],
    "accept-encoding": [
      "gzip, deflate"
    ],
    "User-Agent": [
      "PostmanRuntime/7.13.0"
    ],
    "content-length": [
      "71"
    ],
    "Connection": [
      "keep-alive"
    ],
    "Host": [
      "localhost:8080"
    ],
    "Cache-Control": [
      "no-cache"
    ],
    "Content-Type": [
      "text/plain"
    ]
  },
  "body": "{\n\t\"hello\": 1,\n\t\"test\": [\"foo\", \"bar\"],\n\t\"foo\": {\n\t\t\"bar\": \"hello\"\n\t}\n}",
  "path": "/x1/XUBR5WnG2Hk2V52APDdGaRSDm",
  "queryParameters": {
    "apples": [ "red", "green" ],
    "grapes": [ "green" ]
  }
}

Response

PropertyTypeRequiredDescription
bodystringHTTP response body sent back to the caller.
headersobject

HTTP headers sent by the caller.

Format: nameOfTheHeader: array of strings

Example: "Content-Type": ["application/json"]

statusCodeintegerYesHTTP status code returned to the caller.
statusTextstringText returned to communicate status. The text provides context to the status code.
*anyAdditional properties are provided to support forward compatibility.

Rate this page: