Add new endpoint to manually trigger workflows#1089
Conversation
| return project.ownerId; | ||
| } | ||
|
|
||
| async function validateTriggerType( |
There was a problem hiding this comment.
If anyone knows an easier way to verify that the trigger is of strategy polling, lmk
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new endpoint /v1/flows/{id}/run to manually trigger workflow executions. The implementation restricts manual triggering to only polling-type workflows and requires the workflow to be published.
Key Changes:
- Add POST endpoint for manual workflow execution with validation
- Implement trigger type validation to ensure only polling workflows can be manually triggered
- Add comprehensive test coverage for the new endpoint including error cases
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/server/api/src/app/flows/flow/flow.controller.ts | Implements the new /run endpoint with validation logic and error handling |
| packages/server/api/test/integration/ce/flows/flow.test.ts | Adds integration tests covering unpublished flows, non-polling triggers, and successful execution scenarios |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| ): Promise<{ success: boolean; message: string }> { | ||
| const blockTrigger = flow.version.trigger; | ||
|
|
||
| if (blockTrigger.type !== TriggerType.BLOCK) { |
There was a problem hiding this comment.
This will never happen. If the workflow is published, you must have a trigger. And there are only block triggers.
There was a problem hiding this comment.
Theres TriggerType.Empty in the enum, which is why im doing it
There was a problem hiding this comment.
It's okay to do this. But if this happens, we have a bug. TriggerType.Empty only exists when you create the workflow and have no trigger selected. And without selecting a trigger, you can't publish.
| if ( | ||
| error instanceof ApplicationError && | ||
| error.error?.code === ErrorCode.ENTITY_NOT_FOUND | ||
| ) { | ||
| return reply.status(StatusCodes.BAD_REQUEST).send({ | ||
| success: false, | ||
| message: | ||
| 'Workflow must be published before it can be triggered manually', | ||
| }); | ||
| } |
There was a problem hiding this comment.
So, we check if the workflow is published. Is it possible to reach this catch for that reason?
There was a problem hiding this comment.
fixed the message
| }); | ||
|
|
||
| return { | ||
| success: metadata.type === TriggerStrategy.POLLING, |
There was a problem hiding this comment.
I think we also need WEBHOOK triggers here
There was a problem hiding this comment.
Why? with the webhook i thought you can just go through the normal webhook logic, once you built it cant you just invoke it?
There was a problem hiding this comment.
True. But won't it affect running workflows by AI agent in future?
There was a problem hiding this comment.
Rita says no need for a new endpoint for webhooks, I guess we will get to it when it comes up then, but i think agents are able to invoke urls also
|



Fixes OPS-2273