Skip to main content

Global Variables

What are Global Variables?

Global variables differ from environment variables in their scope of application. Global variables are not influenced by the current environment and will remain active across the entire project.

Global and environment variables use the same syntax for referencing: {{variable name}}

image.png

Management of Global Variables

There are two ways:

Manually manage global variables by adding, modifying, or deleting them through the pop-up window.

image.png

tip

After configuring a variable, click the save button to store it in the cloud; otherwise, it will be lost upon page refresh.

image.png

Maintain through scripts. Add scripts through post-execution operations (for details on post-execution operations, please refer to the specific introduction in the relevant documentation).

Define a global variable num with a value of 1000

pm.globals.set("num", "1000"); // Set a global variable

image.png Similarly, you can modify or delete global variables using scripts.

We can delete global variables through scripts.

pm.globals.set("num", "2000"); // Modify or reset the value of an existing variable
pm.globals.delete("num"); // Delete a global variable
pm.globals.clear(); // Clear global variables

Scope of Global Variables

Global variables are valid throughout the entire current project.

Priority of Global Variables and Environment Variables

Global variables have a lower priority than environment variables.

When both environment and global variables define the same variable, such as num, the environment variable's value takes precedence.