How to validate the required arguments for a trigger
@CrimsonKobalt wrote:
Hi all, when working with the backend API, I've noticed that triggering a workflow requires its name (or is it more correct to say, the name of its trigger?), but the other possible operations require its (mongoDB) id.
However as far as I can see, this id is not visible anywhere in the tool. Is the only solution here fetching all workflows and looking for the id manually (at least once, and save it after)?
I'd like to use the
WorkflowResponse
object to validate the required arguments for a trigger.13 Replies
As for the "Workflow response object", I guess you refer to the JSON object you receive when calling this API endpoint:
https://docs.novu.co/api-reference/workflows/get-workflows
In Novu's terminology, we have:
workflowId
- This is a MongoDB-generated identifier within the Novu system that serves as a unique identifier for workflows. It is used in several API endpoints, including the GET Workflow API, and cannot be modified or altered once generated.
WORKFLOW_TRIGGER_IDENTIFIER
- This is a unique label used to activate or trigger a workflow in Novu.
It is typically represented in a slugified format and can be modified if necessary.
Novu generates this identifier automatically based on the workflow’s name, and it is utilized in Novu API calls to trigger notifications associated with a specific workflow.
As for how you can obtain the workflowId
there are two ways:
1. By calling Get Workflows API
To obtain the workflowId
, you can call the Get Workflows API which will return a list of workflows including their respective _id
fields, which represent their workflowId
. Here's an example of how to use the Get Workflows API:
The response from this endpoint will contain an array of workflows, where each workflow object includes an _id
field that is the workflowId
. You can find this in the JSON response under the "data"
array:
In this JSON response, "64f07ea63f28d769494bd74a"
is an example of a workflowId
.
2. From the workflow's URL
Example:
https://web.novu.co/workflows/edit/64b10dd62d4f4db63503a0a2
In this URL, 64b10dd62d4f4db63503a0a2
is templateId
/ workflowId
How to validate the required arguments for a trigger
Call the Get Workflow API endpoint.Hi @Emil, that confirms what I was trying, thanks a lot! A further question: in the web-interface, it is currently possible to mark arguments on triggers as "required" (i.e. not all arguments are by definition required), however in the API there seems to be no distinction between required and optional arguments. Is that correct?
I've enclosed a dummy workflow in the UI and the GetWorkflow API's corresponding response :
Have you marked arguments as "required" for this workflow?
The API response does not change depending on whether or not I mark the dummy argument as required
@CrimsonKobalt, you just advanced to level 1!
I'm reproducing this and coming back to you
If you use the get workflow api endpoint, in the response you will see that they are required
inside the template part, not in the trigger
Ah I see, and it seems that section is only present in the 'get workflow' (by id) call, and not the 'get workflows' call. OK, thanks!
I mean this part of the response
Ohhh thank you @Gali Baum!!!!
Thanks Gali
@CrimsonKobalt
let me know if you are still facing any issue