# HTTP Request Node JSON payload

**URL:** <https://discourse.nodered.org/t/http-request-node-json-payload/89089>\
**Category:** General\
**Created:** [29 June 2024 14:30 UTC](https://discourse.nodered.org/t/http-request-node-json-payload/89089 "2024-06-29T14:30:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![NodyRed](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@NodyRed](https://discourse.nodered.org/u/NodyRed)\
**Post date:** [29 June 2024 14:30 UTC](https://discourse.nodered.org/t/http-request-node-json-payload/89089/1 "2024-06-29T14:30:10Z")

</div>

I have been using the http-request node successfully (including authentication of the device). I now want to send another command (payload) but due to how it is formatted do not get it working.

The call to be executed:

```auto
http://<IP>/rpc/Cover.SetConfig?id=0&config={in_mode:%22detached%22}

```

works like this when using a browser. So the call basically is correct.

In node red I'm calling the http-request node with the payload providing the data as params (works this way for other commands):

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/ac900aa521cf2058a133c74df6cdf16c9fe0ced8.png)

I get the following reply:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6e69a214dc6aabc7f1973189aaa0e07878b19f60.png)

The issue here is that the config data is provided in `{}` which gets reformatted when sending this payload to the http-request node.

The config part should stay like `config={in_mode:%22detached%22}` and should not be formatted.

Any idea how to solve this? Any escape characters that I can use? I tried `{{{}}}`, `\{\}`, but nothing did the trick.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 June 2024 14:41 UTC](https://discourse.nodered.org/t/http-request-node-json-payload/89089/2 "2024-06-29T14:41:03Z")

</div>

The simplest method would be to put it together in a function node (or template node)

Function e.g.

```auto
msg.url = 'http://<IP>/rpc/Cover.SetConfig?id=0&config={in_mode:%22detached%22}'
return msg

```

NOTE: for this to work, you need to leave the http url field blank.

Read the built in help for the http node for more info

---

<div class="post-metadata">

**Author:** ![NodyRed](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@NodyRed](https://discourse.nodered.org/u/NodyRed)\
**Post date:** [29 June 2024 14:45 UTC](https://discourse.nodered.org/t/http-request-node-json-payload/89089/3 "2024-06-29T14:45:23Z")

</div>

I think I need to send the parameter as POST body together with the authentication, which is what I'm currently doing. But I suspect that the nested `{}` cause issues here.

I tried as you explained already, but it did not work. I think the authentication part was then not accepted anymore. I somehow need to send it as is in the params.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [29 June 2024 14:55 UTC](https://discourse.nodered.org/t/http-request-node-json-payload/89089/4 "2024-06-29T14:55:20Z")

</div>

Not sure I follow.

If you are doing POST then simple put the JS object directly into msg.payload.

Are there other/additional data (different from this config and id you mention in The URL) that needs to be sent as POST data?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 June 2024 14:59 UTC](https://discourse.nodered.org/t/http-request-node-json-payload/89089/5 "2024-06-29T14:59:13Z")

</div>

> [@NodyRed](#):
>
> `http://<IP>/rpc/Cover.SetConfig?id=0&config={in_mode:%22detached%22}`

`{in_mode:%22detached%22}` in\_mode would require quotes also.

If you post this then config would need to be a valid json or a javascript object  
e.g

```auto
[{"id":"762043d30d717daa","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"url","v":"http://192.168.1.10/rpc/Cover.SetConfig","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"id\":0,\"config\":{\"in_mode\":\"detached\"}}","payloadType":"json","x":170,"y":5000,"wires":[["c2242105fc8a2f0a"]]},{"id":"c2242105fc8a2f0a","type":"http request","z":"d1395164b4eec73e","name":"","method":"POST","ret":"txt","paytoqs":"query","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":330,"y":5000,"wires":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![NodyRed](https://avatars.discourse-cdn.com/v4/letter/n/91b2a8/32.png) [@NodyRed](https://discourse.nodered.org/u/NodyRed)\
**Post date:** [29 June 2024 15:05 UTC](https://discourse.nodered.org/t/http-request-node-json-payload/89089/6 "2024-06-29T15:05:24Z")

</div>

@Steve-Mcl @E1cid

Thanks to both of you. I just tried what @E1cid mentioned and it seems to work.  
Let me clean up my workflow with that and I will confirm.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 July 2024 15:05 UTC](https://discourse.nodered.org/t/http-request-node-json-payload/89089/7 "2024-07-13T15:05:41Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
