# How to Verify Body values in a Post Request

**URL:** <https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158>\
**Category:** Help Hub\
**Tags:** tests, post\
**Created:** [June 24, 2021, 6:49am UTC](https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158 "2021-06-24T06:49:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![salmankhan94](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@salmankhan94](https://community.postman.com/u/salmankhan94)\
**Post date:** [June 24, 2021, 6:49am UTC](https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158/1 "2021-06-24T06:49:39Z")

</div>

Hi, I am new to POSTMAN and trying to validate the data to be not null, empty or undefined in a pre-request script of Request Body.

This is the data I am passing in a request body.

```auto
{
    "name": "{{$randomFirstName}}",
    "number": "0123456789",
    "catid": 14,
    "catname": "abc",
    "createdby": "admin"
}

```

Following is my pre-request script to verify the values to be not null, but this isn’t working and the test case is also passing if I pass a null value in the request body.

```auto
const reqBody = request.data;

pm.test("Verify the values are not null", function () {
    pm.expect(reqBody.name).to.not.null;
    pm.expect(reqBody.number).to.not.null;
    pm.expect(reqBody.catid).to.not.null;
    pm.expect(reqBody.catname).to.not.null;
    pm.expect(reqBody.createdby).to.not.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:** [June 24, 2021, 7:08am UTC](https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158/2 "2021-06-24T07:08:34Z")

</div>

Hey @salmankhan94

Not sure where you’re getting `request.data` from?

Have you tried:

```auto
const reqBody =JSON.parse(pm.request.body.raw)

```

If you’re ever having issues with something in the sandbox, a good tip is to just `console.log()` to see what data is being assigned to certain variables.

---

<div class="post-metadata">

**Author:** ![jency.stella19](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jency.stella19/32/16633_2.png) [@jency.stella19](https://community.postman.com/u/jency.stella19)\
**Post date:** [June 24, 2021, 8:49am UTC](https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158/3 "2021-06-24T08:49:18Z")

</div>

HI @salmankhan94

In your Test Script did you try as below?

```auto
var req = JSON.parse(request.data);
pm.test("Verify the name" , function () {
    pm.expect(req.name, 'Name is not null').to.not.be.null;
});

```

Is this what you are expecting?

---

<div class="post-metadata">

**Author:** ![salmankhan94](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@salmankhan94](https://community.postman.com/u/salmankhan94)\
**Post date:** [June 24, 2021, 9:26am UTC](https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158/4 "2021-06-24T09:26:31Z")

</div>

Yes, it worked. Seems like JSON.parse(request.data) is the difference. Thanks

---

<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:** [June 24, 2021, 9:33am UTC](https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158/5 "2021-06-24T09:33:44Z")

</div>

Using `JSON.parse(pm.request.body.raw)` is the same thing as `JSON.parse(request.data)` but it’s using the newer `pm.*` API syntax, that’s the reason why I suggested that. 😃

There was nothing _wrong_ with your test, it was just the reference that you were making to the request body data.

```javascript
const reqBody = JSON.parse(pm.request.body.raw)

pm.test("Verify the values are not null", function () {
    pm.expect(reqBody.name).to.not.null;
    pm.expect(reqBody.number).to.not.null;
    pm.expect(reqBody.catid).to.not.null;
    pm.expect(reqBody.catname).to.not.null;
    pm.expect(reqBody.createdby).to.not.null;
});

```

---

<div class="post-metadata">

**Author:** ![salmankhan94](https://avatars.discourse-cdn.com/v4/letter/s/9de0a6/32.png) [@salmankhan94](https://community.postman.com/u/salmankhan94)\
**Post date:** [June 24, 2021, 10:01am UTC](https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158/6 "2021-06-24T10:01:34Z")

</div>

Yes Danny you are right. Thanks for the help man. Appreciate the prompt response from you guys.

---

<div class="post-metadata">

**Author:** ![jency.stella19](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jency.stella19/32/16633_2.png) [@jency.stella19](https://community.postman.com/u/jency.stella19)\
**Post date:** [June 24, 2021, 10:05am UTC](https://community.postman.com/t/how-to-verify-body-values-in-a-post-request/25158/7 "2021-06-24T10:05:16Z")

</div>

Glad now its clear 🙂
