@Marvin, how can I configure a REST Endpoint in Pr...
# ask-marvin
j
@Marvin, how can I configure a REST Endpoint in Prefect to use with a webhook from another system?
n
it looks like your tag got messed up somehow
@Marvin how can I configure a REST Endpoint in Prefect to use with a webhook from another system?
m
âś… thought for 540.3 seconds
n
but to answer the question, you set up a webhook template that transforms the payload into a prefect event that can then be used to trigger automations (like run_deployment) in prefect
marvin should be able to link the docs here shortly
j
thank you @Nate. Is that possible with Prefect OSS?
n
webhooks are not available at this time in OSS unfortunately
j
There are any workarounds?
n
however you can always have a sidecar service that receives webhooks and calls emit_event
👍 1
âś… 1
j
thank you!
n
catjam
m
Great question! There are two good ways to expose a “REST endpoint” for external webhooks to trigger Prefect runs: 1) Prefect Cloud Webhooks + Automations (no custom server needed) - Create a webhook in Prefect Cloud. It gives you an HTTPS URL like
<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):
Copy code
{
  "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:
Copy code
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):
Copy code
POST http://<your-server-host>:<port>/api/deployments/<DEPLOYMENT_ID>/create_flow_run
Content-Type: application/json
- Example curl (Cloud):
Copy code
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).
- For ECS/container-based deployments, you can pass
job_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).