Skip to content

Flow Control and Responses

action(string action_type, array parameters) : array

Runs Custom Actions in WebhookScript. Can be used to loop over items in a way that not possible using the visual Custom Actions editor.

The function returns an array of runtime variables which can be used to fetch the result of an action that sets a variable, like google_sheets_get_values.

The action_types and their parameters can be seen here.

The following action extracts a list of files from an array of objects in a JSON array and uploads each file to Dropbox using the dropbox_upload_file action.


In this example, we assume that the request content sent to the URL contains the following:

  "files": [
      "url": "",
      "name": "example_1.png"
      "url": "",
      "name": "example_2.png"

In the script, the request contents are JSON decoded and looped over. For each item, the file's URL is downloaded and a Dropbox Upload File action is executed.

files = json_path(var('request.content'), '.files.*')

for (file_info in files) {

  // Download file from URL
  file_download = request(file_info['url'])

  // Generate a destination path for the Dropbox file
  destination_path = '/Example Files/%s'.format(file_info['name'])

  // Execute Dropbox Upload File action
      'path': destination_path,
      'body': file_download['content'],
      'mode': 'update',
      'provider_id': providerId


delay(int seconds, string code)

Executes code in the future. Any output will be stored on the request and will show with a "Was delayed" label.

The code will not inherit the execution scope.

In this example, the format function is used to prepare the code string with a URL, causing {} to be replaced with with

code = '
      \'{"message": "Hello World!"}\',

url = ''

delay(5, code.format(url));

The maximum amount of seconds allowed is 604800 (7 days).

exec(string code) : any

Executes code in code and returns the result. The code will inherit the execution scope.

import(string url) : any

Downloads code located at url and returns the result. The code will inherit the execution scope.

As an example, this can be used if you want to re-use code. Just upload it to a server or e.g. Github and use it in different WebhookScript actions.

result = import('')
echo(result) // value

respond(string content, int status, array headers)

Stops Custom Action execution and returns a response.


Stops Custom Action execution.

set_content(string content)

Sets or overwrites the response content of the URL. Script execution continues.

set_header(string header_name, string header_value)

Sets or overwrites a response header of the URL. Script execution continues.

set_response(string content, int status, array headers)

Sets or overwrites response content, status and headers in single function. Script execution continues.

headers should be an array of strings e.g. ["X-Example: Value", "X-Foo: Bar"].

set_status(number status)

Sets or overwrites the HTTP response status of the current URL. Script execution continues.