# I am insert data in postman and i want add validation

**URL:** <https://community.postman.com/t/i-am-insert-data-in-postman-and-i-want-add-validation/7364>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [August 23, 2019, 7:11am UTC](https://community.postman.com/t/i-am-insert-data-in-postman-and-i-want-add-validation/7364 "2019-08-23T07:11:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradeep49](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@pradeep49](https://community.postman.com/u/pradeep49)\
**Post date:** [August 23, 2019, 7:11am UTC](https://community.postman.com/t/i-am-insert-data-in-postman-and-i-want-add-validation/7364/1 "2019-08-23T07:11:59Z")

</div>

I am inserting data in postman, Data inserting.  
I want to apply validation from POST method in a “TEST SCRIPT”.

I am new to Postman, I am not able to understand

I am writing my json down blow

```
{
  "firstname": "pradeep",
  "lastname": "tiwari",
  "mobile_no": 99000000000
  "email": "pradeep@gmail.com",
  "user_type": 4,
  "password": "pradeep1",
  "confirmPassword":"pradeep1",
  "dob":"nanana",
  "u_org":25,
  "isfoundingpartner":"undifine",
  "gender":1
}
```

---

<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 23, 2019, 8:35am UTC](https://community.postman.com/t/i-am-insert-data-in-postman-and-i-want-add-validation/7364/2 "2019-08-23T08:35:04Z")

</div>

Hey @pradeep49,

Welcome to the community, it’s great to see you here! 🏆

Have no fear - We’re all here to help you learn and understand. ❤

What would you like to validate? Once you know the answer to that question, writing tests for that will become a lot clearer.

I see that you have posted your `Request` body, what’s returned in the `Response`?

These are a couple of resources that will explain a little about writing tests in Postman:

[https://learning.getpostman.com/docs/postman/scripts/test\_scripts](https://learning.getpostman.com/docs/postman/scripts/test_scripts)

> **[Writing tests in Postman | Postman Blog](https://blog.postman.com/writing-tests-in-postman/)**
>
> Everyone agrees that writing tests is important, but not everyone does it. As you introduce new code, tests ensure that your API...

---

<div class="post-metadata">

**Author:** ![pradeep49](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@pradeep49](https://community.postman.com/u/pradeep49)\
**Post date:** [August 23, 2019, 9:38am UTC](https://community.postman.com/t/i-am-insert-data-in-postman-and-i-want-add-validation/7364/3 "2019-08-23T09:38:07Z")

</div>

I am getting a response:

```
{
    "result": {
        "code": 200,
        "status": true,
        "message": "User successfully registered"
    }
}

```

One more thing, if I leave a field empty in the concert, then its validation gives me a response in the show like I leave Blanken on the stage.

Example:-

```
{
  "firstname": "",
  "lastname": "tiwari",
  "mobile_no": 99000000000
  "email": "pradeep@gmail.com",
  "user_type": 4,
  "password": "pradeep1",
  "confirmPassword":"pradeep1",
  "dob":"nanana",
  "u_org":25,
  "isfoundingpartner":"undifine",
  "gender":1
}

```

I get response

```
{
    "result": {
        "code": 112,
        "status": false,
        "message": "Firstname can not be empty"
    }
}

```

If you have a script, then tell me how do I show this message in ‘Test Results’  
If this message is shown in ‘Test Result’, then I will not have to get validation  
I want to show in the “Message” in “Test Results”  
thank you

---

<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 23, 2019, 10:09am UTC](https://community.postman.com/t/i-am-insert-data-in-postman-and-i-want-add-validation/7364/4 "2019-08-23T10:09:11Z")

</div>

You could use something like this to check response data on a successful user registration:

```
pm.test("Successfully register a user", function () {
    let jsonData = pm.response.json().result
    pm.expect(jsonData.code).to.eql(200)
    pm.expect(jsonData.status).to.be.true
    pm.expect(jsonData.message).to.eql("User successfully registered")
})

```

It’s setting the `results` object in the response, as the `jsonData` variable. Then using the `pm.expect()` function, it’s checking the different values to ensure that these are returned correctly.

The `pm.expect()` function works with the `[chaijs](https://www.chaijs.com/api/bdd/)` assertion library that contains certain _getters_ that chain together to construct assertions.

If you’re also looking to add a set of `negative` type tests to check that these failed cases are working as you expect them too, I would add new requests to the Collection and have these in a separate folder to the `positive` type tests.

Using the method above, you should be able to construct some tests to check for these different scenarios.

You could also look for things like:

- Other different blank fields
- All blank fields
- Missing `Keys`
- Additional `Keys`
- The correct data types (swap string values for integers and vice versa)
- `null` and `undefined` values
- Different HTTP Methods and how these are handled (Is it just expecting you to POST something)
- The actual response code returned (Should a successfully created user be a 200 or a 201)
- etc.

This is not an exhaustive list but just _some_ areas that you could create additional tests to check the data.

---

<div class="post-metadata">

**Author:** ![pradeep49](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@pradeep49](https://community.postman.com/u/pradeep49)\
**Post date:** [August 23, 2019, 10:44am UTC](https://community.postman.com/t/i-am-insert-data-in-postman-and-i-want-add-validation/7364/5 "2019-08-23T10:44:23Z")

</div>

@danny-dainton My problem is solved by your reply  
I was engaged in it for 2 days before asking question  
i added if and else statement in your replay  
Got what i want  
I got the task at the postman Doing the same Right now i have more questions but  
Thanks again
