0
0
Postmantesting~5 mins

Collection variables in Postman

Choose your learning style9 modes available
Introduction

Collection variables store values you want to reuse in many requests inside a Postman collection. They help keep your tests organized and easy to update.

You want to use the same API key in multiple requests without typing it each time.
You need to change the server URL for all requests when switching between testing and production.
You want to share common data like user IDs or tokens across requests in a collection.
You want to keep your requests clean by not hardcoding values repeatedly.
You want to update a value once and have it apply to all requests using that variable.
Syntax
Postman
Use {{variable_name}} inside your request URL, headers, or body to refer to a collection variable.
Collection variables are defined at the collection level and override environment variables if names clash.
Use double curly braces {{ }} to insert the variable value in requests.
Examples
Uses the collection variable 'userId' to get a specific user.
Postman
GET https://api.example.com/users/{{userId}}
Uses the collection variable 'apiToken' in the header for authentication.
Postman
Authorization: Bearer {{apiToken}}
Uses the collection variable 'userEmail' inside the JSON body.
Postman
{ "email": "{{userEmail}}" }
Sample Program

This example shows how to use collection variables to build the request URL dynamically.

Postman
1. Define collection variable 'baseUrl' with value 'https://api.example.com'
2. Define collection variable 'userId' with value '12345'
3. Send GET request to {{baseUrl}}/users/{{userId}}
OutputSuccess
Important Notes

You can set collection variables in the Postman app under the collection settings.

Collection variables have higher priority than environment variables with the same name.

Use collection variables to avoid repeating values and to make your requests easier to maintain.

Summary

Collection variables store reusable values for all requests in a collection.

Use {{variable_name}} syntax to insert collection variables in requests.

They help keep your API testing organized and easy to update.