因此,我在调温器上的检索信息运行良好,现在我正在尝试更新ecobee上的设置,并且正在接收:
status.code=3
status.message="Update failed due to a communication error."我的query_string看起来像:
{"selection":{"selectionType":"thermostats","selectionMatch":123456789,"thermostat":{"settings":{"humidity":45}}}}我的卷发如下:
-X POST https://api.ecobee.com/1/thermostat?format=json --data %7B%22selection%22%3A%7B%22selectionType%22%3A%22thermostats%22%2C%22selectionMatch%22%3A311081045454%2C%22thermostat%22%3A%7B%22settings%22%3A%7B%22humidity%22%3A45%7D%7D%7D%7D -H Content-Type: application/json;charset=UTF-8 -H Authorization: Bearer MY-ACCESS-TOKEN--data - Ran the query-string through the jq '@URI' filter也尝试过:--data-urlencode -Without the '@URI' filter (this is the method shown by the Ecobee API Doc
这两种方法都返回“更新失败”
我确实有一个用python编写的关于GitHub的项目的工作代码,但是我使用它作为bash/jq/API学习机会(而且,我不知道python)
他的代码显示了成功更新设置的以下内容:
url:1/thermostat
header:{'Content-Type': 'application/json;charset=UTF-8', 'Authorization': 'Bearer MY-ACCESS-TOKEN'}
parameters:{'format': 'json'}
body:{"thermostat": {"settings": {"humidity": 40}}, "selection": {"selectionType": "thermostats", "selectionMatch": "123456789"}}
{'status': {'code': 0, 'message': ''}}这似乎符合我的卷发要求
这就是我用来建立我的卷发(应该保持正确的引用):
url_request=(-X POST "https://api.ecobee.com/1/thermostat?format=json")
url_body=(--data "$query_string")
url_header=(-H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: Bearer $access_token")
url+=("${url_request[@]}" "${url_body[@]}" "${url_header[@]}")
thermostat=$(curl -s "${url[@]}")有人看到明显的东西了吗?
谢谢
发布于 2022-02-17 17:09:08
对于curl,您需要将每个附加的头作为一个字符串(一个参数)提供。把引号放在他们周围:
-H 'Content-Type: application/json;charset=UTF-8'
-H 'Authorization: Bearer MY-ACCESS-TOKEN'发布于 2022-02-19 00:36:36
将此归因于用户错误!
@pmr.很抱歉把你的时间浪费在这上面。我的json查询字符串已关闭。确实是
{"selection":{"selectionType":"thermostats","selectionMatch":123456789,"thermostat":{"settings":{"humidity":45}}}}而且应该是:
{"selection":{"selectionType":"thermostats","selectionMatch":123456789},"thermostat":{"settings":{"humidity":45}}}“恒温器”应该在顶层,而不是在“选择”之下。
我不想说我花了多少时间看这个直到我注意到
https://stackoverflow.com/questions/71162423
复制相似问题