google script POST to Ninox not working
Hi,
I want to send data from Google Sheets to Ninox with API. In Google Script editor I added the following code (so its not a Ninox code):
function updateNinox() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
var data = sheet.getDataRange().getValues();
var url = "https://api.ninox.com/v1/teams/cGocJJ6kWcBoKNfeG/databases/f8jy4c29hnim/tables/OB/records";
var apiKey = "12345678-1234-1234-1234-123456789012"; //Here I use the valid API key
var records = data.map(function(row) {
return {
Data1: row[0], // First field of the Record
Data2: row[1], // Second field of the Record
Date: row[2], // Dátum field
Time_interval: row[3], // Time interval field
};
});
var options = {
"method" : "post",
"headers" : {
"Authorization" : "Bearer " + apiKey
},
"contentType" : "application/json",
"payload" : JSON.stringify({ "records": records }) // Az 'records' megfelelő formátumban
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText()); // Segít a válasz hibakeresésében
}
If I run this code I receive the following error: Exception: Request failed for https://api.ninox.com returned code 500. Truncated server response: {"message":"Internal Server Error"} (use muteHttpExceptions option to examine full response)
So this is a CODE 500 INTERNAL ERROR response.
If I use the link in the script in Postman with GET method the result is the names and ID-s of the table's records. But with POST it doesn't work.
What could be wrong? What syntax should I use to POST data into Ninox?
1 reply
-
Additional info: in Postman when I POST this url: https://api.ninox.com/v1/teams/cGocJJ6kWcBoKNfeG/databases/f8jy4c29hnim/tables/OB/records?Number=1 a new record is created in the Table (where Number field exists).
Content aside
- 1 mth agoLast active
- 1Replies
- 20Views
-
1
Following