Hello,
I call the API from a Google App Script project with this kind of body:
function add_booking(body) {
const app_id = 'XXX';
const access_key = 'V2-XXX';
const table_name = 'mytable';
const url = 'https://api.appsheet.com/api/v2/apps/' + app_id + '/tables/' + table_name + '/Action';
const headers = {
'applicationAccessKey':access_key
};
const payload = {
'Action':'Add',
'Properties':{},
'Rows':[
{
'name':'some data'
}
]
};
const options = {
'method': 'post',
'content-type': 'application/json',
'headers': headers,
'payload': JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(url,options);
const status = response.getResponseCode();
Logger.log("RESPONSE_STATUS=" + status);
}
I have a return code of 200 which is "success" according to the AppSheet documentation.
22:25:26 Infos RESPONSE_STATUS=200
However, no records are added to the targetted table.
The Audit Log tool shows two lines:
First line shows success with an error (??):
Properties:
{
"RestAPIVersion": 2,
"TableName": "mytable",
"AppTemplateVersion": "1.000091",
"Errors": "'Action' is missing.",
"AppTemplateName": "XXX",
"Operation": "REST API invoke",
"RecordType": "Stop",
"Result": "Success",
"ResultSuccess": true,
"StatusCode": "OK"
}
The seconde one shows the actual error:
REST API:
{
"Action": "'Action' is missing.",
"Properties": {},
"Rows": []
}
Properties:
{
"RestAPIVersion": 2,
"TableName": "mytable",
"AppTemplateVersion": "1.000091",
"Errors": "'Action' is missing.",
"AppTemplateName": "XXX",
"Operation": "REST API invoke",
"RecordType": "Start",
"Result": "Failure"
}
I have no clue of what happening here. The only thing i found is this item where a bug was found and fixed right away.
What can i do now?
Solved! Go to Solution.
"contentType", not "content-type"
😜
That darn crazy code, always making mountains out of mole hills...
---------
Reading through the thread, I initially had the same thoughts as John, properties not being blank, double quotes instead of single. Guess not. But just to provide some validation to you John, I'm extremely certain that at one point, leaving out the Properties did cause an error, but maybe they improved that since then.
Before figuring it out for you, I was going to suggest completely deleting your entire code, and re-writing it from scratch. That probably would have worked in this case, so keep that in mind for the future. It's a lot harder to make the same tiny mistakes when you can't even see the old mistake anymore.
What I actually ended up doing was copying OP's code to my own appsheet API GAS, filling in my own details and running it against my own app to test. Got the exact same error, so I slowly went through line-by-line comparing to my own working code, and eventually saw the difference noted above.
Good luck!
User | Count |
---|---|
31 | |
13 | |
3 | |
3 | |
2 |