# Send payload to my web application using http request

**URL:** <https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427>\
**Category:** General\
**Tags:** http-request\
**Created:** [22 April 2024 23:47 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427 "2024-04-22T23:47:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sobercactus](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sobercactus](https://discourse.nodered.org/u/sobercactus)\
**Post date:** [22 April 2024 23:47 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/1 "2024-04-22T23:47:39Z")

</div>

Hi everyone, I have retrieved msg.payload from my IOT sensors, and I wonder how I can send msg.payload to my flask web application using http request or other method.

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

Thank you.

---

<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:** [23 April 2024 00:22 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/2 "2024-04-23T00:22:37Z")

</div>

Welcome to the forum. However, you've not really given us anything to go on. We have no context about your web application so can't really help.

---

<div class="post-metadata">

**Author:** ![sobercactus](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sobercactus](https://discourse.nodered.org/u/sobercactus)\
**Post date:** [23 April 2024 00:27 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/3 "2024-04-23T00:27:26Z")

</div>

Sorry about that, I have upload a screenshot of my flask application.

---

<div class="post-metadata">

**Author:** ![kitori](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kitori](https://discourse.nodered.org/u/kitori)\
**Post date:** [23 April 2024 05:13 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/4 "2024-04-23T05:13:00Z")

</div>

You can send the request node POSTing data to your server:

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/116f0f3ba282129444379a96111830b11b250e32.png)

Example flow:

![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/81315118a68bde9b540d2035d7fe4983bb0b01ac.png)

```auto
[{"id":"12fde2238ad56ee2","type":"http request","z":"94c514c2ac360b08","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://127.0.0.1:1880/receive_power","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":370,"y":180,"wires":[["a09478c1b756579b"]]},{"id":"e442c220d9d3430d","type":"http in","z":"94c514c2ac360b08","name":"","url":"/receive_power","method":"post","upload":false,"swaggerDoc":"","x":220,"y":320,"wires":[["f53b16c3af14be08","0d1f3e05f092db78"]]},{"id":"98db9a79c6719e6a","type":"inject","z":"94c514c2ac360b08","name":"sensor data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"maschine_id\":\"1\",\"machine_power\":\"200\"}","payloadType":"json","x":190,"y":180,"wires":[["12fde2238ad56ee2"]]},{"id":"a09478c1b756579b","type":"debug","z":"94c514c2ac360b08","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":540,"y":180,"wires":[]},{"id":"f53b16c3af14be08","type":"http response","z":"94c514c2ac360b08","name":"","statusCode":"","headers":{},"x":490,"y":320,"wires":[]},{"id":"0d1f3e05f092db78","type":"debug","z":"94c514c2ac360b08","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":480,"y":360,"wires":[]},{"id":"f576842b9cde1189","type":"comment","z":"94c514c2ac360b08","name":"send post request","info":"","x":190,"y":140,"wires":[]},{"id":"575b9c1094810d37","type":"comment","z":"94c514c2ac360b08","name":"dummy server","info":"","x":190,"y":280,"wires":[]}]

```

you can read more about the request node here: [https://cookbook.nodered.org/#http-requests](https://cookbook.nodered.org/#http-requests)

---

<div class="post-metadata">

**Author:** ![sobercactus](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sobercactus](https://discourse.nodered.org/u/sobercactus)\
**Post date:** [23 April 2024 05:47 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/5 "2024-04-23T05:47:45Z")

</div>

This is my setup.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fbb0a25193643d1e4f76c0244a3a4f1540489ab6.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/6992ca4bb7e018029a98c989be5e2a0a5811dd86.png)

I think in this case what I doing this POSTing the data from my web server to node red, which I should be doing the other way around.

---

<div class="post-metadata">

**Author:** ![kitori](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kitori](https://discourse.nodered.org/u/kitori)\
**Post date:** [23 April 2024 09:22 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/6 "2024-04-23T09:22:50Z")

</div>

Whats is the payload? The server send something back, but the http request node can't convert it to json.

You can set the request that it return a string:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/a/aac96e60e7a78cd51a21b6ab00f9d78c4337e41a.png)

can you see that the data ist ingested into your backend?

And your backend use the Object `requests.form.machine_id` for extracteing the data, so try sending this payload to the backend:

```auto
{
    "payload": {
        "form": {
            "maschine_id": "1",
            "machine_power": "200"
        }
    }
}

```

you can use the change node:

```auto
[{"id":"98db9a79c6719e6a","type":"inject","z":"94c514c2ac360b08","name":"sensor data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"maschine_id\":\"1\",\"machine_power\":\"200\"}","payloadType":"json","x":190,"y":180,"wires":[["751195e907674896"]]},{"id":"751195e907674896","type":"change","z":"94c514c2ac360b08","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.form","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":180,"wires":[["12fde2238ad56ee2","c6d2425f68837d2b"]]}]

```

---

<div class="post-metadata">

**Author:** ![sobercactus](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sobercactus](https://discourse.nodered.org/u/sobercactus)\
**Post date:** [23 April 2024 23:19 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/7 "2024-04-23T23:19:32Z")

</div>

Thank you for your reply.

**1. My msg.object is this:**

{"topic":"servicelocation/1df4d811-cd15-44db-b358-1caa61cf055d/realtime","payload":{"totalPower":0,"totalReactivePower":9,"totalExportEnergy":2271,"totalImportEnergy":8426,"monitorStatus":0,"utcTimeStamp":1713851721210,"channelPowers":[{"ctInput":0,"power":0,"exportEnergy":2271,"importEnergy":8426,"phaseId":0,"current":0}],"voltages":[{"voltage":235,"phaseId":0}]},"qos":0,"retain":false,"\_msgid":"e5ca5b187342aa1b"}

**2. In my backend, I get error message like this:**

192.168.137.116 - - [23/Apr/2024 18:22:40] "POST /receive\_power HTTP/1.1" 500 -  
Traceback (most recent call last):  
File "C:\Users\shawn\OneDrive\Desktop\Unimelb-2024-SEM-1\old\_code.venv\Lib\site-packages\flask\app.py", line 1488, in **call**  
return self.wsgi\_app(environ, start\_response)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File "C:\Users\shawn\OneDrive\Desktop\Unimelb-2024-SEM-1\old\_code.venv\Lib\site-packages\flask\app.py", line 1466, in wsgi\_app  
response = self.handle\_exception(e)  
^^^^^^^^^^^^^^^^^^^^^^^^  
File "C:\Users\shawn\OneDrive\Desktop\Unimelb-2024-SEM-1\old\_code.venv\Lib\site-packages\flask\app.py", line 1463, in wsgi\_app  
response = self.full\_dispatch\_request()  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File "C:\Users\shawn\OneDrive\Desktop\Unimelb-2024-SEM-1\old\_code.venv\Lib\site-packages\flask\app.py", line 872, in full\_dispatch\_request  
rv = self.handle\_user\_exception(e)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File "C:\Users\shawn\OneDrive\Desktop\Unimelb-2024-SEM-1\old\_code.venv\Lib\site-packages\flask\app.py", line 870, in full\_dispatch\_request  
rv = self.dispatch\_request()  
^^^^^^^^^^^^^^^^^^^^^^^  
File "C:\Users\shawn\OneDrive\Desktop\Unimelb-2024-SEM-1\old\_code.venv\Lib\site-packages\flask\app.py", line 855, in dispatch\_request  
return self.ensure\_sync(self.view\_functions[rule.endpoint])(\*\*view\_args) # type: ignore[no-any-return]  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File "c:\Users\shawn\OneDrive\Desktop\Unimelb-2024-SEM-1\old\_code\package\code\server\server\_app.py", line 1296, in receive\_power  
machine\_list.get(machine\_id).power\_generate=int(machine\_power)  
^^^^^^^^^^^^^^^^^^  
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

**3. In the debug panel in Node-Red, when I set the request that it returns a string, I was seeing the error message like above sending from my backend.**

**4. This is a modification of my code before all of the above happened.**

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

**5. I was not using send\_power\_test.py in this scenario, I was just trying to send the JSON object to this url: /receive\_power.**

---

<div class="post-metadata">

**Author:** ![kitori](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kitori](https://discourse.nodered.org/u/kitori)\
**Post date:** [24 April 2024 05:54 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/8 "2024-04-24T05:54:45Z")

</div>

Maybe your dic object is empty?

in this tutorial, you get the dic with the obj.json property. But im not a flask expert 😃  
[https://sentry.io/answers/flask-getting-post-data/#json-data](https://sentry.io/answers/flask-getting-post-data/#json-data)

```auto
from flask import Flask, request
# ...

@app.route('/json_example', methods=['POST'])
def handle_json():
    data = request.json
    print(data.get('name'))
    print(data.get('age'))
    return data

```

---

<div class="post-metadata">

**Author:** ![sobercactus](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sobercactus](https://discourse.nodered.org/u/sobercactus)\
**Post date:** [27 April 2024 03:41 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/9 "2024-04-27T03:41:19Z")

</div>

Thanks for your help kitori. You Node-red flow is of great help.

I have solved my problems. My orginial code is for receiving form data, not json object.

Have a good day. 😀

---

<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:** [26 July 2024 03:41 UTC](https://discourse.nodered.org/t/send-payload-to-my-web-application-using-http-request/87427/10 "2024-07-26T03:41:27Z")

</div>

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