I am trying to call Google NEST API for the thermastat, but im getting thw following error:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name "params[heatCelsius]": Cannot bind query parameter. Field 'params[heatCelsius]' could not be found in request message.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name "params[heatCelsius]": Cannot bind query parameter. Field 'params[heatCelsius]' could not be found in request message."
}
]
}
]
}
}
Here is how I am creating the post data:
var temp = req.query.temp;
var coolOrHeat = req.query.coolHeat;
let celsius = (temp - 32) * 5 / 9;
var jsonDataObj;
if (coolOrHeat == "heat") {
jsonDataObj = {
command: 'sdm.devices.commands.ThermostatTemperatureSetpoint.SetHeat',
params: {
heatCelsius: celsius
}
}
}
if (coolOrHeat == "cool") {
jsonDataObj = {
command: 'sdm.devices.commands.ThermostatTemperatureSetpoint.SetCool',
params: {
coolCelsius: celsius
}
}
}
Here is my POST req
var urlSetTemp = 'https://smartdevicemanagement.googleapis.com/v1/enterprises/' + projectId + '/devices/' + thermId + ':executeCommand';
request.post({
headers: {
'content-type': 'application/json',
'Authorization': 'Bearer ' + accessToken
},
form: jsonDataObj,
url: urlSetTemp
}, function (error, response, body) {
var json = JSON.parse(body);
console.log("res: ", json);
res.json({
'json': json,
'ack': "success",
'body': jsonDataObj
});
});
Google’s doc: https://developers.google.com/nest/device-access/traits/device/thermostat-temperature-setpoint#setheat
Finally, in postman, im good, it works, but not in node.
What exactly am I doing wrong?