无法为 Nest rest 设置温度 API
Unable to set temperature on Nest rest API
我的开发者权限设置为:
- 离开 - read/write v2
- 能量 - 阅读 v2
- 预计到达时间 - 阅读 v1
- 邮政编码 - 读取 v2
- 结构 - read/write v1
- 温控器 read/write 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
但是,我在尝试设置温度时一直收到 "Invalid content sent" 响应。无论我使用 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"}
正如@urman 所发现的那样,我在设置请求的 "thermostats" 中缺少 's'。言语无法表达尴尬:)
请所有 Nest 开发人员阅读 - 是否会返回不同的错误消息?即使是 404 也会指向 url 与 "content".
中更明显的错误
我的开发者权限设置为:
- 离开 - read/write v2
- 能量 - 阅读 v2
- 预计到达时间 - 阅读 v1
- 邮政编码 - 读取 v2
- 结构 - read/write v1
- 温控器 read/write 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
但是,我在尝试设置温度时一直收到 "Invalid content sent" 响应。无论我使用 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"}
正如@urman 所发现的那样,我在设置请求的 "thermostats" 中缺少 's'。言语无法表达尴尬:)
请所有 Nest 开发人员阅读 - 是否会返回不同的错误消息?即使是 404 也会指向 url 与 "content".
中更明显的错误