Not too sure what I've messed up here. I'm trying to send a command to an API to control my aircon system

#1

Hi all,

So If I send the following command via curl in a terminal, it does work fine:

curl \
-H 'Host: que.actronair.com.au' \
-H 'Accept: application/json' \
-H 'Accept-Language: en-AU;q=1' \
-H 'User-Agent: nxgen-ios/1.1.2 (iPhone; iOS 12.1.4; Scale/3.00),SignalR.Client.iOS/2.0.0.0 (iPhone 12.1.4)' \ 
-H 'Authorization: Bearer ABCDE' \ 
-d '{"command":{"UserAirconSettings.isOn”:true,”type":"set-settings"}}' \ 
--compressed 'https://que.actronair.com.au/api/v0/client/ac-systems/cmds/send?serial=12345’

This turns on my aircon and gives the following response:

{"correlationId":"271ae385-18a2-4a3b-9f09-0db55815b2f3","type":"ack","value":{"UserAirconSettings.isOn":true,"type":"set-settings"},"mwcResponseTime":"00:00:00.5460783"}

The below flow (ID's redacted obviously) doesn't work:

[{"id":"7eb9f18e.d50aa","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"ed9d0ae0.1660a8","type":"inject","z":"7eb9f18e.d50aa","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":356.5,"y":302,"wires":[["a718d353.9a125"]]},{"id":"a718d353.9a125","type":"function","z":"7eb9f18e.d50aa","name":"set payload and headers","func":"msg.payload = '{\"command\":{\"UserAirconSettings.isOn”:true,”type\":\"set-settings\"}}';\nmsg.headers = {};\nmsg.headers['Host'] = 'que.actronair.com.au';\nmsg.headers['Accept'] = 'application/json';\nmsg.headers['Accept-Language'] = 'en-AU;q=1';\nmsg.headers['User-Agent'] = 'nxgen-ios/1.1.2 (iPhone; iOS 12.1.4; Scale/3.00),SignalR.Client.iOS/2.0.0.0 (iPhone 12.1.4)';\nmsg.headers['Authorization'] = 'Bearer ABCDE'\nreturn msg; ","outputs":1,"noerr":0,"x":606,"y":290,"wires":[["baafbbe0.99deb8"]]},{"id":"baafbbe0.99deb8","type":"http request","z":"7eb9f18e.d50aa","name":"Token Response","method":"POST","ret":"txt","paytoqs":false,"url":"https://que.actronair.com.au/api/v0/client/ac-systems/cmds/send?serial=12345","tls":"","proxy":"","x":847,"y":290,"wires":[["14969213.2f520e"]]},{"id":"14969213.2f520e","type":"debug","z":"7eb9f18e.d50aa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1088.5,"y":280,"wires":[]}]    

And gives the following error:

"An internal server error prevented this request from being successfully processed. Error Reference: 48b9312c-4d98-4784-a84a-ff3cb7985010"

Previously when I've received a similar error via curl in the terminal, it's because I've used the wrong quotation mark or something similar. Basically it seems to mean that the request is getting through OK but there's something wrong with the formatting maybe?

Just hoping someone can see something obvious I'm doing wrong, as I only started playing with Node-Red yesterday so I'm fumbling through it.

EDIT: I should say that I know I'm using --compressed in the curl statement, but it's not necessary, it works fine without it. It's just a product of testing.

Thanks!!!!

0 Likes

#2

Spot the deliberate mistake (the quote after isOn is not valid)

1 Like

#3

and also before the word type

1 Like

#4

Ugh! Thanks guys, it's so much clearer typed out like that, I must have stared at it 1000 times and not noticed.

Works great now!

1 Like