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:
You can also provide a type parameter to the Workflows type when creating (triggering) a Workflow instance using the create method of the Workers API. Note that this does not propagate type information into the Workflow itself, as TypeScript types are a build-time construct. To provide the type of an incoming WorkflowEvent, refer to the TypeScript and type parameters section of the Workflows documentation.
Was this helpful?
What did you like?
What went wrong?
Thank you for helping improve Cloudflare's documentation!