# Http request POST form data

**URL:** <https://discourse.nodered.org/t/http-request-post-form-data/37727>\
**Category:** General\
**Created:** [18 December 2020 21:01 UTC](https://discourse.nodered.org/t/http-request-post-form-data/37727 "2020-12-18T21:01:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [18 December 2020 21:01 UTC](https://discourse.nodered.org/t/http-request-post-form-data/37727/1 "2020-12-18T21:01:03Z")

</div>

Would anyone have a tip on how I can create an HTTP request with node red flow?

This is Python code that I can trying to figure out how to recreate with node-red. Its an http POST with form data.

```auto
import requests

url = "http://127.0.0.1:5000/read"
read_req = {"address": "12345:2",
        "object_type": "analogValue",
        "object_instance": "302"}

print(requests.post(url, read_req).text)

```

Just trying to use the http request block, still learning node-red 🙂

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

But in node red it doesnt seem like there is an easy button for an http post for form data. Would anyone have any tips? Any tips with a javascript function would be greatly appreciated if I need to go to that extent.

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

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [18 December 2020 21:04 UTC](https://discourse.nodered.org/t/http-request-post-form-data/37727/2 "2020-12-18T21:04:13Z")

</div>

Hi @bbartling

Add a Function node in front of the HTTP Request node with the following:

```auto
msg.payload = {
  "address": "12345:2",
  "object_type": "analogValue",
  "object_instance": "302"
};
return msg;

```

---

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [18 December 2020 21:22 UTC](https://discourse.nodered.org/t/http-request-post-form-data/37727/3 "2020-12-18T21:22:16Z")

</div>

Does this look right?

```auto
msg.headers = {
    "Content-Type": "application/json"
};

msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302"
};
return msg;

```

---

<div class="post-metadata">

**Author:** ![bbartling](https://avatars.discourse-cdn.com/v4/letter/b/bcef8e/32.png) [@bbartling](https://discourse.nodered.org/u/bbartling)\
**Post date:** [18 December 2020 21:30 UTC](https://discourse.nodered.org/t/http-request-post-form-data/37727/4 "2020-12-18T21:30:44Z")

</div>

This is what I have so far thanks for the tips, does it look right?

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

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

For some reason in the console I am getting a  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/5013a2bb3f929ef6060b7df067bce2f987362aa7.png)

In Python requests ill get this if the keys arent named correctly

```auto
"address": 
"object_type"
"object_instance"

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [18 December 2020 21:39 UTC](https://discourse.nodered.org/t/http-request-post-form-data/37727/5 "2020-12-18T21:39:51Z")

</div>

You currently have the HTTP Request node configured to return a parsed JSON object. The error you're getting suggests the response to the HTTP Request isn't parsable JSON. Change the Request node configuration to return a String and see what you get.

---

<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:** [16 February 2021 21:39 UTC](https://discourse.nodered.org/t/http-request-post-form-data/37727/6 "2021-02-16T21:39:59Z")

</div>

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