{"record":{"id":"aa427fef6d97aeed","repo":"mastra-ai/mastra","slug":"workflow-body-workflowid-not-found","errorCode":null,"errorMessage":"Workflow \"${body.workflowId}\" not found","messagePattern":"Workflow \"(.+?)\" not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"packages/server/src/server/handlers/schedules.ts","lineNumber":148,"sourceCode":"  method: 'POST',\n  path: '/schedules',\n  responseType: 'json' as const,\n  bodySchema: createScheduleBodySchema,\n  responseSchema: scheduleSchema,\n  summary: 'Create a schedule',\n  description:\n    'Creates a new schedule. Pass `agentId` (plus `prompt`) to schedule an agent, or `workflowId` (plus optional `inputData`) to schedule a workflow. Agent schedules get a random `agent_<uuid>` id, workflow schedules a random `schedule_<uuid>` id; pass `id` for a stable slug instead.',\n  tags: ['Schedules'],\n  requiresAuth: true,\n  handler: async ({ mastra, ...body }) => {\n    // getAgentById / getWorkflowById throw a MastraError (status 404) when the\n    // target is unknown; translate that into a clean HTTP 404 instead of\n    // letting it surface as 500.\n    if ('workflowId' in body && body.workflowId) {\n      try {\n        mastra.getWorkflowById(body.workflowId);\n      } catch {\n        throw new HTTPException(404, { message: `Workflow \"${body.workflowId}\" not found` });\n      }\n      return await mastra.schedules.create({\n        workflowId: body.workflowId,\n        cron: body.cron,\n        ...(body.id ? { id: body.id } : {}),\n        ...(body.timezone ? { timezone: body.timezone } : {}),\n        ...(body.inputData !== undefined ? { inputData: body.inputData } : {}),\n        ...(body.initialState !== undefined ? { initialState: body.initialState } : {}),\n        ...(body.requestContext ? { requestContext: body.requestContext } : {}),\n        ...(body.metadata ? { metadata: body.metadata } : {}),\n      });\n    }\n    const agentBody = body as Extract<typeof body, { agentId: string }>;\n    try {\n      mastra.getAgentById(agentBody.agentId);\n    } catch {\n      throw new HTTPException(404, { message: `Agent \"${agentBody.agentId}\" not found` });\n    }","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/schedules.ts#L130-L166","documentation":"When creating a schedule targeting a workflow, the handler validates the workflow exists via mastra.getWorkflowById(body.workflowId); a throw is translated into HTTP 404 'Workflow \"<id>\" not found' instead of a 500.","triggerScenarios":"POST /api/schedules with body.workflowId set to an id that mastra.getWorkflowById cannot resolve (workflow not registered on the Mastra instance).","commonSituations":"Workflow registered with a different id/name than the one sent; workflows module not imported/registered into the Mastra instance; id casing mismatch; referring to a workflow by its export name instead of its registered id.","solutions":["Use the exact registered id the workflow was created with in new Workflow({ id: ... }).","Confirm the workflow module is imported and included in the Mastra constructor's workflows map.","Verify with mastra.getWorkflowById(id) locally before calling the API."],"exampleFix":"// before\nPOST /api/schedules { \"workflowId\": \"dataPipeline\", ... }  // registered as 'data-pipeline'\n// after\nPOST /api/schedules { \"workflowId\": \"data-pipeline\", ... }","handlingStrategy":"validation","validationCode":"const registered = mastra.getWorkflowById(workflowId); // throws if missing\n// or client-side: keep workflowIds from the Mastra config, not export names\nif (!knownWorkflowIds.includes(workflowId)) {\n  throw new Error(`Workflow \"${workflowId}\" is not registered`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await client.createSchedule({ workflowId, cron });\n} catch (e) {\n  if (isHttpError(e, 404) && /not found/.test(e.message)) {\n    throw new Error(`Register workflow '${workflowId}' on the Mastra instance first`);\n  }\n  throw e;\n}","preventionTips":["Use the Workflow constructor's registered id, not the JS export name.","Ensure all workflows are passed into the Mastra instance's workflows map.","Generate the schedule request from the registered ids list at build time."],"tags":["http-404","schedules","workflow","configuration"],"backgroundTag":"resource-not-found","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}