Workflows API
The Workflows API provides methods to interact with and execute automated workflows in Mastra.
Getting All Workflows
Retrieve a list of all available workflows:
const workflows = await client.getWorkflows();
Working with a Specific Workflow
Get an instance of a specific workflow:
const workflow = client.getWorkflow("workflow-id");
Workflow Methods
Get Workflow Details
Retrieve detailed information about a workflow:
const details = await workflow.details();
Execute Workflow
Execute a workflow with input parameters:
const result = await workflow.execute({
input: {
param1: "value1",
param2: "value2",
},
});
Resume Workflow
Resume a suspended workflow step:
const result = await workflow.resume({
stepId: "step-id",
runId: "run-id",
contextData: { key: "value" },
});
Watch Workflow
Watch workflow transitions in real-time:
const response = await workflow.watch();
// Read Transition Data from response body
const reader = response.body.getReader();
let buffer = "";
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += new TextDecoder().decode(value);
// Split the buffer into records
const records = buffer.split("\x1E");
buffer = records.pop() || "";
// Process each record
for (const record of records) {
// Handle each record
const { activePaths, context, timestamp } = record;
console.log({
activePaths,
context,
timestamp,
});
}
}