Rule Structure
Understanding the structure of trigger rules
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 unique id
and a human-readable name
:
Event Type
The event
field specifies which event type this rule applies to:
Common event types include:
user.created
user.updated
user.deleted
payment.succeeded
document.shared
Conditions
The condition
field defines when the rule should be triggered. It can be a simple condition or a complex nested structure:
See the Conditions page for more details on available operators and condition types.
Actions
The actions
field is an array of actions to perform when the rule is triggered:
See the Actions page for more details on available action types.
Priority
The optional priority
field determines the order in which rules are evaluated when multiple rules match the same event:
Enabled Flag
The optional enabled
field determines whether the rule is active:
Tags
The optional tags
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