0

So, My retrieving information on the thermostat is working fine, now I'm trying to update a setting on the ecobee and am receiving:

status.code=3
status.message="Update failed due to a communication error."

my query_string looks like:

{"selection":{"selectionType":"thermostats","selectionMatch":123456789,"thermostat":{"settings":{"humidity":45}}}}

My curl as follows:

-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 also tried: --data-urlencode -Without the '@URI' filter (this is the method shown by the Ecobee API Doc

Both ways return the "Update failed"

I do have working code from a project on GitHub written in python, but I'm using this as a bash/jq/API learning opportunity (also, I don't know python)

His code shows the following for updating a setting successfully:

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': ''}}

This seems to match up to my curl request

This is what I'm using to build my curl (which should be maintaining the proper quoting):

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[@]}")

Anyone see anything obvious?

Thanks

rr0ss0rr
  • 154
  • 1
  • 6

2 Answers2

0

With curl, you need to provide each additional header as one string (one argument). Put quotes around them:

-H 'Content-Type: application/json;charset=UTF-8'
-H 'Authorization: Bearer MY-ACCESS-TOKEN'
pmf
  • 24,478
  • 2
  • 22
  • 31
  • Thanks. I’ll check when I get home but I thought I did that or I did not do it correctly;-) – rr0ss0rr Feb 17 '22 at 19:21
  • I hardcoded instead of using array variables: thermostat=$(curl -s -X POST "https://api.ecobee.com/1/thermostat?format=json" --data "$query_string" -H "Content-Type: application/json;charset=UTF-8" -H "Authorization: Bearer $access_token") ... Same issue – rr0ss0rr Feb 17 '22 at 21:56
  • @rr0ss0rr Then this time it might actually be an issue with ecobee, with which I cannot help you, unfortunately. :( -- (PS: While researching for this issue, I stumbled upon the `--data-urlencode` option in curl's manual, which made me think that instead of `--data "$(jq -r '@uri' <<< "$json")"` you could actually directly be using `--data-urlencode "=$json"`.) – pmf Feb 18 '22 at 05:05
  • @pmr. I appreciate your effort on this. I already tried `—data-urlencode` with the same response. It seems that the next release of curl will include a `—json` option. I also opened a support ticket with ecobee. In the meanwhile Since it works from a python script, it looks like a curl to API issue. I’m going to look for a replacement for curl to see if I have better luck. Thanks again – rr0ss0rr Feb 18 '22 at 15:03
0

Chalk this up to USER ERROR!

@pmr. sorry to waste your time on this. My json query string was off. It was

{"selection":{"selectionType":"thermostats","selectionMatch":123456789,"thermostat":{"settings":{"humidity":45}}}}

and should have been:

{"selection":{"selectionType":"thermostats","selectionMatch":123456789},"thermostat":{"settings":{"humidity":45}}}

'thermostat' should have been at the top level instead of under 'selection'

I don't want to say how much time I spent looking at that until I noticed

rr0ss0rr
  • 154
  • 1
  • 6