Tickets for the 2019 Postman User Conference are available! Get your tickets now before they're gone. Learn more.

Branching and looping

When running a collection, you can branch and loop across API requests in Postman using the postman.setNextRequest("request_name"); function.

set next request method

Set the request to be executed next

postman.setNextRequest("request_name");

Stop workflow execution

postman.setNextRequest(null);

Some salient points about postman.setNextRequest():

  1. Specify the name or ID of the subsequent request and the collection runner will take care of the rest.
  2. It can be used in the pre-request or the test script. If there's more than one assignment, the last set value takes precedence.
  3. If postman.setNextRequest() is absent in a request, the collection runner defaults to linear execution and moves to the next request

For more information about control flow, refer to building workflows.