# How to handle CSV response with postman

**URL:** <https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219>\
**Category:** Help Hub\
**Tags:** csv\
**Created:** [March 14, 2018, 6:23pm UTC](https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219 "2018-03-14T18:23:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![grant.prichard](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/grant.prichard/32/435_2.png) [@grant.prichard](https://community.postman.com/u/grant.prichard)\
**Post date:** [March 14, 2018, 6:23pm UTC](https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219/1 "2018-03-14T18:23:39Z")

</div>

Hello all,

I am trying to process a CSV response, and verify values within the CSV returned are matching what I expect based on the beginning of my collection. Can anyone point me in the right direction on how I might go about doing this?

Thanks,  
Grant

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [March 15, 2018, 11:24am UTC](https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219/2 "2018-03-15T11:24:39Z")

</div>

Can you post a minimal sample of your CSV response and what kind of things you are trying to assert?

---

<div class="post-metadata">

**Author:** ![grant.prichard](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/grant.prichard/32/435_2.png) [@grant.prichard](https://community.postman.com/u/grant.prichard)\
**Post date:** [March 15, 2018, 2:32pm UTC](https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219/3 "2018-03-15T14:32:39Z")

</div>

@vdespa certainly! Here’s a sample of the CSV I’m receiving:

> InvoiceId,InvoiceCreate,InvoiceCapture,First,Last,InvType,InvTotal,InvStatus,InvCredit,ResId,ResHash,ResStart,ResEnd,Duration,Decal,Plate,Market,Community,TollId,BeforeTax,Tax,AfterTax  
> 34001,2018-03-07T21:46:30+0000,2018-03-07T21:46:37+0000,First,Last,Test,“$3,500.00”,PAID,N/A,1234,ABC1234,2018-03-09T14:00:00+0000,N/A,API-GAP12,“API-RSQ - 853”,“Test Data”,“Test Data”,7712141,$92.42,$9.24,$101.66  
> 34000,2018-03-07T20:39:46+0000,2018-03-07T20:39:46+0000,First,Last,Test,“$3,500.00”,PAID,N/A,1234,CDE1234,2018-03-12T13:00:00+0000,N/A,ABCD123ID,ABCD123,Test,Data,123ABCD,$0.00,$0.00,$0.00  
> 33999,2018-03-07T20:25:53+0000,2018-03-07T20:25:56+0000,First,Last,Test,“$3,500.00”,PAID,N/A,1234,EFG1234,“Test Data”,N/A,“$1,363.64”,$136.36,“$1,500.00”  
> 33998,2018-03-07T20:08:53+0000,2018-03-07T20:08:56+0000,First,Last,Test,“$3,500.00”,PAID,N/A,1234,GHI1234,“Test Data”,N/A,“$1,501.50”,$298.50,“$1,800.00”

Trying to assert whether something appears in the output, with the correct fee. So for the example above I might be looking to see that ResHash ABC1234 was charged the correct amount of 3500.

---

<div class="post-metadata">

**Author:** ![vdespa](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/vdespa/32/2770_2.png) [@vdespa](https://community.postman.com/u/vdespa)\
**Post date:** [March 16, 2018, 10:31pm UTC](https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219/4 "2018-03-16T22:31:05Z")

</div>

UPDATE: See answer from @saswat.das first.

Interesting problem, so I decided to do a video on this:

Below a short summary:

1. You can use a 3rd party library to parse a CSV response
2. I suggest using [papaparse.com](http://papaparse.com)
3. After parsing the response, you have a JavaScript object, so nothing special anymore.

Let me know if this helps you.

---

<div class="post-metadata">

**Author:** ![shamasis](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/shamasis/32/53_2.png) [@shamasis](https://community.postman.com/u/shamasis)\
**Post date:** [March 18, 2018, 3:01pm UTC](https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219/5 "2018-03-18T15:01:18Z")

</div>

Postman script has `csv-parse` library built in.

---

<div class="post-metadata">

**Author:** ![saswat.das](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@saswat.das](https://community.postman.com/u/saswat.das)\
**Post date:** [March 18, 2018, 7:56pm UTC](https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219/6 "2018-03-18T19:56:15Z")

</div>

Hi @grant.prichard, Postman natively supports CSV parsing. Here is a sample test script that does exactly what you asked for

> Trying to assert whether something appears in the output, with the correct fee. So for the example above I might be looking to see that ResHash ABC1234 was charged the correct amount of 3500.

Postman - **Test Script**

```javascript
/* 
 * For documentation check http://csv.adaltas.com/parse/
 * and https://www.getpostman.com/docs/v6/postman/scripts/postman_sandbox_api_reference
 *   
 */

const parse = require('csv-parse/lib/sync'),
    parsedBody = parse(responseBody, {relax_column_count: true});
    
pm.test("Correct CSV response", function () {
    // Check that we have at least 2 two (header + row)
    pm.expect(parsedBody).to.have.length.above(1);
    
    // Getting the index of ResHash and InvTotal 
    const head = parsedBody.shift(),
        resHash = head.indexOf('ResHash'),
        invTotal = head.indexOf('InvTotal');
    
    // Iterate through the rows
    parsedBody.forEach(function(row) {
        
        // If resHash matches the required value perform the test
        if(row[resHash] === 'ABC1234') {
            pm.expect(row[invTotal]).to.equal('$3,500.00');
        }
    })
});

```

I am also sharing a postman collection with you, which you can use to get started [https://www.getpostman.com/collections/4fe24427914d24149c8e](https://www.getpostman.com/collections/4fe24427914d24149c8e)

_Also feel free to reach out to us, If you need any more help or clarification regarding CSV parsing in Postman_

---

<div class="post-metadata">

**Author:** ![grant.prichard](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/grant.prichard/32/435_2.png) [@grant.prichard](https://community.postman.com/u/grant.prichard)\
**Post date:** [March 19, 2018, 7:27pm UTC](https://community.postman.com/t/how-to-handle-csv-response-with-postman/1219/7 "2018-03-19T19:27:43Z")

</div>

this worked like a charm, thank you so much for the help!
