Array of values inside one CSV cell, Collection Runner

Hello.
How to include a value which is an array inside the CSV cell to be then passed into Collection Runner?
Any advise on it?
All the best
Wojciech

Hi @wmocek,

So if you are using a Collection Runner, with a CSV datafile (I presume), then when you reference the CSV cell in a Pre Request Script, using:

var cell = pm.iterationData.get("ColumnName");

You then can initialize an array like so:

var array = cell.split(",");

The above assumes that your array is separated by commas, which it should be.

I hope this helps!

Thanks Orest for your response.
However what I mean is that I have a CSV file where each column is one key but some keys can contain several values while they are defined in JSON as arrays but I have no idea how to prepare CSV file so that cells in columns corresponding to keys where multiple values are allowed could contain more than one value.

For example:

  "sourceLangs": [
    "{{sourceLangs}}"
  ]

I have a column “sourceLangs” in my CSV but no idea how can I enter there more than one value into the cell.

All the best
Wojciech

Hi @wmocek :wave:

As I understand it, you have a column named “sourceLangs” in CSV file - where the column contains multiple rows, is that correct?

In that case, I believe what you may be able to do is organise the data in CSV as below:
Screen Shot 2021-01-14 at 10.18.28 am

And then you can define the JSON as:
"sourceLangs": {{sourceLangs}}

I hope this helps! Please let me know if that’s not exactly what you are after :slightly_smiling_face:

Hello,
hope you are, fine and thanks for responding.
Organising data the way you suggested does not work as I am getting an error.
All the best
Wojciech

Thanks for getting back @wmocek :wave:

I am sorry to hear that you are still seeing an error - can you elaborate on what specific errors that you are seeing?

Also if you can share some sample CSV file that resembles the actual data, that would be super helpful :slightly_smiling_face:

Thanks for following up.
Here is the CSV file:
import_users_new4.csv - Google Drive error I am getting is 404:


which is the result of not proper CSV formatting which is visible in Preview:

All the best
Wojciech

Hey @wmocek!

Thanks for getting back to me with those information :smiley:

I can see that you are using this API endpoint - according to the documentation, both “sourceLangs” and “targetLangs” expect an array of string.

I have made a slight modification to CSV as below:
Screen Shot 2021-01-18 at 1.49.09 pm

I hope this helps :slightly_smiling_face:

Thanks @taehoshino Send me, please, your CSV.
All the best
Wojciech

Hey @wmocek :wave:

Here is the CSV which I made a slight modification to yours:

Thanks @taehoshino
However in this case body will look like this:


while it should look like this:

hence the error again.
Any advice on this?
All the best
Wojciech

Hello. Maybe it works with something like this:

sourceLangs,targetLangs
“en,de”,“en,ja”
“en,fr”,“en,kr”

It works for me for arrays.

Thanks for getting back!

How about this now?

const sourceLangs = pm.iterationData.get('sourceLangs').split(',')
const targetLangs = pm.iterationData.get('targetLangs').split(',')
pm.environment.set('sourceLangsArr', sourceLangs)
pm.environment.set('targetLangsArr', targetLangs)

An array of strings is now stored as sourceLangsArr etc in environment.

Here is CSV:

Hope this helps!

Thanks @ivanvazquezz
I have tried this already and the only problem is that body looks like below:


while it should look like this:

@taehoshino : I have used your hint entering it into “Pre-request script”
and it has not helped.
All the best everyone.

Hello, @wmocek.

If you want to print the quotes, then maybe this works:

sourceLangs,targetLangs
“”“en”","“de”","“en,ja”""
“”“en,fr”","“en,kr”""

Note that there are 3 quotes at the beginning and at the end. 2 quotes in the middle.

And in the POST don’t write the quotes, like:

“sourceLangs”: [
{{sourceLangs}}
],

Bye

1 Like

Thanks @ivanvazquezz , it helped.
All the best
Wojciech