Loop webhooks in Canonic allow you to iterate over a set of data and execute actions for each item, similar to a 'for loop' in programming.
Example: If you have a list of products, you can loop over them to perform actions such as updating their status or validating their availability.
Creating a Loop Webhook
- Within your workflow, decide where the Loop webhook is needed and click the + icon to add it.
- Select the
Loopwebhook type to start configuring your loop.
Configure the Loop webhook by setting the Name and the Property to loop over:
- Name: Enter a descriptive name for the loop webhook.
- Key: Automatically generated based on the Name but can be customized for reference within the project.
- Property to loop over: Define the data path that contains the items you wish to loop over.
Nesting Webhooks within a Loop
- To nest webhooks within a loop, add the desired webhooks by clicking the + icon beneath the Loop webhook.
- These nested webhooks will execute for each iteration of the loop based on the items in your specified data set.
Testing the Loop Webhook
Before finalizing your workflow, use the Test feature to ensure that the Loop webhook is configured correctly and that the response from the Loop is as expected.
Suppose you have a workflow that needs to send personalized emails to a list of users:
- You add a Loop Webhook named "Email Users".
- The Loop webhook is configured to iterate over a list of user data.
Configuring the Loop Webhook
- Name: "Email Users".
- Property to loop over: Set this to the data path that holds your user list, such as
Adding Actions within the Loop
- Inside the loop, add an Email integration webhook that sends an email to each user.
- Configure the Email integration webhook to use the user's email address and other relevant data available in each iteration.
Setting Up the Workflow
- In your workflow, at the point where the user list is ready, add the "Email Users" Loop webhook.
- Under this Loop webhook, add the Email integration webhook, and configure it to use data from the current iteration, such as
params.data.current.emailfor the email address.
- Use descriptive names for your Loop webhook to easily identify their purpose within complex workflows.
- Ensure that the Property to loop over is correctly pointing to a list of items to prevent errors during execution.
Note: All changes must be published to be effective in the live environment.