Juan Carlos Ortiz G.
12/09/2025, 9:23 PMNate
12/09/2025, 9:44 PMNate
12/09/2025, 9:44 PMMarvin
12/09/2025, 9:44 PMNate
12/09/2025, 9:44 PMNate
12/09/2025, 9:45 PMJuan Carlos Ortiz G.
12/09/2025, 9:46 PMNate
12/09/2025, 9:46 PMJuan Carlos Ortiz G.
12/09/2025, 9:47 PMNate
12/09/2025, 9:47 PMJuan Carlos Ortiz G.
12/09/2025, 9:47 PMNate
12/09/2025, 9:47 PMMarvin
12/09/2025, 9:53 PM<https://api.prefect.cloud/hooks/<id>>.
- The webhook uses a Jinja template to turn the incoming HTTP request (method/headers/body) into a Prefect Event.
- Create an Automation with an Event trigger that listens for that event and adds a Run Deployment action to start your deployment. Use Jinja to map fields from the event payload into your flow parameters.
Minimal example:
- Webhook template (UI → Webhooks):
{
"event": "external.webhook.received",
"resource": {
"prefect.resource.id": "external.webhook"
},
"payload": {
"user_id": "{{ body.user_id }}",
"action": "{{ body.action }}"
}
}
- Automation (UI → Automations) with:
- Trigger: Event, expect external.webhook.received
- Action: Run deployment, parameters:
- `user_id`: {{ event.payload.user_id }}
- `action`: {{ event.payload.action }}
- Security options:
- Require a service account API key on the webhook and have the external system send `Authorization: Bearer <key>`; Prefect strips this header from templates for safety.
- If you can’t send auth headers, the webhook URL is opaque; you can rotate it when needed.
Docs:
- Webhooks concepts
- Create a webhook
- Automations concepts
- Creating automations
2) Call Prefect’s REST API directly to create a flow run (Cloud or OSS)
If your external system can include an Authorization header, you can skip webhooks/automations entirely and call the deployment’s “create flow run” endpoint.
- Cloud URL shape:
POST <https://api.prefect.cloud/api/accounts/<ACCOUNT_ID>/workspaces/<WORKSPACE_ID>/deployments/<DEPLOYMENT_ID>/create_flow_run>
Authorization: Bearer <PREFECT_API_KEY>
Content-Type: application/json
- OSS URL shape (default port may be 4200 in local dev or 8080 in some setups):
POST http://<your-server-host>:<port>/api/deployments/<DEPLOYMENT_ID>/create_flow_run
Content-Type: application/json
- Example curl (Cloud):
curl -X POST \
"<https://api.prefect.cloud/api/accounts/<ACCOUNT_ID>/workspaces/<WORKSPACE_ID>/deployments/<DEPLOYMENT_ID>/create_flow_run>" \
-H "Authorization: Bearer pnu_XXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d '{
"name": "triggered-from-webhook",
"parameters": {
"user_id": "user-123",
"action": "process"
},
"tags": ["webhook"]
}'
Docs:
- REST: create_flow_run_from_deployment
- REST API overview (Cloud URL shape)
- Python client alternatives:
- PrefectClient.create_flow_run_from_deployment
- run_deployment helper
Which should you use?
- Use Cloud Webhooks + Automations when the external system cannot add a Bearer token, or you want to route through Prefect events/filters and reuse Jinja templating to map webhook payloads to parameters.
- Use the REST API directly when the external system can authenticate with a header and you just want to start a run immediately.
Notes and gotchas
- Webhooks are a Prefect Cloud feature; OSS should use the REST API directly (or front with your own lightweight receiver).
- Automations can be managed via UI or API; the CLI currently supports listing/inspecting/pausing/resuming/deleting (not creating).Marvin
12/09/2025, 9:53 PMjob_variables in the create_flow_run body to tweak infra at run time if needed.
If you can share whether you’re on Cloud vs OSS and any constraints of the upstream system (auth headers, HMAC signatures, etc.), I can tailor an exact configuration (including an automation payload mapping and a minimal curl for your environment).