Introduction
Conditional webhooks in Canonic workflows allow you to create decision branches in your workflow logic, which can determine the direction of data flow based on boolean conditions.
Example: A Conditional webhook named "Products" can direct a workflow to different functionalities based on whether products exist or categories are missing.
Creating a Conditional Webhook
- Navigate to your workflow and locate the point where you want to insert a Conditional webhook.
- Click on the + icon to add a new webhook and select the
Conditional
webhook type. - Label each branch for clarity on the graph and define the boolean conditions that determine the flow.
Configuration
Each branch within a Conditional webhook can be configured with a label and a condition:
- Label: A descriptive name that appears on the workflow graph.
- Condition: A boolean expression that, when evaluated to true, will direct the workflow to proceed down the linked path.
Attaching Webhooks to a Conditional Webhook
- Once your Conditional webhook is in place, add webhooks to each branch by clicking the + icon on the webhook.
- Configure the webhook with the required actions that should occur if the condition is met.
Testing the Conditional Webhook
Before finalizing your workflow, use the Test feature to ensure that the Conditional webhook is configured correctly and that the response is as expected.
Example
Suppose you're managing a product's stock levels and need to branch out actions based on availability:
- Add a Conditional Webhook named "Check Stock".
-
Label two branches:
- "Sufficient Stock" with a condition like
stock > 20
. - "Low Stock" with a condition such as
stock <= 20
.
- "Sufficient Stock" with a condition like
- These conditions use the stock level from a previous node's output, which you select from a dropdown in the UI.
- Attach subsequent webhooks to each branch to handle the workflow based on stock availability. For example, the "Sufficient Stock" branch could confirm an order, while the "Low Stock" branch might trigger a restock process.
Best Practices
- Use clear and descriptive labels for each branch to maintain readability.
- Ensure your boolean conditions are correctly formatted and test them to avoid logical errors in your workflow.
Note: Changes made to Conditional webhooks are saved in real-time but need to be published to take effect.