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

**URL:** <https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002>\
**Category:** Help Hub\
**Created:** [June 19, 2019, 10:02pm UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002 "2019-06-19T22:02:53Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![asaadullamikabir](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@asaadullamikabir](https://community.postman.com/u/asaadullamikabir)\
**Post date:** [June 19, 2019, 10:02pm UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/1 "2019-06-19T22:02:53Z")

</div>

**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.

**Screenshots**

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/8/6/865a87494d8ad12df6a47798554a679784923819.png)

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

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/c/9/c949fc50799931847c929919ecf5a98afb8cb65e.png)  
**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.

---

<div class="post-metadata">

**Author:** ![VincentD123](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vincentd123/32/1845_2.png) [@VincentD123](https://community.postman.com/u/VincentD123)\
**Post date:** [June 20, 2019, 9:13am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/2 "2019-06-20T09:13:35Z")

</div>

Yeah that looks frustrating @asaadullamikabir ☹

Welcome to the Postman community though! 👍

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

You could open the Postman console  
 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/e/ef7f91769a571dbbbdd03a6183793c9dd397a4de.png)  
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 `Product.name` cannot be null, have you tried changing the key to exactly that?

---

<div class="post-metadata">

**Author:** ![natarajan.trichy](https://avatars.discourse-cdn.com/v4/letter/n/3e96dc/32.png) [@natarajan.trichy](https://community.postman.com/u/natarajan.trichy)\
**Post date:** [August 31, 2019, 8:49am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/3 "2019-08-31T08:49:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [August 31, 2019, 10:06am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/4 "2019-08-31T10:06:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ddhar2895](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@ddhar2895](https://community.postman.com/u/ddhar2895)\
**Post date:** [February 26, 2020, 5:02am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/5 "2020-02-26T05:02:30Z")

</div>

Try using this on server side:

request.on(‘data’, (data: any) =\> {  
console.log(data.toString());  
});

request.on(‘end’, () =\> {  
response.json({  
fileUpload: ‘successful’  
});  
});

---

<div class="post-metadata">

**Author:** ![bharath.jrgunner](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@bharath.jrgunner](https://community.postman.com/u/bharath.jrgunner)\
**Post date:** [February 28, 2020, 5:35am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/6 "2020-02-28T05:35:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ta.22.ha.18.s](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@ta.22.ha.18.s](https://community.postman.com/u/ta.22.ha.18.s)\
**Post date:** [October 30, 2020, 8:20am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/7 "2020-10-30T08:20:42Z")

</div>

Hey!  
I was facing the same issue.

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

The above code solved the issue for me!

---

<div class="post-metadata">

**Author:** ![doniyor17ibragimov](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/doniyor17ibragimov/32/8230_2.png) [@doniyor17ibragimov](https://community.postman.com/u/doniyor17ibragimov)\
**Post date:** [April 25, 2021, 12:48am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/8 "2021-04-25T00:48:58Z")

</div>

Your comment solved my problem! I did not insert my code app.use(express.json()) or body parser! Thanks!

---

<div class="post-metadata">

**Author:** ![doniyor17ibragimov](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/doniyor17ibragimov/32/8230_2.png) [@doniyor17ibragimov](https://community.postman.com/u/doniyor17ibragimov)\
**Post date:** [April 25, 2021, 12:54am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/9 "2021-04-25T00:54:06Z")

</div>

I had same issue really frustrating! I used body parser as const express = require('express) → const app = express() → app.use(express.json()); It should work

---

<div class="post-metadata">

**Author:** ![research-cosmologis1](https://avatars.discourse-cdn.com/v4/letter/r/94ad74/32.png) [@research-cosmologis1](https://community.postman.com/u/research-cosmologis1)\
**Post date:** [May 17, 2021, 8:42am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/10 "2021-05-17T08:42:29Z")

</div>

app.use(express.json());

app.use(express.urlencoded({

extended: true

}));  
I tried using this but didn’t worked, postman is sending the respond but on submitting the form its returning a null body.  
Even body parser isn’t working:- “The declaration was marked as deprecated here.”

---

<div class="post-metadata">

**Author:** ![jerard.king](https://avatars.discourse-cdn.com/v4/letter/j/8dc957/32.png) [@jerard.king](https://community.postman.com/u/jerard.king)\
**Post date:** [August 13, 2021, 8:12am UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/11 "2021-08-13T08:12:30Z")

</div>

I’m running into the same issue.  
The problem is that postman is not sending the files as part of the from-data request body so the needed files and other multipart data is not even being sent to my API.

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/1/1f2b0cd7897fc348060b5c08702efe0ce85f2dc0.png)

---

<div class="post-metadata">

**Author:** ![newer-to-webdev](https://avatars.discourse-cdn.com/v4/letter/n/ecd19e/32.png) [@newer-to-webdev](https://community.postman.com/u/newer-to-webdev)\
**Post date:** [September 5, 2021, 2:18pm UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/12 "2021-09-05T14:18:02Z")

</div>

Remains undefined in post man  
–\>Here are your undefined undefined tacos  
even I add app.use(express.json()); in index.js file.

 ![img01](https://us1.discourse-cdn.com/getpostman/original/2X/2/24932330166dc184652f9eb5892d743eef684b4e.png)

Till I figured out I didn’t change TEXT to JSON, now it works

---

<div class="post-metadata">

**Author:** ![Godwin\_O](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Godwin\_O](https://community.postman.com/u/Godwin_O)\
**Post date:** [July 21, 2023, 12:10pm UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/13 "2023-07-21T12:10:12Z")

</div>

This resolved the error I have been trying to fix for some hours.

Much thanks

---

<div class="post-metadata">

**Author:** ![aldaineamber](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@aldaineamber](https://community.postman.com/u/aldaineamber)\
**Post date:** [November 8, 2023, 4:52pm UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/14 "2023-11-08T16:52:52Z")

</div>

I was trying to upload files but was getting this error.  
Sending with JSON works fine no errors there.  
However even if the data I am sending over is not a file, I would get an empty object for the req.body.  
The fix was to use **express-fileupload** middleware which would handle file uploads.

---

<div class="post-metadata">

**Author:** ![material-technologi4](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@material-technologi4](https://community.postman.com/u/material-technologi4)\
**Post date:** [November 21, 2023, 3:43pm UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/15 "2023-11-21T15:43:24Z")

</div>

Yeah. Even the multer middleware will fix the issue

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 21, 2023, 3:55pm UTC](https://community.postman.com/t/trying-to-send-form-data-but-im-getting-req-body-as-undefined/6002/16 "2023-11-21T15:55:42Z")

</div>

Closed on November 21, 2023, 3:55pm UTC


