问题
I'm trying to connect to Cloud Waitress API, a solution for restaurants,
Documentation: https://apidocs.cloudwaitress.com/#orderpromos
It's documentation gives an example on how to connect to the API:
curl https://api.cloudwaitress.com/v1/orders \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: YOUR_API_KEY" \
-d `
{
"restaurant_id": "xxxxxxx",
"limit": 10,
"page": 1,
"sort": { "created": -1 },
}
`
I tried to create a Script in GAS to get the information back to a Spreadsheet.
This is my code so far:
function GetOrders(){
var url='https://api.cloudwaitress.com/v1/orders';
var options = {
"method": "POST",
"headers":{
"Content-Type": "application/json",
"Authorization": "SOME-AUTHORIZATION-KEY"
},
"payload": {
"restaurant_id":"SOME-RESTAURANT-ID",
"limit": 10,
"page": 1,
"sort": { "created": -1 }
}
/*
,
"muteHttpExceptions": true
*/
};
var response = UrlFetchApp.fetch(url, options);
var data = JSON.parse(response.getContentText());
var TotalRecord = data["outcome"];
Logger.log("response: " + response);
Logger.log("data: " + data);
Logger.log("TotalRecord: " + TotalRecord);
}
However I'm getting a 500 error
Exception: Request failed for https://api.cloudwaitress.com returned code 500. Truncated server response: {"error":"Internal Error"} (use muteHttpExceptions option to examine full response) (line 23, file "Code")
According to their website a 500 error corresponds to:
I would interpretate the error as if something is wrong of their side, which I doubt.
However, seeing my code I can't figure out what might be missing.
Additional notes:
Output when Mutting exceptions:
Thanks for your time.
来源:https://stackoverflow.com/questions/62135141/gas-error-500-while-connecting-to-an-api