Rule Structure
Trigger rules follow a specific JSON structure that defines when and how they should be applied. This page explains the structure of rules and how to create them.Basic Rule Structure
A rule consists of the following components:Example Rule
Here’s an example of a complete rule:Rule Components
ID and Name
Each rule must have a uniqueid
and a human-readable name
:
Event Type
Theevent
field specifies which event type this rule applies to:
user.created
user.updated
user.deleted
payment.succeeded
document.shared
Conditions
Thecondition
field defines when the rule should be triggered. It can be a simple condition or a complex nested structure:
Actions
Theactions
field is an array of actions to perform when the rule is triggered:
Priority
The optionalpriority
field determines the order in which rules are evaluated when multiple rules match the same event:
Enabled Flag
The optionalenabled
field determines whether the rule is active:
Tags
The optionaltags
field allows you to categorize rules:
Rule Organization
Rules can be organized in different ways:Single JSON File
Store all rules in a single JSON file:Multiple Files by Category
Organize rules into separate files by category:Database Storage
For more dynamic applications, rules can be stored in a database and loaded at runtime.Best Practices
- Use descriptive IDs and names - Make it easy to understand what each rule does
- Keep conditions focused - Don’t create overly complex conditions
- Use tags for organization - Tags make it easier to filter and manage rules
- Set appropriate priorities - Use priorities to ensure rules are evaluated in the correct order
- Document your rules - Add descriptions to explain the purpose of each rule
See Also
- Learn about Conditions in trigger rules
- Explore available Actions for trigger rules
- Understand how to Manage Rules effectively