homebridge-http-switch icon indicating copy to clipboard operation
homebridge-http-switch copied to clipboard

Sending JSON body

Open mbierman opened this issue 2 years ago • 1 comments

Is your feature request related to a problem? Please describe. I'm trying to post a JSON payload and it isn't working. This might not be a bug,just a documentation issue (no example provided).

{
            "accessory": "HTTP-SWITCH",
            "name": "NAS temp warning",
            "switchType": "stateless",
            "serialNumber": "SW002",
            "timeout": 1000,
            "onUrl": "https://maker.ifttt.com/trigger/homealert/with/key/d16qe9xyq1***SVS",
            "body": {
                "value1": "NAS is running hot",
                "value2": "temperature is over 95",
                "value3": "https://i.ibb.co/28HTMY7/Unknown.png"
            },
            "method": "POST",
            "debug": false
        },

What am I doing wrong?

I'm also confused by this:

Defines the body sent with the http request. If value is not a string it will be converted to a JSON string automatically.

Is it meant to say?

Defines the body sent with the http request. If value is a string it will be converted to a JSON string automatically.

Describe the solution you'd like

Additional context Add any other context about the feature request here.

mbierman avatar Dec 21 '21 20:12 mbierman

o.k. I figured out the issue. The documentation should be enhanced with better examples IMHO since I am not the only one who has had issues with this. For the sake of others in the future (including myself if I forget) here's a proper example:

   {
            "accessory": "HTTP-SWITCH",
            "name": "NAS temp warning",
            "switchType": "stateless",
            "serialNumber": "SW002",
            "timeout": 1000,
            "debug": true,
            "method": "POST",
            "headers": {
                "Content-Type": "application/json"
            },
            "onUrl": {
                "url": "https://maker.ifttt.com/trigger/homealert/with/key/***",
                "method": "POST",
                "headers": {
                    "Content-Type": "application/json"
                },
                "body": {
                    "value1": "🔥  NAS is running hot 🔥",
                    "value2": "temperature is over 95",
                    "value3": "https://sflanders.net/wp-content/uploads/2015/11/synology-150x150.png"
                }
            }
        },

mbierman avatar Dec 22 '21 00:12 mbierman

I added your example to https://github.com/Supereg/homebridge-http-switch/wiki/Community-supplied-examples

Supereg avatar Feb 16 '23 13:02 Supereg