Confused a bit - RESTful API -> json / new webserver

Posted on
Tue Feb 28, 2023 1:26 pm
shapa offline
Posts: 483
Joined: Sep 08, 2014
Location: Swindon

Confused a bit - RESTful API -> json / new webserver

For many years I've been using my intercom (2N) to trigger some functionality via Indigo when someone calls at the door - a simple HTTP call via built-in automation.

Now it's not working because of deprecated RESTful API.

I'm trying to re-enable the feature. Authentication works OK, but I'm confused with payload a bit.

What should I put in the "text" field?

The URI is "http://172.16.1.100:8176/v2/api/command?api-key=xxxx" (works ok)
The text is {"message":"indigo.variable.updateValue","objectId":'1208039266',"parameter":{"value":"True"}}', which is not working.

Web Server Debug received an API command message with an invalid JSON payload:
{"message":"indigo.variable.updateValue","objectId":'1208039266',"parameter":{"value":"True"}}'
Web Server Warning HTTP 400 error for request /v2/api/command from 172.16.1.26
Attachments
Screenshot 2023-02-28 at 19.22.39.png
Screenshot 2023-02-28 at 19.22.39.png (320.27 KiB) Viewed 1078 times

Posted on
Tue Feb 28, 2023 1:38 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Confused a bit - RESTful API -> json / new webserver

"parameter" should be "parameters". But there's also an issue with your quotes (the single quote on the end). It should be:

Code: Select all
{
  "message": "indigo.variable.updateValue",
  "objectId": 1208039266,
  "parameters": {
    "value": "True"
  }
}
Instead of:

Code: Select all
{
  "message":"indigo.variable.updateValue",
  "objectId":'1208039266',
  "parameter": {
    "value":"True"
    }
}'
You may also need to surround the whole thing with quotes depending on your software.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Feb 28, 2023 2:08 pm
shapa offline
Posts: 483
Joined: Sep 08, 2014
Location: Swindon

Re: Confused a bit - RESTful API -> json / new webserver

Fascinating, as I've taken the "parameter" from the official docs

https://wiki.indigodomo.com/doku.php?id ... n_examples

Thanks, I will try now.

Posted on
Tue Feb 28, 2023 2:23 pm
shapa offline
Posts: 483
Joined: Sep 08, 2014
Location: Swindon

Re: Confused a bit - RESTful API -> json / new webserver

Neither with nor without quotes

Web Server Debug valid access token/api key...
Web Server HTTP API command call received from 172.16.1.26
Web Server Error received an API command message with an invalid JSON payload
Web Server Debug received an API command message with an invalid JSON payload:
{"message":"indigo.variable.updateValue","objectId":'1208039266',"parameters":{"value":"True"}}
Web Server Warning HTTP 400 error for request /v2/api/command from 172.16.1.26

...


Web Server Error received an API command message with an invalid JSON payload
Web Server Debug received an API command message with an invalid JSON payload:
'{"message":"indigo.variable.updateValue","objectId":'1208039266',"parameters":{"value":"True"}}'
Web Server Warning HTTP 400 error for request /v2/api/command from 172.16.1.26

Posted on
Tue Feb 28, 2023 2:28 pm
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Confused a bit - RESTful API -> json / new webserver

Please try this one specifically:

Code: Select all
{"message": "indigo.variable.updateValue", "objectId": 1208039266, "parameters": {"value": "True"}}

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Feb 28, 2023 2:34 pm
jay (support) offline
Site Admin
User avatar
Posts: 18224
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Confused a bit - RESTful API -> json / new webserver

shapa wrote:
Fascinating, as I've taken the "parameter" from the official docs.


Sorry, that was my typo. Dave's fixing it now.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Mar 01, 2023 6:52 am
shapa offline
Posts: 483
Joined: Sep 08, 2014
Location: Swindon

Re: Confused a bit - RESTful API -> json / new webserver

Works now! Thanks a lot. Quotes are the key...

Posted on
Wed Mar 01, 2023 7:10 am
DaveL17 offline
User avatar
Posts: 6759
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Confused a bit - RESTful API -> json / new webserver

Good deal. Glad you were able to get it working. Single quotes in JSON are problematic. As far as I know, they can never be used for element names or value containers, and must be escaped when contained within a value. For example,

Code: Select all
{"element": "Element\'s value."}
Please report back if you see any other issues with the API specification docs or examples.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests