Search code examples
javapythoncurlnest-api

Unable to set temperature on Nest rest API


My developers permissions are set to:

  • Away - read/write v2
  • Energy - read v2
  • ETA - read v1
  • Postal code - read v2
  • Structure - read/write v1
  • Thermostat read/write v6

I can get the temperature easily:

$ curl -s -L -X GET "https://developer-api.nest.com/devices/thermostats/ADK.....-/target_temperature_c" -H "Content-Type: application/json"  -H "Authorization: Bearer c.IQvC....."
$ 11.0

However I'm consistently getting an "Invalid content sent" response when trying to set the temperature. This is consistent whether I use Curl, Java, python, etc.. I've tried requests in each of the following formats (And more besides, but the below were various examples found in documentation and here on SO)

# With Auth Token in URL
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-/target_temperature_c?auth=c.IQvCNgfU......" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d     "10"

# Without write target in URL
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d "{\"target_temperature_c\":10}"

# Without write target in URL, not escaping quotes
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d '{"target_temperature_c":10}'

# With write target in URL
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-/target_temperature_c" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d "10"

# Try and set a String field instead
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-/label" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d "A Label"

# Try it without Json as a content type
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-/label" -H "Authorization: Bearer c.IQvCNgfU......" -d "A Label"    

Here's the error response in full:

{"error":"Invalid content sent","type":"https://developer.nest.com/documentation/cloud/error-messages#invalid-content-sent","message":"Invalid content sent","instance":"91c86174-576d-43b7-a586-fcc07a92efa5"}

Solution

  • As @urman kindly spotted, I was missing an 's' in "thermostats" in the set request. Words cannot express the embarrassment:)

    As a request for any Nest developers reading - could a different error message be returned? Even a 404 would point to something more obviously wrong in the url vs the "content".