How to pass a csv in collection runner which starts with 0's

I am using collection runner to run a GET command which uses a variable. I have the code ready and running for multiple values in the variable. Now i am trying to use collection runner and import a csv file to get the input values . This runs fine when my input id starts with 1 or something but it fails when my input id starts with 0 .For all inputs with 0 it takes from the next value and fails , how can i get rid of this error? My csv file if i open it on notepad i can see the leading zeros in there.

Thanks,
Sujith

I tried using “01234” within the quotes and due to the quotes the runner reads it as %220123422% which is also not working in my case

Hey @sujithkumar.matharas,

I believe this is expected behaviour because the number without quotes is converted to a Javascript Number when the CSV gets parsed in the Postman app. You cannot store a number with a leading zero in Javascript. You can replicate this behaviour in the Chrome Console:


Thus why wrapping the number in quotes should typically help here because it’s treated as a String. There’s some context here, if needed: Runner Removes leading 0's from .csv data · Issue #2734 · postmanlabs/postman-app-support · GitHub.

Now regarding why it isn’t working for your particular use case, i.e. %220123422%, could you provide more information or screenshots about how you’re using this value? I just tried on my end by saving it to an Environment Variable and then referencing the variable as part of a URL param, and it worked but curious to get more details. Hopefully, the information provided helps.

Hi Sabri,

I stored the values in my csv file as
“NI603160”
“10090260”
“03830539”
with header companies which is my variable and when i pass this file in collection runner i get this error

So if you see in the error after gb it has %22 before our provided ID because of the quotes.

just to add to this, i dont have anything in my body & pre-request script however i have this in my tests code
pm.test(“Body contains companies”, function () {

pm.expect(pm.response.text()).to.include(pm.iterationData.get("companies"));




// older syntax still works too: with dot or bracket notation

pm.expect(pm.response.text()).to.include(data.companies); 

console.log("companies to be sent: " + data["companies"]); 

});

to loop through all id’s and i havent declared any variable in global or environments

Hi @sujithkumar.matharas,

How are you setting the URL? When I include quotes around the item in the CSV file, it resolves as a string with pm.iterationData.get('companies'). It looks like the error you’re getting is coming from the URL containing quotes. I’m wondering if those quotes are sneaking in via some other way. If I include {{companies}} as a variable in the URL, that’s also resolving correctly. Are you using that variable syntax in the URL address bar or are you setting the URL in a pre-request script via pm.request.url?

Best,

Kevin

@sujithkumar.matharas,

One more thing. I’d make sure your quotes aren’t getting escaped in the CSV file. It should look like "01234" in the raw CSV file, not """01234""".

Best,

Kevin

i was using “01234” in this format only but it wasnt working, so i used online csv to json convertor and then uploaded the json file which ran fine.

This is a very common scenario to have leading zeroes in imported data variables.
I’m surprised why postman didn’t resolve this yet.
As a temporary solution, I am converting CSV to JSON and running all my data driven tests (yes, this is cumbersome way but no other option).

Thanks,
Arjun Marati

1 Like

I know i’m a couple of years late, but incase anyone else comes across this. This is how I got around it (Mine was always a pre-fixed length):

var policyno = data[‘PolicyNo’].toString()
if(policyno.length < 12){
policyno = ‘0’+ policyno
pm.variables.set(“PolicyNo”,policyno)
}

1 Like

A fix was added to the latest version (10.18) which handles the issue with leading zeros.

You can read more about that here:

1 Like