# Inject Json in "Body" using a http request node dont work

**URL:** <https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674>\
**Category:** General\
**Tags:** http-request\
**Created:** [13 December 2023 13:43 UTC](https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674 "2023-12-13T13:43:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin.gustafsson](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@martin.gustafsson](https://discourse.nodered.org/u/martin.gustafsson)\
**Post date:** [13 December 2023 13:43 UTC](https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674/1 "2023-12-13T13:43:22Z")

</div>

Hi,  
iam trying to collect data from an API  
If you just request the API without filters you get every data, but i need to filter it  
I have set it up in postman and it is working with and without the filtering.

In node red i get it to work to request all data, but i cant get the "filtering" to work  
The request returns all data and not the filtered data

To do the filtering In postman i add Content-Type : application/json in Headers and in Body i have this

```auto
{
    "operator": "and",
    "filters": [
		        {
            "key": "survey",
            "values": ["mI7Utyd5igBVyLfR_E2F2P6dL0bPMfA9juUHyiPUgq7"],
            "comparison": "is"
        }
    ]
}

```

And in Node red i inject the same into msg.body and add Content-Type : application/json as a header in http-request

When looking at the debug i see this result under Body

```auto
body: object
operator: "and"
filters: array[1]
0: object
key: "survey"
values: array[1]
0: "mI7Utyd5igBVyLfR_E2F2P6dL0bPMfA9juUHyiPUgq7"
comparison: "is"
statusCode: 200

```

And the payload should return 5 counts but return 110

```auto
payload: object

next: "https://api.simplesat.io/api/v1/answers/search?page=2"

previous: null

count: 110

answers: array[100]

```

This is probably something simple but iam realy new to this and any help is apreshiated

Here are some info about the API

> **[Simplesat API (v1)](https://documenter.getpostman.com/view/457268/UVRDGRZ2#c79d74a4-b215-4a60-bf93-896b00f4b3c1)**
>
> Welcome to the Simplesat API reference!
> 
> The public endpoints are stable but still a work in progress. If you have any questions or see any issues, please reach out to us at \[support@simplesat.io\](https://mailto:support@simplesat.io).
> 
> \## Previous...

Thanx

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 December 2023 13:48 UTC](https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674/2 "2023-12-13T13:48:35Z")

</div>

> [@martin.gustafsson](#):
>
> And in Node red i inject the same into msg.body and add Content-Type : application/json as a header in http-request

Did you set the correct type? The default for the request node is `GET` but that will probably not pass the JSON correctly, you should be using `PUT` most likely.

---

<div class="post-metadata">

**Author:** ![martin.gustafsson](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@martin.gustafsson](https://discourse.nodered.org/u/martin.gustafsson)\
**Post date:** [13 December 2023 13:56 UTC](https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674/3 "2023-12-13T13:56:56Z")

</div>

Hi  
Thanx for the reply

I´ve set it to POST according to the API documentation, now tried with PUT but got the response "PUT is not allowed"

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 December 2023 14:45 UTC](https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674/4 "2023-12-13T14:45:26Z")

</div>

OK, I don't have access so I can't test it out I'm afraid. Not much else I can do.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [13 December 2023 15:11 UTC](https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674/5 "2023-12-13T15:11:43Z")

</div>

> [@martin.gustafsson](#):
>
> And in Node red i inject the same into msg.body

This is where you might be going wrong.

The **body** for a **POST** request is taking from **msg.payload**.

- set **msg.payload** to the filter as required
- set the **content type** to **application/json** in the request node
- set **method** to **POST**

---

<div class="post-metadata">

**Author:** ![martin.gustafsson](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@martin.gustafsson](https://discourse.nodered.org/u/martin.gustafsson)\
**Post date:** [13 December 2023 15:18 UTC](https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674/6 "2023-12-13T15:18:19Z")

</div>

Yes 🙂 that worked, thanx

---

<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 February 2024 15:19 UTC](https://discourse.nodered.org/t/inject-json-in-body-using-a-http-request-node-dont-work/83674/7 "2024-02-11T15:19:08Z")

</div>

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