<@ULVA73B9P> when receiving a webhook event that t...
# ask-marvin
d
@Marvin when receiving a webhook event that triggers a deployment, I would like to include the webhook payload as the deployment parameters, how can I do that?
m
thought for 228.7 seconds
Great question—yes, you can pass the webhook payload into your deployment’s parameters using templating in Prefect 3.x Automations. High-level approach: 1) Create a webhook that turns the incoming HTTP request into a Prefect event and stores the request body in the event’s payload. 2) Create an Automation that triggers on that event and uses Jinja templates to map event payload fields to your deployment parameters. Step-by-step A) Create the webhook (Cloud UI → Automations → Webhooks) - Use an event template that passes the entire request body through as the event payload. For JSON payloads, do this:
Copy code
{
  "event": "my.webhook.received",
  "payload": {{ body }}
}
- Notes: - Set your sender to POST application/json so Prefect parses it into
body
. - You can also cherry-pick fields, e.g.
"payload": {"order_id": "{{ body.order_id }}"}
- You can include headers, etc., in other fields if useful:
"resource": {"id": "{{ headers['X-Request-ID'] | default('unknown') }}"}
- Docs: Create a webhook and Webhooks concept B) Create an Automation to run your deployment - Trigger: When event equals
my.webhook.received
(or whatever you set in the webhook template). - Action: Run deployment → pick your deployment → set Parameters using Jinja to reference the event payload. Example mapping Suppose your flow expects:
Copy code
from prefect import flow

@flow
def process_order(order_id: str, customer_email: str | None = None, raw: dict | None = None):
    ...
And your webhook sends JSON like:
Copy code
{
  "order_id": "A-123",
  "customer": {
    "email": "<mailto:alice@example.com|alice@example.com>"
  }
}
Then in the Automation “Run deployment” Parameters field, enter valid JSON with Jinja templates:
Copy code
{
  "order_id": "{{ event.payload.order_id }}",
  "customer_email": "{{ event.payload.customer.email | default('<mailto:unknown@example.com|unknown@example.com>') }}",
  "raw": {{ event.payload }}
}
Important tips - The Parameters field must render to valid JSON. - Wrap string values in quotes:
"id": "{{ event.payload.id }}"
- Do not quote objects/numbers/booleans:
"raw": {{ event.payload }}
- For nested fields use dot notation:
{{ event.payload.customer.email }}
- Use filters like
default(...)
to handle missing keys:
{{ event.payload.foo | default('N/A') }}
- If you only need a subset of fields, you can construct a smaller object:
"raw": {"id": "{{ event.payload.id }}", "ts": "{{ event.occurred }}"}
- You can also reference other event fields, e.g.
{{ event.occurred }}
or
{{ event.resource.id }}
, depending on what you set in the webhook template. Docs you may find helpful - Create a webhook: https://docs-3.prefect.io/v3/how-to-guides/cloud/create-a-webhook - Webhooks concept: https://docs-3.prefect.io/v3/concepts/webhooks - Automations (creating deployment triggers): https://docs-3.prefect.io/v3/how-to-guides/automations/creating-deployment-triggers Would you like to pass the entire payload as a single parameter (e.g.,
raw
) or map individual fields to specific parameters? If you share a sample payload and your flow’s parameter names, I can give you the exact JSON to paste into the Automation.