Configuring HTTP Request for API call

Trying to control a z-wave switch through a call to the API method object_prop_set

Direct input to browser:
http://192.168.1.118/iungo/api_request/object_prop_set?oid=b05dd514?prop=command?value=off
Result:
{"ok":true,"type":"response","time":0.010250617051497,"rv":{"value":"off"},"systime":1740320581,"seq":1,"error":false}

So control of that switch works for switching on and off but whatever I tried I have not been able to configure the HTTP-Request node to achieve that same result.

Configuration within the HTTP Request node nor using a preceding function node for setting method and headers was successful.

Any suggestion welcome...

Is this correct i would think the second and third ? should be &
e.g

http://192.168.1.118/iungo/api_request/object_prop_set?oid=b05dd514&prop=command&value=off

Try that direct in the http url field and set the method to GET and ignore msg.payload.

Thanks for reaction.

The input in the browser was exactly what I described above with all those ? between headers.

One of the many ways I tried:
[
{
"id": "06748d9fc38754f0",
"type": "http request",
"z": "62558479d2a986e8",
"name": "Switch Extra",
"method": "POST",
"ret": "obj",
"paytoqs": "query",
"url": "http://192.168.1.118/iungo/api_request/object_prop_set",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": true,
"authType": "",
"senderr": false,
"headers": [
{
"keyType": "msg",
"keyValue": "oid",
"valueType": "other",
"valueValue": "b05dd514"
},
{
"keyType": "msg",
"keyValue": "prop",
"valueType": "other",
"valueValue": "command"
},
{
"keyType": "msg",
"keyValue": "value",
"valueType": "other",
"valueValue": "on"
}
],
"x": 590,
"y": 140,
"wires": [
[
"27a8d25ff2dcd4a0",
"a69505ee9895d0ec"
]
]
},
{
"id": "9ed11ab460e04bc0",
"type": "debug",
"z": "62558479d2a986e8",
"name": "debug 1",
"active": true,
"tosidebar": false,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 960,
"y": 140,
"wires":
},
{
"id": "076b0c640872f1aa",
"type": "inject",
"z": "62558479d2a986e8",
"name": "On",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "Switch",
"payload": "On",
"payloadType": "str",
"x": 410,
"y": 140,
"wires": [
[
"06748d9fc38754f0"
]
]
},
{
"id": "27a8d25ff2dcd4a0",
"type": "json",
"z": "62558479d2a986e8",
"name": "",
"property": "payload",
"action": "",
"pretty": false,
"x": 770,
"y": 140,
"wires": [
[
"9ed11ab460e04bc0"
]
]
},
{
"id": "a69505ee9895d0ec",
"type": "debug",
"z": "62558479d2a986e8",
"name": "debug 8",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 840,
"y": 60,
"wires":
}
]

Your flow is corrupt due to not posting code in the correct way

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

What is the response you get from the http resquest node?
Did you try what I said?

[edit]
The browser is a GET request but you set the http request to POST.
To append the query string mag.payload needs to be a object.
You do not require the JSON node, unless you want a JSON(string) returned rather than a Javascript object.

example flow

[{"id":"076b0c640872f1aa","type":"inject","z":"d1395164b4eec73e","name":"On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Switch","payload":"{\"oid\":\"b05dd514\",\"prop\":\"command\",\"value\":\"off\"}","payloadType":"json","x":450,"y":5800,"wires":[["06748d9fc38754f0"]]},{"id":"06748d9fc38754f0","type":"http request","z":"d1395164b4eec73e","name":"Switch Extra","method":"GET","ret":"obj","paytoqs":"query","url":"http://192.168.1.118/iungo/api_request/object_prop_set","tls":"","persist":false,"proxy":"","insecureHTTPParser":true,"authType":"","senderr":false,"headers":[],"x":630,"y":5800,"wires":[["a69505ee9895d0ec","9ed11ab460e04bc0"]]},{"id":"a69505ee9895d0ec","type":"debug","z":"d1395164b4eec73e","name":"debug 8","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":5720,"wires":[]},{"id":"9ed11ab460e04bc0","type":"debug","z":"d1395164b4eec73e","name":"debug 1","active":true,"tosidebar":false,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":5800,"wires":[]}]

What you call headers are properties of the query string. headers are a completely different thing.

Dear E1cid,

Thank you for taking the time to educate me.

The Node Red documentation approach is pretty weird in explaining node functions by supplying the underlying script.

It is like explaining a high level language by supplying the underlying code after compilation. It makes the learning curve pretty steep. Way back in the 80’ that was the way Wordperfect allowed users to correct bugs.

That json node insertion was frustration/desperation because the HTTP REQUEST is already supposed to return json indeed.

I really had no clue what method to use so the advice to use GET will be quite useful.

The API description referred to “method” like object_prop_set so I was not sure whether this method was the same as method the HTTP REQUEST node referred to.

Good to know that the arguments have to passed on as an object.

Because “headers” seemed to be the only manner to configure the HTTP REQUEST to have it passing on arguments I assumed that this was the manner this should be done. Got that wrong…too

Using a function node to create that object to be fed into the HTTP REQUEST is than probably the best option, because as far as I understand it now the HTTP REQUEST node itself cannot be configured to create that object.

Perhaps something like this:

The API method is then part of the URL. The object passes on the arguments required.

For your information: This is the direct interface the API for object_prop_set:(while addressing a different switch so oid is different):

As a result the switch is activated.

I will look into this again taking account your advice. Will post any progress.

Thank you,

JPHR

Using the browser looks like this:

As a result the switch is activated.

Again did you try my first example url in the browser?

The arguents should be in msg.payload.command, oid and value. Take a look at the object that comes from my inject node. msg.url is correct.

You seem to have added an extra ? after api_request in msg.url. This was originally a / in previous posts.

Exchanged 2nd and 3rd ? for & and it still works

So when changing 1st ? to & it fails

"?" was a typo should have been "/" indeed.

You gave me some real valuable leads. I will start testing those and report back tomorrow.

Thanks!

The image is strange and url looks weird, can you supply this url in text format, to alleviate aby confusion.

As a string (Not allowed to post a link so left out first part of url IP)
/iungo/api_request/object_prop_set?oid=b05dd514?prop=command?value=off

Result:
{"ok":true,"type":"response","time":0.011344432947226,"rv":{"value":"off"},"systime":1740422619,"seq":1,"error":false}

This does work too (2nd and 3rd ? replaced by &):

/iungo/api_request/object_prop_set?oid=b05dd514&prop=command&value=off

and this fails (1st ? replaced by & too):
/iungo/api_request/object_prop_set&oid=b05dd514&prop=command&value=off

This is the correct format and feeding a object in msg.payload and append payload as query string will create this payload for you,

My example flow with the inject node should work for you.
Just in case you are unsure how to import a flow How to import/export a flow

If you surrond the link with single backticks `link` then the link becomes plain text. As a new user the system flagged your use of multiple links.

Thank you very much for your advice. It works now!
Greatly appreciated....and thanks for your patience.

Some background
The Iungo is an energy manager which gets its data from the utility smart meter port.
It has a z-wave radio for adding z-wave wall plugs and has been pretty reliable over the years. However its processing capability is limited. Though it publicizes all its data through MQTT too, adding logic for directing the wall plugs was not facilitated. Guess that might affect reliability too so the manufacturer wants to avoid that. So I have a Raspbery Pi with MQTT server and Node Red to get data also by MQTT from a Temperature and Humidity sensor and have that drive a ventilation switch (incorporated in my heat pump driven hot water supply) in order to control the humidity in our house.

As a new user I am not allowed to upload the json as an attachment so this code proved to work:

In order to post this I had to replace the IP with XXXX

[{"id":"62558479d2a986e8","type":"tab","label":"test","disabled":false,"info":"","env":},{"id":"cb1dfcde.fd153","type":"function","z":"62558479d2a986e8","name":"set payload and headers","func":"msg.url = XXXX'/iungo/api_request/object_prop_set';\nmsg.payload = {}\nmsg.payload.oid = "b05dd514";\nmsg.payload.prop = "command";\nmsg.payload.value = "on";\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":,"x":390,"y":280,"wires":[["8b7724bbca9c6524","b2d1e9d68abec398"]]},{"id":"8b7724bbca9c6524","type":"http request","z":"62558479d2a986e8","name":"Switch Extra1","method":"GET","ret":"obj","paytoqs":"query","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":true,"authType":"","senderr":false,"headers":,"x":660,"y":280,"wires":[["62d1deafa032670b"]]},{"id":"62d1deafa032670b","type":"debug","z":"62558479d2a986e8","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":280,"wires":},{"id":"db0803a027b9f5b3","type":"inject","z":"62558479d2a986e8","name":"On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Switch","payload":"On","payloadType":"str","x":150,"y":280,"wires":[["cb1dfcde.fd153"]]},{"id":"b2d1e9d68abec398","type":"debug","z":"62558479d2a986e8","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":380,"wires":}]

Result (successful switch activation):

2/24/2025, 8:06:33 PMnode: debug 7Switch : msg.payload : Object

{ oid: "b05dd514", prop: "command", value: "on" }

2/24/2025, 8:06:33 PMnode: debug 5

Switch : msg.payload : Object

object

ok: true

type: "response"

time: 0.02093876095023

rv: object

systime: 1740423994

seq: 1

error: false

After you first flow example I warned you it was corrupt and posted how to post code. You seem to have ignored the advise of how to post code/flows, as this flow example you have just posted is also corrupt. please reread my advice and edit you posts with code/flows in and correct the format. Otherwise no one can import your flows. This forum is for all to get advise and ideas, posting corrupt flows is not helpful for others.

1 Like

I am sorry. Too much focused on my problem. I will look up how to post tomorrow.

[{"id":"62558479d2a986e8","type":"tab","label":"test","disabled":false,"info":"","env":[]},{"id":"8b7724bbca9c6524","type":"http request","z":"62558479d2a986e8","name":"Switch Extra1","method":"GET","ret":"obj","paytoqs":"query","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":true,"authType":"","senderr":false,"headers":[],"x":660,"y":280,"wires":[["62d1deafa032670b"]]},{"id":"62d1deafa032670b","type":"debug","z":"62558479d2a986e8","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":880,"y":280,"wires":[]},{"id":"db0803a027b9f5b3","type":"inject","z":"62558479d2a986e8","name":"On","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":150,"y":240,"wires":[["9d176bb9a54fd0d6"]]},{"id":"b2d1e9d68abec398","type":"debug","z":"62558479d2a986e8","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":380,"wires":[]},{"id":"43557ae1ee6236f7","type":"inject","z":"62558479d2a986e8","name":"Off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":150,"y":320,"wires":[["9d176bb9a54fd0d6"]]},{"id":"9d176bb9a54fd0d6","type":"function","z":"62558479d2a986e8","name":"set payload and headers","func":"var state = msg.payload;\nmsg.url = 'http://192.168.1.118/iungo/api_request/object_prop_set';\nmsg.payload = {}\nmsg.payload.oid = \"b05dd514\";\nmsg.payload.prop = \"command\";\nmsg.payload.value = state;\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":430,"y":280,"wires":[["8b7724bbca9c6524","b2d1e9d68abec398"]]}]
1 Like