# POST JSON Object via HTTP REQUEST

**URL:** <https://discourse.nodered.org/t/post-json-object-via-http-request/70425>\
**Category:** General\
**Created:** [11 November 2022 02:39 UTC](https://discourse.nodered.org/t/post-json-object-via-http-request/70425 "2022-11-11T02:39:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![interscope101](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@interscope101](https://discourse.nodered.org/u/interscope101)\
**Post date:** [11 November 2022 02:39 UTC](https://discourse.nodered.org/t/post-json-object-via-http-request/70425/1 "2022-11-11T02:39:36Z")

</div>

Hello, I've been running a node-red app that sent a string URL via an HTTP REQUEST (that also included a SHA 256 encoded signature in the headers). Now I needed to send a request that had some nested parameters (array), started getting errors, and apparently the solution is to send it JSON object. I don't know how to proceed with this new approach. Thanks for your help.

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

```auto
[
    {
        "id": "cb5f584da001246b",
        "type": "function",
        "z": "5ef1a9875ae1c916",
        "name": "json",
        "func": "{\"account_id\": 555555,\n \"pair\": \"USDT_BTC\",\n \"position\": {\n \"type\": \"buy\",\n \"units\": {\n \"value\": \"0.01\"\n },\n \"order_type\": \"market\"\n },\n \"take_profit\": {\n \"enabled\": \"true\",\n \"steps\": [\n {\n \"order_type\": \"market\",\n \"price\": {\n \"value\": 10000,\n \"type\": \"bid\"\n },\n \"volume\": 100\n }\n]\n },\n \"stop_loss\": {\n \"enabled\": \"false\"\n }\n}",
        "outputs": 1,
        "noerr": 6,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 510,
        "y": 240,
        "wires": [
            []
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2022 07:45 UTC](https://discourse.nodered.org/t/post-json-object-via-http-request/70425/2 "2022-11-11T07:45:55Z")

</div>

A function node is used for javascript only.

You can use a template node and put the object in there, or define a variable and assign the object and return it.

```auto
const payload = {"account_id": 555555,
    "pair": "USDT_BTC",
    "position": {
        "type": "buy",
        "units": {
            "value": "0.01"
        },
        "order_type": "market"
    },
    "take_profit": {
        "enabled": "true",
        "steps": [
            {
                "order_type": "market",
                "price": {
                    "value": 10000,
                    "type": "bid"
                },
                "volume": 100
            }
        ]
    },
    "stop_loss": {
        "enabled": "false"
    }
}

msg.payload = payload
return msg

```

This will produce a json result, but I suspect this will only be the beginning of your journey, if the API needs all this information, it will probably wants a POST request with various headers.

---

<div class="post-metadata">

**Author:** ![interscope101](https://avatars.discourse-cdn.com/v4/letter/i/a88e4f/32.png) [@interscope101](https://discourse.nodered.org/u/interscope101)\
**Post date:** [11 November 2022 17:21 UTC](https://discourse.nodered.org/t/post-json-object-via-http-request/70425/3 "2022-11-11T17:21:10Z")

</div>

Thanks, I understand I would need to use a template node to setup the JSON structure. Is the difference between sending a string query and json body via http post request is simply the format of the url?

Could someone share an example of sending a json via http request post?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [11 November 2022 20:38 UTC](https://discourse.nodered.org/t/post-json-object-via-http-request/70425/4 "2022-11-11T20:38:39Z")

</div>

Just attach with this payload to a http request node and set it to POST and check the output

---

<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:** [12 November 2022 00:12 UTC](https://discourse.nodered.org/t/post-json-object-via-http-request/70425/5 "2022-11-12T00:12:45Z")

</div>

> [@interscope101](#):
>
> Could someone share an example of sending a json via http request post

Set the payload to an object and the http node will know what to do.

---

<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:** [11 January 2023 00:12 UTC](https://discourse.nodered.org/t/post-json-object-via-http-request/70425/6 "2023-01-11T00:12:52Z")

</div>

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