Moose Stack

Moose APIs

Trigger Workflows

Trigger APIs

Viewing:

Overview

You can create APIs to initiate workflows, data processing jobs, or other automated processes.

Basic Usage

app/apis/trigger_workflow.ts
import { ConsumptionApi } from "@514labs/moose-lib";
 
interface WorkflowParams {
  inputValue: string;
  priority?: string;
}
 
interface WorkflowResponse {
  workflowId: string;
  status: string;
}
 
const triggerApi = new ConsumptionApi<WorkflowParams, WorkflowResponse>(
  "trigger-workflow",
  async ({ inputValue, priority = "normal" }: WorkflowParams, { client }) => {
    // Trigger the workflow with input parameters
    const workflowExecution = await client.workflow.execute("data-processing", { 
        inputValue,
        priority,
        triggeredAt: new Date().toISOString()
      }
    );
 
    return {
      workflowId: workflowExecution.id,
      status: "started"
    };
  }
);
 
export default triggerApi;

Using the Trigger API

Once deployed, you can trigger workflows via HTTP requests:

Terminal
curl "http://localhost:4000/consumption/trigger-workflow?inputValue=process-user-data&priority=high"

Response:

{
  "workflowId": "workflow-12345",
  "status": "started"
}