You can set the automation rule to trigger by condition, or periodically. The following instruction shows you how to send the request body. Consult the example request for demonstration.
After successful creation, an id is returned, this is the ID of the automation rule you just created, and is to be distinguished from the action's _id like explained below in the actions section.
First, define the running condition
For the run_condition parameter, use
per_updatefor conditional trigger, if the rule should be triggered when a certain condition is met when the table has been updated;per_day,per_week, orper_monthfor periodical trigger, if the rule should be triggered periodically.
Then, define the trigger condition
In the trigger object, all the following params are required:
rule_nameis the name of this rule;table_idis the ID of the table;view_idis the ID of the view;conditionis how you'd like the rule to trigger. Usefilters_satisfyfor conditional trigger orrun_periodicallyfor periodical trigger.
Determine the trigger scenario if run_condition is per_update
run_condition is per_updateIn the automation rule's trigger conditions, you can watch some or all of the columns for changes, and eventually set filter conditions to narrow down the watching. So that means there are three typical scenarios:
-
This is the simplest scenario: whenever a record has been changed, this rule will trigger. To do this, just defineWatch all the columns without filterswatch_all_columnsastrueand you are good to go:
"trigger": {
"rule_name": "Watch all",
"table_id": "0000",
"view_id": "0000",
"condition": "filters_satisfy",
"watch_all_columns": true
}
-
In theWatch one or more columns without filterscolumn_keysarray, list thekeys of columns you'd like to watch. Remember to setwatch_all_columnstofalse(if you leave it astrue, all the columns will be watched):
"trigger": {
"rule_name": "Watch Name and Select",
"table_id": "0000",
"view_id": "0000",
"condition": "filters_satisfy",
"column_keys": ["0000", "72IC"]
}
-
You'll need two further params, if you'd like to filter the watched columns:To apply filters to the above scenarios filtersas an object. For details, refer to the SeaTable API Parameter Reference under "filters".filter_conjunction: UseAndorOrfor the filter conjunction logic.
Here's an example:
"trigger": {
"rule_name": "test-auto",
"table_id": "0000",
"view_id": "0000",
"condition": "filters_satisfy",
"filters": [{
"column_key": "0000",
"filter_predicate": "contains",
"filter_term": "yes"
}, {
"column_key": "_creator",
"filter_predicate": "contains",
"filter_term": ["[email protected]"]
}],
"filter_conjunction": "And"
}
Determine the trigger scenario if run_condition is per_day, per_week, or per_month
run_condition is per_day, per_week, or per_monthOne or more further params are required:
- If the
run_conditionisper_day, definenotify_hourhere. Use0to23for the time of day you'd like the rule to trigger. - If the
run_conditionisper_week, define these two params:notify_week_day: Use an integer from1to7for Monday to Sunday, andnotify_week_hour: Use0to23for the time of day you'd like the rule to trigger.
- If the
run_conditionisper_month, define these two params:notify_month_day: Use an integer from1to31for the day of month. Attention: If it's set to31but a month doesn't have a 31st day, this rule won't be triggered. It'll only be triggered when the current day is a 31st.notify_month_hour: Use0to23for the time of day you'd like the rule to trigger.
See the example request for demonstration.
Last but not least: The action
Different than the trigger object, the actions is a list of objects. This enables you to trigger multiple actions all at once.
In each action object, the _id is the first parameter. It's an ID of the action. If you have multiple actions in one rule, they should carry different IDs. You can decide which ID an action should carry.
To notify one or more users:
typeshould benotify;usersis a list of user's IDs, it's optional if theusers_column_keyis defined;users_column_keyis a list ofkeys of columns that are the types of collaborator, creator or modifier;default_msg: is the content of the message. You can use {column name} in the message to quote the content of a certain cell.
Example:
"actions": [
{
"type": "notify",
"users": [],
"default_msg": "look at {Name}.",
"_id": "740077",
"users_column_key": "iXRK"
}
]
To modify the record:
typeshould beupdate_record;updatesis an object including the columnkeyand desired content of each field that you would like to modify.
Example:
"actions": [
{
"type": "update_record",
"updates": {
"0000": "abc",
"6NKm": 123
},
"_id": "54696"
}
]
To lock the record:
typeshould belock_record;is_lockedset totrueand the record that triggered the action will be locked.
Example:
"actions": [
{
"type": "lock_record",
"is_locked": true,
"_id": "872510"
}
]
To add a new record:
typeshould beadd_record;rowis an object including the columnkeyand desired content of each field that you would like to add in the new record.
Example:
"actions": [
{
"type": "add_record",
"row": {
"0000": "abc"
},
"_id": "410993"
}
]
To send an email:
typeshould besend_email;account_idis the ID of the third party account you added in this base. Refer to Third Party Email Accounts for details;send_tois the receiver's email address. If you would like to send to multiple receivers, separate their email addresses with comma (,) inside of the quotation mark.copy_tois the CC receiver's email address. For multiple addresses see above.subjectis the subject of your email.default_msgis the content of the message.
Example:
"actions": [
{
"type": "send_email",
"default_msg": "Content example.",
"account_id": 17,
"subject": "Subject sample",
"send_to": "[email protected], [email protected]",
"copy_to": "[email protected], [email protected]",
"_id": "838356"
}
]
}
