I have a Google Apps Script function that I would like to run a published Particle Cloud function. But I am getting a 400 error. Here is my Apps Script Function:
function sheetOpened() {
let access_token = "<ACCESS_TOKEN>"
let device_id = "<DEVICE_ID>"
let url = "https://api.particle.io/v1/devices/" + device_id + "/sheet_opened";
let options = {
method: "POST",
headers: {
"Authentication": "Bearer " + access_token
},
}
let response = UrlFetchApp.fetch(url, options);
}
The really weird thing is that this curl request works completely fine:
curl -X POST -H "Authorization: Bearer <ACCESS_TOKEN>" \
https://api.particle.io/v1/devices/<DEVICE_ID>/sheet_opened
And I believe there is not difference between the requests. Does anyone know what is wrong?
function sheetOpened() {
let access_token = "<ACCESS_TOKEN>";
let device_id = "<DEVICE-ID>";
// Url to cloud function (named `sheet_opened`)
let url = "https://api.particle.io/v1/devices/" + device_id + "/sheet_opened";
// Request options
let options = {
// AJAX Verb, it can work with "GET", but it is probably better to use "POST"
method: "POST",
payload: {
// The `arg` field is not mandatory, but if you want to add it you can
// arg: "argument"
access_token: access_token
}
}
// Send request, and get response
let response = UrlFetchApp.fetch(url, options);
// Log response
Logger.log(response);
}