You can use a webhook and the API to copy newly added records from one table to another.
This example uses two identical tables called People
and PeopleEcho
. Both tables contains four identical fields named Name
, Age
, DropDown
, and Count
. Admittedly this example is simple and contrived, but it illustrates how you can use the same approach in more complex cases.
Every time a new record is added to the People
table, the webhook is triggered. The webhook uses the API to add an identical record into the PeopleEcho
table.
To copy newly added records:
-
Go to Automation section and create an automation bot with a webhook task and configure the following properties:
-
Target data property choose the People table.
-
Update event property choose ADDS_ONLY.
-
Url property enter:
https://appsheet.com/api/v2/apps/ad178014-1282-4055-bf14-505e31c90c73/tables/PeopleEcho/Action
Where the app ID followingapps/
is the app ID from the Manage > Integrations > IN pane and the value followingtables/
is the name of the target table. In this case,PeopleEcho
. -
HTTP Verb property enter Post.
-
HTTP Headers property enter: applicationAccessKey: "C2iXO-RjfVq-PmcLy-d7nil-YiLvt-BCAYy-C04LY-Ynt0q"
Where the access key value is the Access Key from the Manage > Integrations > IN pane. The Access Key must be enclosed in quotes. For more informations, see Specify application access key when invoking from a webhook.
-
-
Create a JSON Body Template that looks like the one below.
This JSON Body Template copies the value of theName
field of tablePeople
to theName
field of tablePeopleEcho
. Ditto for the other three fields.
This example, is simply copying the entire record fromPeople
toPeopleEcho
but you could do other things. You could copy a subset of the fields. You could initialize the fields of the new record using constants or expressions.
{
"Action": "Add",
"Properties": {
"Locale": "en-US",
"Location": "47.623098, -122.330184",
"Timezone": "Pacific Standard Time",
"UserSettings": {
"Option 1": "value1",
"Option 2": "value2"
}
},
"Rows": [
{
"Name": "<<[Name]>>",
"Age": "<<[Age]>>",
"DropDown": "<<[DropDown]>>",
"Count": "<<[Count]>>"
}
]
}
Create the JSON body template
If you click the Create button following the JSON Body Template property, AppSheet will create an initial JSON Body Template which you can then modify. The template is based on the fields of the table you specify in the Target data property.
The following technique can simplify template creation.
- Temporarily change the Target data property to the table you want to use for the template.
- Click Save to save the temporary change.
- Click Create to create the template.
- Restore the Target data property to its original value.
- Click Save to save all changes.
Troubleshoot your webhook and API
- To troubleshoot your webhook, see Troubleshoot webhooks.
- To troubleshoot your API, see Troubleshoot API calls.