How i can check environmet from a csv?

Hi all,

i working with postman from a couple of days and it is very useful :).

I configured a collection like the image:

image

it works fine and i can create user and role with mongo db api from a csv.

My question is, how i can check the environmet and execute the correct line from a csv? My csv is formatted like the screen:

if i run collection with that csv postman create in all enviroment, DV and TS, the same object.
If possibile to configure a control that get the environmet, ts and dv also from a new Column in csv:
image

and than create object in the right environmet?

I just put into body request the json code and setup the variable on postman.

Here body json code(is the same in all request):


image

Thanks

Hey @emanuele1986,

Welcome to the community!!

You’ll only be able to set one environment during a collection run. However, If I understood your request correctly you’d like to use the TS values for the TS folder and the DV values for the DV folder, is that correct?

In that case, I believe you should accomplish your desired outcome by using branching-looping to do so. I’ll reference the documentation here: https://learning.postman.com/docs/postman/scripts/branching-and-looping/

You’d use fetch the data from the CSV file ( more information on how to do so here: https://learning.postman.com/docs/postman/scripts/postman-sandbox-api-reference/#pmiterationdata ) and the branching-looping would allow you to set your workflow for requests with the logic you’d like to establish.

Hopefully, this helps!

Hi @SabriH ,

yes is correct. I would like to use, from a unique csv, TS variable for TS folder, DV variables for a DV folder, etc…

I red that links but i don’t understand well. I tried to do some test with postman.setNextRequest(“nomaofmyrequest”), but it didn’t work well:

  1. if i configure it on collection or folder in prerequisites script:

it take only the first row of csv and after went in conflict(it try to create always firts row of csv)

if i put it directly on request it create same object in ts and dv folder:

Can you make please an example for branch looping and pmiterationdata for how i have to setup it?
Excuse me for this request.

Thanks

Hey @emanuele1986,

Just following up here. As requested, I’ve added a template here: https://documenter.getpostman.com/view/10582367/SzYbxGw1?version=latest to hopefully illustrate. This isn’t a very in-depth example but hopefully will help demonstrate some of the possibilities regarding what you are trying to accomplish.

The CSV used in the example template was the following:
Screen Shot 2020-04-03 at 4.05.23 PM

So for this example, a dummy request was set where we fetch data from the CSV ( in this case the environment variables ) and then set the next request accordingly depending on the value of the variable. You could then expand upon this example depending on your requirements.

Hopefully, this helps!

Thanks for the example, i will try in the next days :slight_smile: