I am now adding records to a table through the AppSheet API and the code is computing using the Google Apps Script (GAS). I can get the rows in HTTP contents when I was reading records. With the similar code with some minor modification, I can also add row into the Table. However Igot an error "{Message=An error has occurred.}" from the HTTP contents when I was adding rows, while it is normal when reading data. I wonder if there is some API error as the code works normally in a few days ago.
The following are the example functions for reading and adding records from a table.
function testFindAPI(){
var tableName = "T_Vouchers";
var date = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd'T\'HH:mm:ss")
var url = `https://api.appsheet.com/api/v2/apps/${appId}/tables/${encodeURIComponent(`${tableName}`)}/Action`;
var body = {
"Action": "Find",
"Properties": {
},
"Rows": [
]
}
var params = {
"method": "POST",
'contentType': 'application/json',
"headers": {
"ApplicationAccessKey": applicationAccessKey
},
"payload": JSON.stringify(body),
'muteHttpExceptions': true
}
var response = UrlFetchApp.fetch(url, params);
var responseRowData = JSON.parse(response.getContentText());
console.log(response);
console.log(responseRowData);
}
function testAddAPI() {
var tableName = "T_Vouchers";
var voucherDate = Utilities.formatDate(new Date(), "GMT+8", "yyyy-MM-dd'T\'HH:mm:ss");
var url = `https://api.appsheet.com/api/v2/apps/${appId}/tables/${encodeURIComponent(`${tableName}`)}/Action`;
var body = {
"Action": "Add",
"Properties": {},
"Rows": [
{
"Type": "Normal voucher",
"Date": voucherDate,
"Price": "10000",
"Remarks": "test",
}
]
}
var params = {
"method": "POST",
'contentType': 'application/json',
"headers": {
"ApplicationAccessKey": applicationAccessKey
},
"payload": JSON.stringify(body),
'muteHttpExceptions': true
}
var response = UrlFetchApp.fetch(url, params);
var responseRowData = JSON.parse(response.getContentText());
console.log(response);
console.log(responseRowData);
}
Sorry, I got the error fixed.
It is not the problem of either API or GAS. It was because I got a virtual column that compute the values by using the "date". Thus everything works fine when I removed that virtual column
User | Count |
---|---|
36 | |
32 | |
30 | |
18 | |
16 |