Here’s a script template to invoke an AppSheet action via API from an Apps Script. It could surely be streamlined or optimized in various ways. I find this scaffolded structure of building variables upon variables to be helpful in development, troubleshooting, and script reuse (of course, it could be turned into a function with some/all of the variables as function parameters). It includes logging of both the request and the response, which also helps in troubleshooting.
// Values specific to app
const appAccessKey = 'my-appAccessKey';
const appId = 'my-appId';
// Values specific to individual AppSheet API call
const table = 'my-Table';
const action = 'my-Action';
const userSettings = {'my-ColumnName': my-ColumnValue, 'my-Column2Name': my-Column2Value};
const properties = {
'Locale': 'my-LocaleCode',
'RunAsUserEmail': my-UserEmail,
'UserSettings': userSettings
};
const rows = my-Array;
const body = {
'Action': action,
'Properties': properties,
'Rows': rows
};
const payload = JSON.stringify(body);
// Values universal to AppSheet API calls
const url = 'https://api.appsheet.com/api/v2/apps/' + appId + '/tables/' + table + '/Action';
const method = 'post';
const headers = {'ApplicationAccessKey': appAccessKey};
const params = {
'method': method,
'contentType': 'application/json',
'headers': headers,
'payload': payload,
'muteHttpExceptions': true
};
const requestSimulate = UrlFetchApp.getRequest(url, params);
let response
try{
response = UrlFetchApp.fetch(url, params);
}
catch(err){
Logger.log('err: ' + err);
}
finally{
Logger.log ('requestSimulate:');
Logger.log (requestSimulate);
Logger.log ('response: ' + response);
}