N
Novu11mo ago
empe

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
empe
empeOP11mo ago
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:
curl --request GET \
--url https://api.novu.co/v1/workflows \
--header 'Authorization: <authorization>'
curl --request GET \
--url https://api.novu.co/v1/workflows \
--header 'Authorization: <authorization>'
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:
{
"data": [
{
"_id": "64f07ea63f28d769494bd74a",
"name": "Chat with Novu",
...
},
...
]
}
{
"data": [
{
"_id": "64f07ea63f28d769494bd74a",
"name": "Chat with Novu",
...
},
...
]
}
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.
empe
empeOP11mo ago
No description
CrimsonKobalt
CrimsonKobalt11mo ago
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?
CrimsonKobalt
CrimsonKobalt11mo ago
I've enclosed a dummy workflow in the UI and the GetWorkflow API's corresponding response :
{
"_id": "65ae465d2e7b311203329764",
"name": "test-providers",
...
"triggers": [
{
"type": "event",
"identifier": "test-providers",
"variables": [
{
"name": "uuid",
"type": "String",
"_id": "65ae6ead2e7b31120338a4c4"
}
],
"reservedVariables": [],
"subscriberVariables": [],
"_id": "65ae465d2e7b311203329765"
}
],
...
}
{
"_id": "65ae465d2e7b311203329764",
"name": "test-providers",
...
"triggers": [
{
"type": "event",
"identifier": "test-providers",
"variables": [
{
"name": "uuid",
"type": "String",
"_id": "65ae6ead2e7b31120338a4c4"
}
],
"reservedVariables": [],
"subscriberVariables": [],
"_id": "65ae465d2e7b311203329765"
}
],
...
}
No description
No description
empe
empeOP11mo ago
Have you marked arguments as "required" for this workflow?
CrimsonKobalt
CrimsonKobalt11mo ago
The API response does not change depending on whether or not I mark the dummy argument as required
Novu_Bot
Novu_Bot11mo ago
@CrimsonKobalt, you just advanced to level 1!
empe
empeOP11mo ago
I'm reproducing this and coming back to you
Gali Baum
Gali Baum11mo ago
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
CrimsonKobalt
CrimsonKobalt11mo ago
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!
Gali Baum
Gali Baum11mo ago
I mean this part of the response
No description
empe
empeOP11mo ago
Ohhh thank you @Gali Baum!!!!
Pawan Jain
Pawan Jain10mo ago
Thanks Gali @CrimsonKobalt let me know if you are still facing any issue
Want results from more Discord servers?
Add your server