# How can I validate Postman API response contains the String mentioned CSV file

**URL:** <https://community.postman.com/t/how-can-i-validate-postman-api-response-contains-the-string-mentioned-csv-file/15473>\
**Category:** Help Hub\
**Tags:** tests, variables, collections, csvdatafile\
**Created:** [September 1, 2020, 2:52am UTC](https://community.postman.com/t/how-can-i-validate-postman-api-response-contains-the-string-mentioned-csv-file/15473 "2020-09-01T02:52:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![p.s.m.rodrigo](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@p.s.m.rodrigo](https://community.postman.com/u/p.s.m.rodrigo)\
**Post date:** [September 1, 2020, 2:52am UTC](https://community.postman.com/t/how-can-i-validate-postman-api-response-contains-the-string-mentioned-csv-file/15473/1 "2020-09-01T02:52:07Z")

</div>

**Your question may already have an answer on the community forum. Please search for related topics, and then read through the [guidelines](https://community.postman.com/t/about-the-help-category/38) before creating a new topic.**

When running a Postman requests through Collection runner by passing the values contain in a CSV file for the input parameters, how can I validate each response contain the String text mentioned in the expected value column in this CSV file. I also want to write each response to the Actual result column in this CSV file.

 ![Validate](https://us1.discourse-cdn.com/getpostman/original/2X/6/676db559e05dabf2fa82ecaa6678f2f3edacc3f6.png)

For example after executing the 1st request in the above pic using the Postman collection runner I want to validate the response contains ‘Sydney’ as a text value and give the result as ‘PASS’ or ‘FAIL’ as well as write the actual response to the Actual result column of the above file. This should continue till the last row of the CSV file

---

<div class="post-metadata">

**Author:** ![arlem](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/arlem/32/3078_2.png) [@arlem](https://community.postman.com/u/arlem)\
**Post date:** [September 1, 2020, 1:21pm UTC](https://community.postman.com/t/how-can-i-validate-postman-api-response-contains-the-string-mentioned-csv-file/15473/2 "2020-09-01T13:21:38Z")

</div>

Hey @p.s.m.rodrigo! Welcome to the community! 🚀

You can use the `pm` API to compare the response and the data from the file. You’ll need to use `pm.iterationData.get("value")` to get the value from the CSV file and `pm.response.json()` to get the response from the server.

You can then use a test to get a pass/fail status on it, e.g.:

```
 pm.test("Response value matches expected value", function () {
         // this is the element you get from the response
         var jsonData = pm.response.json().valueToCheck;
         // this is the element coming from the data file
         pm.expect(jsonData.value).to.eql(pm.iterationData.get("value"));
 });

```

Updating the CSV file with the response won’t be feasible directly though, you’ll need to find a way to write to a file, here are a few examples of how this could be achieved:

> **[Postman: How to Write Files to Disk?](https://medium.com/apis-with-valentine/postman-how-to-write-files-to-disk-5ee398624a42)**
>
> Sooner or later you will ask yourself the question: how can a read or write files to disk when using Postman?

> **[Write Responses To File](https://documenter.getpostman.com/view/3407886/RWgp1fB5)**
>
> This collection makes it easy for users who want to write the response of each request to a file.
> This can be extended to write anything for eg. meta information or value of variables being used.
> 
> 
> This project is using a powerful feature built in...
