0

I'm designing a fairly simple collection, with two services in the collection:

  • Request # 1 : get token service
  • Request #2 : service to get detailed information (needs token from previous service)

I've managed to get the token from service #1 and set it into a variable, and use said token in Request #2. I then use a csv file in Runner to call service #2 using different arguments.

What I'm trying to achieve is to run service #1 only once, instead of running as many times as the number of lines on the CSV. Is it possible?

noitib
  • 148
  • 1
  • 13

1 Answers1

0

You can use postman.setNextRequest("request #2"); in the Tests script of request #2 to skip the execution of request #1 after the first run.

But you also need to add a condition to only do that while pm.info.iteration is smaller than your amount of required executions to avoid an endless loop.

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
  • 1
    I didn't know about the pm.info.iteration number. I successfully accessed it and printed to log, wrote an if statement with setNextRequest but request #1 is still being called. var iteration = pm.info.iteration if(iteration > 0 ){ console.log("skipping token request") postman.setNextRequest("Request2"); } else { console.log("First run: getting token") } – noitib Sep 03 '20 at 08:36
  • I didn't know about "postman.setNextRequest() is always executed at the end of the current request. This means that if you put this function before other code blocks anywhere in pre-request or test script, these blocks will still execute." I edited my answer accordingly. (See https://learning.postman.com/docs/running-collections/building-workflows/#:~:text=setNextRequest()%20is%20always%20executed,source%20of%20your%20collection%20run) – Christian Baumann Sep 03 '20 at 14:31