# Sending data to a Rest API

**URL:** https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774
**Category:** General
**Created:** [27 July 2020 14:17 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774 "2020-07-27T14:17:14Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![DanielBerith](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DanielBerith](https://discourse.nodered.org/u/DanielBerith)
#### Post date: [27 July 2020 14:17 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/1 "2020-07-27T14:17:14Z")

</div>

Good day,

I hope you are doing well,  
i'm trying to send data to a Rest API, that i have created using node.js and express.  
i am using the post request, i'm new to node-red, the GET request work fine but i'm kinda stuck when it comes to POST request, the debug side shows that it working and display the successful message from the app but when i look into the database, only the id is created.  
when i try to console in the terminal it is empty.  
i am using a localhost server  
please find some pictures to illustrate  
Thank you for you time!

Regards  
Daniel

 ![Capture1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/6/56d9dd411054ee3eaad5abc37906f201fd5fbef9.png) ![Screenshot (45)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/aee848f8080e2ca46e4dab44520cf22adbc635c6.png)

---

<div class="post-metadata">

### Author: ![DanielBerith](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DanielBerith](https://discourse.nodered.org/u/DanielBerith)
#### Post date: [27 July 2020 14:18 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/2 "2020-07-27T14:18:09Z")

</div>

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/a/8aaa3dfdd363d7518a8994e2e9022b04a617df3a.png)

 ![Screenshot (44)](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/b/eb45bd128c3de6e7a9ed69b6bdf11c30e860ea1d.png)

---

<div class="post-metadata">

### Author: ![DanielBerith](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DanielBerith](https://discourse.nodered.org/u/DanielBerith)
#### Post date: [27 July 2020 14:24 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/3 "2020-07-27T14:24:16Z")

</div>

please find a pic of the flow

 ![test](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/3/83b4fbe0595f98b9d1f496abf48810f03d2182b1.png)

---

<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: [27 July 2020 14:27 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/4 "2020-07-27T14:27:16Z")

</div>

should work.

What does this test flow do...

```auto
[{"id":"e1a946e4.37f558","type":"inject","z":"63b08af4.a0bfc4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"title\":\"hello\"}","payloadType":"json","x":210,"y":160,"wires":[["8296bb26.d2e858"]]},{"id":"8296bb26.d2e858","type":"http request","z":"63b08af4.a0bfc4","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"http://localhost:1880/test","tls":"","persist":false,"proxy":"","authType":"","x":400,"y":160,"wires":[["a4938060.8293e"]]},{"id":"edd853b3.56c2f","type":"http in","z":"63b08af4.a0bfc4","name":"","url":"/test","method":"post","upload":false,"swaggerDoc":"","x":230,"y":300,"wires":[["4a46b53.7172b4c","8e949317.b184f"]]},{"id":"4a46b53.7172b4c","type":"debug","z":"63b08af4.a0bfc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":390,"y":380,"wires":[]},{"id":"a4938060.8293e","type":"debug","z":"63b08af4.a0bfc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":160,"wires":[]},{"id":"8759ab5f.c3e2e8","type":"http response","z":"63b08af4.a0bfc4","name":"","statusCode":"","headers":{},"x":630,"y":300,"wires":[]},{"id":"8e949317.b184f","type":"change","z":"63b08af4.a0bfc4","name":"","rules":[{"t":"set","p":"payload.ok","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":300,"wires":[["8759ab5f.c3e2e8"]]}]

```

edit...  
maybe you need to add Content-Type header `application/json` in your request?  
also are you using bodyParser.json?

```auto
app.use(bodyParser.json());

```

---

<div class="post-metadata">

### Author: ![DanielBerith](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DanielBerith](https://discourse.nodered.org/u/DanielBerith)
#### Post date: [27 July 2020 14:36 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/5 "2020-07-27T14:36:18Z")

</div>

thank you for your response Steve  
it is only creating the id  
 ![st](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/f/7fe5c252dedbec648deab27be2fe38f23c98c11f.png)

---

<div class="post-metadata">

### Author: ![DanielBerith](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DanielBerith](https://discourse.nodered.org/u/DanielBerith)
#### Post date: [27 July 2020 14:37 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/6 "2020-07-27T14:37:11Z")

</div>

@Steve-Mcl i am not using that  
let me try it

---

<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: [27 July 2020 14:39 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/7 "2020-07-27T14:39:45Z")

</div>

that demo flow i posted was to create an endpoint in node red to test if your http-request was correctly sending data.

in other words, taking your express application out of the equation (as a process of elimination)

Also, did you know you can push data straight to database from node-red (im only adding that info in case you dont realise and are building an express app unnecessarily)

---

<div class="post-metadata">

### Author: ![DanielBerith](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DanielBerith](https://discourse.nodered.org/u/DanielBerith)
#### Post date: [27 July 2020 14:43 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/8 "2020-07-27T14:43:28Z")

</div>

@Steve-Mcl thank you, i just added app.use(bodyParser.json()); in my application and it works  
and yes i have try it with mongodb but i was getting an error that why i tried to build a Rest API

---

<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: [27 July 2020 14:47 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/9 "2020-07-27T14:47:21Z")

</div>

> [@DanielBerith](#):
>
> yes i have try it with mongodb but i was getting an error

Did you report it on the repos issues pages? It is always beneficial to do so if you have exhausted forums etc to raise an issue to give the DEV the chance to fix any bugs. Win win for everyone 🙂

I see this is your first thread on this forum - so I guess you didnt make a post here.

I can assure you plenty of users have had success with node-red mongodb without needing to build an express app.

Anyhow, glad you're sorted.

---

<div class="post-metadata">

### Author: ![DanielBerith](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@DanielBerith](https://discourse.nodered.org/u/DanielBerith)
#### Post date: [27 July 2020 14:49 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/10 "2020-07-27T14:49:39Z")

</div>

Thanks again!  
and i will report the error that i got with mongodb

---

<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: [10 August 2020 14:49 UTC](https://discourse.nodered.org/t/sending-data-to-a-rest-api/30774/11 "2020-08-10T14:49:45Z")

</div>

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