Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the "local" variables in Postman?

Tags:

Postman's documentation leaves a lot to be desired. In their Variables page they say:

The following scopes are available to you:

  1. Global
  2. Environment
  3. Local
  4. Data

There's information about the Global and Environment scopes, and I believe the "Data" scope is the data from a collection run. But what are the "local" variables?

Because I'd love to have a variable that is calculated on the fly, used for the request, and then discarded. Both global and environment variables are persistent.

like image 678
Vilx- Avatar asked Sep 21 '17 09:09

Vilx-


1 Answers

According to the Postman Quick Reference Guide local variables are only available within the request (or collection run) that has set them. So they are used for the request or collection run and then discarded.

When to use:

passing data from the pre-request script to the request or tests or between requests.

The behavior is a bit different in Postman vs Collection Runner / Newman, so make sure you understand how they work before using!

Setting

pm.variables.set('myVariable', MY_VALUE); 

Getting

pm.variables.get('myVariable', MY_VALUE); 

Removing

Local variables are automatically removed once the tests have been executed / collection run finished.

like image 178
Valentin Despa Avatar answered Jan 07 '23 15:01

Valentin Despa