In this post, we will go over Postman Variables and look into different types of variable scope that are available in Postman and how we can use them with Postman Collection.
Variables are like boxes where you can store data and reuse them when needed. For example, you can store data related to your requests like your baseURL or API key or maybe some test data that you are using for your requests like username and password. You can store all these values in Variable and give it a name that you can reuse throughout Postman.
Postman has different scopes that allow or block the usage of a variable in a particular context. For example, if you have 2 collections and you don’t want other collections to use your variable you can give it a Collection scope to add Collection level scope restriction on it.
- Global variables – available throughout the workspace and can be accessed between environments, collections, requests, and test scripts.
- Collection variables – available throughout the requests in a collection
- Environment variables – set of variables stored for each environment, for example, local development vs testing or production.
- Local variables – temporary variables, only available for a single request or collection run and are no longer available when the run is complete.
- Data variables – import variables from external files (CSV & JSON), can be used when running collections via Newman or the Collection Runner.
I hope this video helped you out, let me know if you have any questions in the comments below!