Sending data to a Rest API

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!



please find a pic of the flow

should work.

What does this test flow do...

[{"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"]]}]

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


thank you for your response Steve
it is only creating the id

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

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)

@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

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 :slight_smile:

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.

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

1 Like

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