Postman Dependencies in Test Script

Hello folks,

I am new in postman.
What I want to archieve is:
When I test the API via postman, I can put external data like JSON

Imagine:
You do a request to an API, which delivers you an attribute, which you will need for another request like:

someId = 12345

You need this value, to request another API.
Is there a way, how I can do dependencies in collection tests with external files?
That I can also store the result for example temporary for another request?

Thanks

Hi Anton,

We usually use a variable to store data that is passed from one request to the other.

Using files is rather complicated as Postman has limited access to the filesystem.

Thank you.

Do you have an example, how to do this?
Like calling API one, safe data and put it to another one?

Thanks in advance

Hi @Anton39,

I think this article explains what you´re looking for: https://blog.getpostman.com/2014/01/27/extracting-data-from-responses-and-chaining-requests/

Best,
Christian

Hi @Anton39,

You can use Global variables as well as environment variables to store the data you have received as a response for the next request based on your requirements.

  1. Global Variables: Save the value retrieved from the JSON response as a global variable.These values will be available across all environments. Given below is an example for the same:

Example JSON response:

{

“responseTime”: “100”

}

Usage: pm.globals.set(“variable_key”, pm.response.json().responseTime);

  1. Environment Variables: Save the value retrieved from the JSON response as an environment variable. These values will be available in a specific environment which you have selected as shown in the attached image:
    ManageEnvironments

Example JSON response:

{

“responseTime”: “100”

}

Usage: pm.environment.set(“variable_key”, pm.response.json().responseTime);

To get a detailed understanding on how to use Global and environment variables, have a look at the following link: https://learning.getpostman.com/docs/postman/environments_and_globals/intro_to_environments_and_globals/

1 Like