You can use a webhook and the API to copy data from an updated record to an existing record in another table.
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 an existing record is updated in the People
table, the webhook is triggered. The webhook uses the API to update the corresponding record into the PeopleEcho
table. This ensure that the two records have identical field values.
Do this as follows:
- Enable the API.
-
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 UPDATES_ONLY.
-
Url property enter:
https://www.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.
You must include values in the key fields of the updated table. These key values are used to locate the record to be updated.
{
"Action": "Edit",
"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.