Trying to send form data but i'm getting req.body as undefined

Describe the bug
I am trying to send form data to my API but req.body is undefined for some reason.

To Reproduce
Steps to reproduce the behavior:

  1. create a new request
  2. enter your API endpoint URL
  3. select the body tab and then select the form-data tab
  4. enter the key name of the form data you are trying to send so your API can recognize it and then the value.
  5. Click send and you should get a response with a status code of 200. If you get an error like me telling me that req.body is undefined then you have the same problem as me.

Expected behavior
I expect my API route handler function to create a new product for my ecommerce site. But instead I get an error coming from my ORM which is Sequelize. Telling me that name cannot be null because I am trying to add it to the database table. I even console.logged it on my server (im using node.js) and it req.body really is undefined.


Here is another picture that is showing that req.body is actually empty. I console.logged it:

App information (please complete the following information):

  • Ecommerce API (Node.js)
  • Postman Version 7.2.1
  • OS: Windows

Additional context
If you have any other question or I am forgetting something to show you guys, just let me know.

Yeah that looks frustrating @asaadullamikabir :frowning:

Welcome to the Postman community though! :+1:

You’ll have to put on your detective hat on to track down how to make it work.

You could open the Postman console
and run the request again. Then check how the request looks there ( try both the pretty and raw views)
That would verify if Postman thinks it’s sending the form data.

Also, is there a system that currently makes the call (web UI, mobile app etc) that you could capture using something like the browser dev tools, Fiddler or CharlesProxy etc? Then double check if you’re doing exactly the same thing in your Postman request.

I notice that the error response in your screenshot reports that cannot be null, have you tried changing the key to exactly that?

same issue ,this is real frustrating…

my body of form-data value showing null after i pass the leadId : 12345 error after testing your leadId is null

This is quite a tricky question to answer without any implementation details of the API. For me, Postman is not really the cause of the issue, it’s just showing you that there is an issue.

What framework is being used? Express or something else?

I’ve found issues with getting that data in the past using Express due to things like the body-parser module not being installed and used correctly.

Try using this on server side:

request.on(‘data’, (data: any) => {

request.on(‘end’, () => {
fileUpload: ‘successful’

I am using Express and i get the same problem . I want to send some text and a file for a sign up page. I am using formidable to upload the file . The file gets uploaded. As I try to acces the body of the request it returns an empty object {}. Please Help me

I was facing the same issue.

var bodyParser = require(‘body-parser’);
const app = express();
app.use(bodyParser.urlencoded({extended: true}));

The above code solved the issue for me!