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.
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:
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.
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
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?
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).