Home > OS >  curl POST request to Ecobee's API failing with "Update failed due to a communication error
curl POST request to Ecobee's API failing with "Update failed due to a communication error

Time:02-19

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 {"selection":{"selectionType":"thermostats","selectionMatch":311081045454,"thermostat":{"settings":{"humidity":45}}}} -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

CodePudding user response:

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'

CodePudding user response:

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

  • Related