Running Workflows via API
Workflows can be triggered from the API by calling runWorkflow
. This method is available on the hatchet.admin
client:
run-workflow.ts
import Hatchet from "@hatchet-dev/typescript-sdk";
const hatchet = Hatchet.init();
const workflowRun = hatchet.admin.runWorkflow(
"api-trigger-workflow",
{
test: "test",
},
{
additionalMetadata: {
hello: "moon",
},
},
);
Usage
Type Parameters
Q
: The type of the input data for the workflow. Default isJsonValue
.P
: The type of the output data from the workflow. Default isJsonValue
.
Parameters
workflowName
(string
): The name of the workflow to be spawned. This will be concatenated with the client's namespace to form the full workflow name.input
(Q
): The input data for the workflow. The type of this data is specified by the generic type parameterQ
.options
(optional): Additional options to pass to the workflow. The current options are supported:additionalMetadata
: A dict of key-value strings to attach to the workflow run. This metadata will be shown in the Hatchet UI and will be available in API endpoints for listing/filtering.
Returns
WorkflowRunRef
: A reference to the workflow run, with the output data type specified by the generic type parameterP
.
Exceptions
HatchetError
: Thrown if there is any error during the workflow spawning process, with the error message provided.