Webhook
Availability table
Module |
Available |
|---|---|
webhook controller
Helper used by scripts triggered through a webhook. Parse the script parameters with
webhook.parseArgs(trigger.parameters) to obtain a webhook.WebhookRequest(), which
exposes the incoming HTTP request (method, headers, body and query parameters) and lets the script build
the HTTP response returned to the caller.
(see webhook documentation).
- webhook.parseArgs(args: object)
Parses the webhook HTTP request from the script parameters.
- Arguments:
args – The script parameters (
trigger.parameters).
- Returns:
A
webhook.WebhookRequest()exposing the request and the response builder.
WebhookRequest
- class webhook.WebhookRequest()
The HTTP request that triggered the script, and the response builder.
- WebhookRequest.body()
The raw request body (POST / PUT).
- Returns:
The body as text.
- WebhookRequest.header(name: string)
The value of a single request header.
- Arguments:
name – The header name.
- Returns:
The header value, or an empty string when the header is absent.
- WebhookRequest.headers()
All request headers as a key/value object.
- Returns:
The headers object.
- WebhookRequest.json()
The request body parsed as JSON.
- Returns:
The parsed body object, or an empty object when the body is absent. Throws an error when the body is present but not valid JSON.
- WebhookRequest.method()
The HTTP method of the request (POST, GET, PUT or DELETE).
- Returns:
The HTTP method.
- WebhookRequest.query()
The query parameters (GET / DELETE) as a key/value object.
- Returns:
The query parameters object.
- WebhookRequest.respond(code: number, content?: string, contentType?: string)
Sets the HTTP response to the webhook caller to the given status code, with no body. This does not stop the script; the last call wins and the response is read once the script ends.
- Arguments:
code – The HTTP status code returned to the caller.
content
contentType