I'm developing a code that makes a POST to an API with Google Apps Script.
That API needs in the payload a Array of Arrays.
I use as Array of Arrays directly a GetValues of a range, cause, as I understand the result of this is an Array of Arrays
The API is working if I've tested with curl but when I use the Google Apps Script the API returns me that the payload is not correct.
Here is the code:
function GetUrl()
{
var values = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getDataRange().getDisplayValues();
var api = "https://......";
var headers = {
"xxxxx-auth": "--------------------------",
"content-type" : "application/json",
"cache-control": "no-cache"
};
var payload =
{
"token": "XXXXXXXXXXXXXXXXXXXXXXXXX",
"data" : JSON.stringify(values),
}
Logger.log(payload);
var options =
{
"headers": headers,
"method" : "POST",
"payload" : JSON.stringify(payload)
};
var response = UrlFetchApp.fetch(api, options);
var json = JSON.parse(response.getContentText());
Logger.log(json);
}
If I execute this code I will get this logs:
[20-08-14 03:19:37:134 CEST] {token=XXXXXXXXXXXXX, data=[["header1","header2","header3"],["blu","blu2","blu4"],["bla","bla2","bla3"],["blu","blu3","blu5"],["bla","bla3","bla4"]]}
[20-08-14 03:19:37:647 CEST] {Success=false, Data={Code=-1.0, Message=Error: Supplied parameter 'data' must be an array of arrays (cells).}}
I checked with JSON.stringify and without it. ( no differences in the result)
Do you know what I'm doing wrong in the creation of the payload? As I see all should be ok...