<@ULVA73B9P> what's the correct way in a webhook t...
# ask-marvin
d
@Marvin what's the correct way in a webhook triggered automation to run a deployent to get the body payload of a webhook post to use as a deployment parameter?
m
thought for 252.7 seconds
Great question. In Prefect 3.x, the cleanest way to pass data from a webhook POST into a deployment is: - Put the incoming HTTP body onto the event’s payload in your webhook template - In your Automation’s RunDeployment action, enable Jinja and read from
event.payload
(or from
event.resource
labels if you only need strings) Here’s a minimal end-to-end example. 1) Webhook: map the POST body into the event - In the webhook template (Automations -> Webhooks), you have Jinja access to
body
,
headers
, and
method
- Preserve the full structure by putting the body on the event payload
Copy code
{
  "event": "myapp.webhook.received",
  "resource": {
    "prefect.resource.id": "myapp/webhook/{{ body.id | default('unknown') }}",
    "source": "myapp"
  },
  "payload": {{ body | tojson }}
}
Notes: -
tojson
ensures the payload is valid JSON on the event - If you only need a few fields as strings, you can also add resource labels like
"user": "{{ body.user.name }}"
, but labels are strings only; use
payload
for structured data 2) Automation: Run the deployment with parameters from the event - Create an Automation with an Event Trigger that matches
myapp.webhook.received
- Add a RunDeployment action - In Parameters, switch to JSON and toggle “Use Jinja input” - Option A: Pass specific fields
Copy code
{
  "__prefect_kind": "jinja",
  "user": "{{ event.payload.user.name }}",
  "count": "{{ event.payload.count }}",
  "source": "{{ event.resource.source }}"
}
- Option B: Pass the entire webhook body as one parameter
Copy code
{
  "__prefect_kind": "jinja",
  "payload": {{ event.payload | tojson }}
}
Tip: When passing structured values (dicts/lists), render them with
tojson
and do not wrap them in quotes so the rendered JSON becomes a real object in your flow’s parameters. 3) Flow parameters Make sure your flow’s signature matches what you pass:
Copy code
from prefect import flow, get_run_logger

@flow
def process_webhook(user: str = "", count: int = 0, payload: dict | None = None):
    logger = get_run_logger()
    <http://logger.info|logger.info>(f"user={user}, count={count}, payload_keys={list((payload or {}).keys())}")
That’s it: POST → Webhook → Event (payload contains the body) → Automation trigger → RunDeployment with Jinja-templated parameters. Useful docs: - Webhooks overview: Webhooks concept - Create a webhook: How to create a webhook - Use parameters in Jinja templates: Access parameters in templates - Automations and triggers: Create deployment triggers - Jinja filters (including tojson): Jinja filters reference If you share a sample of the webhook body you’re receiving, I can sketch an exact webhook template and parameter block for your deployment.