Hi everyone,
sorry for my english.
I'm trying to query my Home Assistant with API (https://developers.home-assistant.io/docs/api/rest/), pull the value of a sensor and write it to a google sheet. With Postman no problem, so url and token are correct. It doesn't work with google script. I write only the part of code that performs this action
with the Home Assistant API.
function fetchHomeAssistantData()
{
var token = "myapikey";
var options = {
"method": "GET",
"headers": {
"Authorization": "Bearer " + token
},
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch(url, options);
var data = response.getContentText();
var jsonData = JSON.parse(data);
Logger.log(options);
Logger.log(response.getContentText());
var state = jsonData.state;
var lastChanged = jsonData.last_changed;
}
Response: "Error SyntaxError: Unexpected non-whitespace character after JSON at position 3 fetchHomeAssistantData @ HARestApi.gs:15"
can anyone help me? thank you