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_update
for 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_month
for 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_name
is the name of this rule;table_id
is the ID of the table;view_id
is the ID of the view;condition
is how you'd like the rule to trigger. Usefilters_satisfy
for conditional trigger orrun_periodically
for periodical trigger.
Determine the trigger scenario if run_condition
is per_update
run_condition
is per_update
In 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_columns
astrue
and 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_keys
array, list thekey
s of columns you'd like to watch. Remember to setwatch_all_columns
tofalse
(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 filters
as an object. For details, refer to the SeaTable API Parameter Reference under "filters".filter_conjunction
: UseAnd
orOr
for 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_month
One or more further params are required:
- If the
run_condition
isper_day
, definenotify_hour
here. Use0
to23
for the time of day you'd like the rule to trigger. - If the
run_condition
isper_week
, define these two params:notify_week_day
: Use an integer from1
to7
for Monday to Sunday, andnotify_week_hour
: Use0
to23
for the time of day you'd like the rule to trigger.
- If the
run_condition
isper_month
, define these two params:notify_month_day
: Use an integer from1
to31
for the day of month. Attention: If it's set to31
but 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
: Use0
to23
for 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:
type
should benotify
;users
is a list of user's IDs, it's optional if theusers_column_key
is defined;users_column_key
is a list ofkey
s 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:
type
should beupdate_record
;updates
is an object including the columnkey
and 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:
type
should belock_record
;is_locked
set totrue
and the record that triggered the action will be locked.
Example:
"actions": [
{
"type": "lock_record",
"is_locked": true,
"_id": "872510"
}
]
To add a new record:
type
should beadd_record
;row
is an object including the columnkey
and 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:
type
should besend_email
;account_id
is the ID of the third party account you added in this base. Refer to Third Party Email Accounts for details;send_to
is 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_to
is the CC receiver's email address. For multiple addresses see above.subject
is the subject of your email.default_msg
is 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"
}
]
}