无法在Nest rest API上设置温度

时间:2017-04-16 10:24:54

标签: java python curl nest-api

我的开发人员权限设置为:

  • 离开 - 读/写v2
  • 能源 - 阅读v2
  • ETA - 阅读v1
  • 邮政编码 - 阅读v2
  • 结构 - 读/写v1
  • 恒温器读/写v6

我可以轻松获得温度:

$ 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

但是,在尝试设置温度时,我一直收到“无效内容已发送”响应。无论我使用Curl,Java,python等,这都是一致的。我已经尝试了以下每种格式的请求(除此之外,还有以下是文档中的各种示例,这里是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"    

以下是完整的错误回复:

{"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"}

1 个答案:

答案 0 :(得分:1)

正如@urman所发现的那样,我在设置请求中错过了“恒温 s ”中的's'。言语无法表达尴尬:))

作为任何Nest开发人员阅读的请求 - 是否可以返回不同的错误消息?即使是404也会指出网址与“内容”相比更明显错误。