1. Action Meta
  2. Webhooks

Action Meta

Webhooks

Explains webhook action metadata for triggering actions from external systems. Useful for implicit and explicit webhooks, authentication, GET or POST calls, and data exchange.

There are 2 types of webhooks:

  1. Implicit - using the stubref as part of the URL
  2. Explicit - using a webhook URL with a UUID that was created from a create webhook task

See the webhooks concept for more information on webhooks in Stubber.

Implicit Webhooks

Implicit webhooks are set via setting some action meta data on the action to enable it.

Webhook url format: https://webhooks.stubber.com/im/{{stubref}}/{{action_name}}

  • {{stubref}} is the stub you want to run an action on.
  • {{action_name}} is the name of the action you want to run.

You may use POST or GET methods

If you had a stub with the stubref 2023-09-14-XXXX-V1A5 and you want to execute an action named example_action

The webhook url will be https://webhooks.stubber.com/im/2023-09-14-XXXX-V1A5/example_action

Enabling an implicit webhook

To allow an action to be triggered by a webhook you must configure it in the action_meta

Navigate to Advanced tab and add the following json

loading...

You can now execute it using the following http request

        GET /im/{{stubref}}/example_action HTTPS/1.1
Host: webhooks.stubber.com
Content-Type: application/json

      

Result:

Copying the Webhook URL from the UI

Once an action has webhooks enabled, two copy shortcuts appear in the action's dropdown within the Actions Menu block on any stub:

  • Copy webhook link — copies the full webhook URL for that stub and action to your clipboard, ready to paste into an external system.
  • Copy as cURL — copies a ready-to-run curl command to your clipboard:
        curl --request POST \
  --url https://webhooks.stubber.com/im/{stubref}/{action_name} \
  --header 'Content-Type: application/json' \
  --data '{}'

      

This makes it easy to test or share a webhook directly from the stub without manually constructing the URL.

Putting data into stub.data.payload

By default data will be placed in stub.data.payload

When using the GET method all query params will be placed into stub.data.payload When using the POST method the request body will be placed into stub.data.payload

editor
        {
  "stub":{
    "data":{
      "payload": {
        // data goes here
      }
    }
  }
}

      

Putting data into stub.data

You can configure your data to go to the root of stub.data using the post_data_on_root parameter in the action_meta configuration

loading...
this is stub.data
        {
  "stub":{
    "data":{
      // data goes here
    }
  }
}

      

Calling a webhook using the GET method

        GET /im/{{stubref}}/example_action?some=data HTTPS/1.1
Host: webhooks.stubber.com
Content-Type: application/json
Authorization: Bearer token

      
Result
        {
  "stub":{
    "data":{
      "payload": {
        "some": "data"
      }
    }
  }
}

      

Calling a webhook using the POST method

        POST /im/{{stubref}}/example_action HTTPS/1.1
Host: webhooks.stubber.com
Content-Type: application/json
Authorization: Bearer token

{
  "some": "data",
}

      
Result
loading...

Getting stub.data in response

Using webhooks and external system can pull data from a stub

The default the response will be:

        {
    "success": true,
    "status": 200,
    "payload": {
      "stubdata":{
        // stub.data
      },
    }
  }
}

      

There are 2 ways to enable this functionality:

  1. Via a setting a query parameter (_synchronous=true)
        GET /im/{{stubref}}/example_action?_synchronous=true HTTPS/1.1
Host: webhooks.stubber.com
Content-Type: application/json
Authorization: Bearer token

      
  1. Via setting action_meta.webhooks.synchronous.enable to true
        {
  "action_meta": {
    "webhooks": {
      "enable": true,
      "synchronous": {
        "enable": true
      }
    }
  }
}

      

Result

the default response for a synchronous webhook

        {
    "success": true,
    "status": 200,
    "payload": {
      "stubdata":{
        // stub.data
      },
    }
  }
}

      

Custom webhook response

You can override the default response and configure it to be any structure you need

Follow the below steps to configure a custom response:

  1. set action_meta.webhooks.synchronous.use_custom_return_data to true
  2. configure your response structure in action_meta.webhooks.synchronous.return_data
        {
  "action_meta": {
    "webhooks": {
      "enable": true,
      "synchronous": {
        "enable": true,
        "use_custom_return_data": true,
        "return_data": {
          "example": {
            "json": "~~stub.stubref"
          }
        }
      }
    }
  }
}

      

Webhook response

        {
  "example": {
    "json": "2024-03-01-XXXX-35VK"
  }
}

      

Custom status and headers

return_status and return_headers set the status and headers of a synchronous webhook's answer. Like return_data, they're substituted after the action runs, so the action can decide them. They work with or without use_custom_return_data.

        {
  "action_meta": {
    "webhooks": {
      "enable": true,
      "synchronous": {
        "enable": true,
        "use_custom_return_data": true,
        "return_data": {
          "order_id": "~~stubpost.data.payload.order_id"
        },
        "return_status": "{{#if stubpost.data.payload.order_id}}201{{else}}422{{/if}}",
        "return_headers": {
          "Location": "https://example.com/orders/{{stubpost.data.payload.order_id}}"
        }
      }
    }
  }
}

      

return_status

optional
integer

The status, from 200 to 599, as a number or text that substitutes to one. Defaults to 200. Any other value answers 500 with error.message return_status_invalid.

return_headers

optional
object

Headers to add, by name. A header whose value substitutes to nothing is left out. Content-Length, Transfer-Encoding, Connection and the other connection headers, Set-Cookie, Retry-After and the RateLimit-* headers can't be set; a template that sets one answers 500 with error.message return_headers_invalid.

To answer with something other than JSON, make return_data a string and set Content-Type, e.g. XML for a service that expects it:

        {
  "synchronous": {
    "enable": true,
    "use_custom_return_data": true,
    "return_data": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><Message>Received {{stubpost.data.payload.Body}}</Message></Response>",
    "return_headers": { "Content-Type": "text/xml" }
  }
}

      

These apply when the action ran. When it fails, the answer is one of the errors below.

Synchronous errors

When the action fails, a synchronous webhook answers with an error instead of the stub data:

  • 422 when the action couldn't run on the stub, e.g. it isn't available in the stub's state (action_not_in_state) or its conditions weren't met (action_conditions_failed). error.message says why.
  • 502 with error.message core_action_failed when the action failed for a technical reason, or Stubber couldn't run it.
        {
  "success": false,
  "status": 422,
  "error": {
    "type": "conceptual",
    "message": "action_not_in_state"
  }
}

      

Execution

You can configure how the webhook action is executed using the execution object within the webhooks configuration.

bulk_random_order

optional
boolean

If set to true, the action will run on the bulk nodes. Actions that run on the bulk nodes do not have a guaranteed order of execution, but more of them can be processed at the same time. This is useful when you want to trigger thousands of a specific action via webhook and the order they run in does not matter.

loading...

Validating the payload

An action's input_schema is a JSON Schema (draft 2020-12) of the data it takes, its stubpost.data. An implicit webhook checks every call against it before anything runs, and refuses a call that doesn't fit with status 400, listing each problem. Use it to require fields, check formats and patterns, and refuse fields you don't expect.

input_schema sits on the action itself, next to fields, not in action_meta:

loading...

The schema describes stubpost.data. With post_data_on_root, that's the request body, as above. Without it, the body arrives in stubpost.data.payload, so the schema describes it under payload:

        {
  "input_schema": {
    "type": "object",
    "required": ["payload"],
    "properties": {
      "payload": {
        "type": "object",
        "required": ["order_id"],
        "properties": { "order_id": { "type": "string" } }
      }
    }
  }
}

      

The link id's data that a webhook adds as data.lid isn't checked.

Besides JSON Schema's own keywords (required, type, pattern, minLength, maxLength, minimum, enum, additionalProperties…), the standard formats are checked: email, uri, uuid, date, time, date-time, duration, ipv4, ipv6 and hostname, among others. For anything else, such as a phone number in international format, use a pattern. A keyword or format JSON Schema doesn't define (including a misspelled one) makes the schema invalid, rather than being ignored.

Query strings and form fields are always text, so for GET requests and form posts a value that reads as the schema's type passes and is converted: amount=250 arrives as the number 250. JSON bodies are checked as they are.

A call that doesn't fit is refused with every problem found (up to 20), each with the path of the value, the rule it broke and a message:

        {
  "success": false,
  "status": 400,
  "error": {
    "type": "conceptual",
    "message": "payload_invalid",
    "details": [
      { "path": "/phone", "rule": "pattern", "message": "must match pattern \"^\\+[1-9][0-9]{1,14}$\"" },
      { "path": "/order_id", "rule": "pattern", "message": "must match pattern \"^A-[0-9]{4,10}$\"" },
      { "path": "/admin", "rule": "additionalProperties", "message": "must NOT have additional properties" }
    ]
  }
}

      

A schema that isn't valid JSON Schema answers 500 with error.message input_schema_invalid, so a mistake in it is noticed rather than letting everything through.

NOTE

Values that pass the schema are stored as data and aren't changed. To keep markup or quotes out of a field, describe what it may hold (pattern, enum, format, maxLength), and use {{ }} rather than {{{ }}} when placing values in HTML, which escapes them.

Rate limits

You can limit how often an implicit webhook can be called. Calls over the limit are rejected before authentication and before the action runs. Without rate_limit, a webhook isn't limited.

loading...

per_stub

optional
object

At most limit calls of this action on one stub within any window_seconds.

per_template

optional
object

At most limit calls of this action across all stubs of the template within any window_seconds. Useful for a system that sends to many stubs at once.

Set either or both; when both are set, a call must be within both. limit and window_seconds are whole numbers of at least 1. The window slides: calls in the previous window still count, in proportion to how much of it falls within the last window_seconds.

A rejected call is answered with status 429 and a Retry-After header, the number of seconds after which a call will be accepted again. A rejected call doesn't count towards the limit.

        {
  "success": false,
  "status": 429,
  "error": {
    "type": "conceptual",
    "message": "rate_limited"
  }
}

      

Every answer from a rate-limited webhook carries headers for the limit closest to running out:

  • RateLimit-Limit: the limit.
  • RateLimit-Remaining: calls left.
  • RateLimit-Reset: seconds until the current window ends.

Authentication

Authentication is disabled by default.

You may quickly toggle authentication by setting the action_meta.webhooks.authorization.enable field to true

There are 4 authentication types currently available

  1. basic
  2. bearer
  3. credential
  4. hmac (implicit webhooks only)

Basic Authentication

To enable basic authentication configure your action_meta like the json below:

        {
  "action_meta": {
    "webhooks": {
      "enable": true,
      "authorization": {
        "enable": true,
        "type": "Basic",
        "keys": {
          "username": "user",
          "password": "pass"
        }
      }
    }
  }
}

      

Bearer Token Authentication

To enable Bearer authentication configure your action_meta like the json below:

        {
  "action_meta": {
    "webhooks": {
      "enable": true,
      "authorization": {
        "enable": true,
        "type": "Bearer",
        "keys": {
          "token": "custom_token"
        }
      }
    }
  }
}

      

Credential authentication

To enable Credential authentication create a credential

Current supported credentials for webhook:

  1. Basic user and pass
  2. Bearer token
  3. Custom header

Once you have created your credential configure your action_meta like the json below:

        {
  "action_meta": {
    "webhooks": {
      "enable": true,
      "authorization": {
        "enable": true,
        "type": "credential",
        "keys": {
          "credentialuuid": "< paste your credential uuid >"
        }
      }
    }
  }
}

      

HMAC authentication

With HMAC authentication, callers sign every request with a secret they share with Stubber, together with a timestamp and a nonce. A request can't be altered, sent to another stub or action, or replayed. Use it when the system calling the webhook can compute a signature, e.g. your own backend or an integration you build.

  1. Create a credential of type generic with the shared secret as its value. Give the same secret to the caller.
  2. Configure the action:
        {
  "action_meta": {
    "webhooks": {
      "enable": true,
      "authorization": {
        "enable": true,
        "type": "hmac",
        "hmac": {
          "credentialuuid": "< paste your credential uuid >",
          "tolerance_seconds": 300
        }
      }
    }
  }
}

      

credentialuuid

required
string

The generic credential holding the shared secret.

tolerance_seconds

optional
integer

How far a request's timestamp may be from Stubber's clock, in seconds. Defaults to 300, at most 3600.

The caller signs requests as described in Signing Webhook Requests (HMAC), which has examples in several languages and test values. HMAC can't be used with file uploads (multipart/form-data).

Authentication with interpolation

You can use interpolation to dynamically set the authentication keys

Below is an example for setting the stubref as the username and password

        {
  "action_meta": {
    "webhooks": {
      "enable": true,
      "authorization": {
        "enable": true,
        "type": "Basic",
        "keys": {
          "username": "~~stub.stubref",
          "password": "~~stub.stubref"
        }
      }
    }
  }
}

      

Request with Authorization

Below is an example for making a request with basic authentication

In this example we are using the stubref 2024-06-19-XXXX-ASEQ as the username and password

        GET /im/{{stubref}}/example_action?_synchronous=true HTTPS/1.1
Host: webhooks.stubber.com
Content-Type: application/json
Authorization: Basic MjAyNC0wNi0xOS1YWFhYLUFTRVE6MjAyNC0wNi0xOS1YWFhYLUFTRVE=

      

Default response if Authorization success

        {
  "success": true,
  "status": 200,
  "payload": {
    "stubdata":{
      // stub.data
    },
  }
}

      

Default response if Authorization fail

        {
  "success": false,
  "status": 401,
  "error": {
    "type": "conceptual",
    "message": "invalid_credentials"
  }
}

      

Uploading files with form-data

Only Implicit webhooks support form-data.

Below is an example for uploading files

After a successful request your files will be added to the stub as attachments