When a Workflow is triggered, it can receive an optional event. This event can include data that your Workflow can act on, including request details, user data fetched from your database (such as D1 or KV) or from a webhook, or messages from a Queue consumer.
Events are a powerful part of a Workflow, as you often want a Workflow to act on data. Because a given Workflow instance executes durably, events are a useful way to provide a Workflow with data that should be immutable (not changing) and/or represents data the Workflow needs to operate on at that point in time.
Pass parameters to a Workflow
You can pass parameters to a Workflow in two ways:
As an optional argument to the create method on a Workflow binding when triggering a Workflow from a Worker.
Via the --params flag when using the wrangler CLI to trigger a Workflow.
You can pass any JSON-serializable object as a parameter.
To pass parameters via the wrangler command-line interface, pass a JSON string as the second parameter to the workflows trigger sub-command:
TypeScript and type parameters
By default, the WorkflowEvent passed to the run method of your Workflow definition has a type that conforms to the following, with payload (your data) and timestamp properties:
You can optionally type these events by defining your own type and passing it as a type parameter ↗ to the WorkflowEvent:
When you pass your YourEventType to WorkflowEvent as a type parameter, the event.payload property now has the type YourEventType throughout your workflow definition:
Note that type parameters do not validate that the incoming event matches your type definition. Properties (fields) that do not exist or conform to the type you provided will be dropped. If you need to validate incoming events, we recommend a library such as zod ↗ or your own validator logic.
Was this helpful?
What did you like?
What went wrong?
Thank you for helping improve Cloudflare's documentation!