Pass response to another request in collection

Hi Guys,

Newbie here, I’m creating a test suite for a collection that has multiple requests, the first request within the collection will return a token which im storing in an environment variable within a test in request 1. I would like this token to get passed to request 2 which needs this token but I cant get it to work from running in collection folder.

Hi @defconn

In your first request, you would need to set the variable in the “Test” tab using;
pm.environment.set("variable_key", "variable_value");

Then in your second request, you would call the variable using the {{}} notation.

Here is an example;
First call;

Second call;

Hi @w4dd325 , your suggestion is exactly what I did, the problem is when I run the requests from the collection test runner.

I think the problem is the execution of the collection test runner, it will run request 2 before it runs the test script in request 1 (which saves the token from response 1) which means request 1 passes but request 2 doesnt have the token yet so it fails.

That was run in the collection runner.

If your issue is simply the flow of requests being made then try using the setNextRequest option. It will allow you to explicitly state in which order calls are executed.

The requests are ordered correctly, but how can I run test script in request 1 run before request 2? It doesnt work if I put it in the pre-request.

Can you show what you have tried?

Hello,
I just want to take this time to share an example collection that uses this type of workflow

https://www.postman.com/postman/workspace/published-postman-templates/folder/20021534-f2b39eb1-393a-4a9e-8fb0-135abb60c9d3?ctx=documentation

If you take a look at folder Using Request Workflows you can see how the postman.setNextRequest() is utilized. Feel free to fork and add the right authorization to run this folder using the collection runner