• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json get request not working, error in documentation
#1
Bug 
Hi,

I am trying to change the state of a device via the /send page.

First: there seems to be a mistake in the documentation:
https://www.pilight.org/development/api/
The code sample
Code:
send%3F%7B%0A%09%22action%22%3A%20%22control%22%2C%0A%09%22code%22%3A%20%7B%0A%09%09%22device%22%3A%20%22mainlight%22%2C%0A%09%09%22state%22%3A%20%22on%22%2C%0A%09%09%22values%22%3A%20%7B%0A%09%09%09%22dimlevel%22%3A%20%2210%22%0A%09%09%7D%0A%09%7D%0A%7D
does not work (404), this one seems to do the trick:
Code:
send?%7B%0A%09%22action%22%3A%20%22control%22%2C%0A%09%22code%22%3A%20%7B%0A%09%09%22device%22%3A%20%22mainlight%22%2C%0A%09%09%22state%22%3A%20%22on%22%2C%0A%09%09%22values%22%3A%20%7B%0A%09%09%09%22dimlevel%22%3A%20%2210%22%0A%09%09%7D%0A%09%7D%0A%7D
(? not url-encoded)

But my crafted request does not work:
http://192.168.178.22:5001/send?%7B%0A%0...9%7D%0A%7D
Code:
http://192.168.178.22:5001/send?{
    "action": "control",
    "code": {
        "device": "striplight",
        "state": "on"
    }
}

returns: {"message":"success"} but the state of the device does not change.
Everything else works, the device can be toggled from web etc.

Do I need to go through the identification process first?



here is an excerpt of my config:
Code:
"devices": {
                ...
                "striplight": {
                        "protocol": [ "quigg_gt7000" ],
                        "id": [{
                                "id": 666,
                                "unit": 1
                        }],
                        "state": "off"
                },
...
pilight 7.0 stable on raspberry 2 / raspbian
 
Reply
#2
Thumbs Up 
Hi,

I found the problem:
the json needs to be minified (spaces and tabs removed).

This should be mentioned in the documentation
https://www.pilight.org/development/api/
There is also still a small mistake, the ? in the example should not be url-encoded.

Maybe this could be a core-feature? (automatically minifying incoming json)

Greetings
Jan
pilight 7.0 stable on raspberry 2 / raspbian
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  rpi3 Buster Compile Error Nikau 9 1,128 03-26-2020, 08:47 AM
Last Post: tvdgeer
  ERROR: The Broadcom 2835 GPIO 0 is not set to output mode stuckinger 10 1,730 05-07-2019, 09:11 PM
Last Post: curlymo
  v8.1.3 compile error without https fourty2 3 914 11-21-2018, 08:02 PM
Last Post: fourty2
  Assert error in v8.1.3-nightly-d2ee2d0d Ulrich.Arnold 4 949 10-24-2018, 09:28 PM
Last Post: curlymo
  433 mhz receiver working on Raspberry pi with a hack knex 3 2,504 01-21-2018, 06:28 PM
Last Post: curlymo
  pilight on RPi with latest Arch stopped working Ypsilon 12 5,876 12-17-2017, 12:43 PM
Last Post: tinusv
  [solved] Webgui 404-Error PT-Biker 2 1,345 11-11-2017, 09:49 AM
Last Post: PT-Biker
  Error installing pilight AMWN 2 1,943 11-02-2017, 10:09 PM
Last Post: AMWN
  AdHoc network with 2 Raspberry and 2 GPIO transmitter not working webdandy 29 9,221 09-06-2017, 02:39 PM
Last Post: wseifert
  pilight-raw working in nightly? Cipher 8 2,483 08-30-2017, 09:35 PM
Last Post: curlymo

Forum Jump:


Browsing: 1 Guest(s)