Variables
A variable is a value that can be applied on certain parameters of a request. Instead of typing the same value repeatedly across many requests, you can use a variable for that, saving effort if you need to change this value - only change the variable's value where it is defined, in a single place.
There are two classes of variables: collection variables and environment variables.
Collection variables
Collection variables are available to be used in every request of the collection. To view them, click on the collection Variables in the left panel.
Environment variables
Environment variables are also available for every request of the collection, however, they will only be considered for usage if the environment is active / current. To view them, click on the environment in the left panel.
Editing variables
You can add a new variable by clicking on the "+
" button, at the top left. To edit a variable, double-click a field of the variable on the grid and enter text.
To move your variables, click, hold and drag the "::
" symbol at the left of the row and drag to where you want to place your variable.
To remove a variable, click on the "X
" mark of its row, at the right, on the grid.
A variable can be enabled or disabled. Only enabled variables will be considered for resolution.
Variables marked as secret allow for better control of sensitive data when exporting your collection or environment. Read more on the Export and Import page.
How to use a variable
Variables can be used for the following fields of a request:
- URL
- HTTP headers' names and values
- Custom auth parameters
- HTTP request
- Raw body: content
- File body: file source path
- Form URL encoded body: parameters' names and values
- Multipart form data body: parameters' names and values, including file source paths
- GraphQL body: variables content
- WebSocket message
- Raw body: content
- File body: file source path
- HTTP repeater
- Raw input data
- Input data file source path
To use a variable, type {{VariableName}}
on the field you want to apply it.
For example: if a request URL is {{BaseUrl}}/index.html
and there is a variable named BaseUrl
with the value http://www.pudim.com.br
, when sending the request, the resolved URL will be http://www.pudim.com.br/index.html
.
For request URLs, you can hover over the URL text box and preview the resolved URL.
The image below shows how to use a variable in a raw body's content. In it, {{VariableName}}
will appear highlighted in yellow.
Variable resolution logic
The resolution logic is as follows:
- Only enabled variables are considered.
- Collection variables will be joined with the current environment variables. If no environment is active, then only collection variables.
- Environment variables have precedence - if there are two variables declared with the same name both in the collection and in the environment, the environment variable will be preferred.
- Every request field that allows the usage of variables will be checked for whether it has a variable template, for example,
{{VARIABLE_NAME}}
. If the template is found and there is an enabled variable for it, the variable's value will be applied. Otherwise, the template will remain in the text field.
Predefined variables
Predefined variables provide random values or of the present moment, that can be used in your requests.
Variable template | Example value |
---|---|
{{ $guid }} | 7cc34984-e276-4cad-948d-25a1d4686b78 |
{{ $now }} | 2024-05-28T16:33:30.5687994-03:00 |
{{ $today }} | 2024-05-28 |
{{ $timestamp }} | 1728309929 |
{{ $randomBirthDate }} | 2015-04-22 |
{{ $randomBirthDateOver18 }} | 1966-03-17 |
{{ $randomInt }} | 455659758 |
{{ $randomQuantity }} | 34 (number between 1 and 1000) |
{{ $randomFullName }} | (see below) |
{{ $randomManFullName }} | Ricardo Torres de La Cruz |
{{ $randomWomanFullName }} | Viviana Fermi Veronesi |
{{ $randomFirstName }} | (see below) |
{{ $randomManFirstName }} | Ricardo |
{{ $randomWomanFirstName }} | Viviana |
{{ $randomLastName }} | Fermi |
{{ $randomCPF }} | 123.456.789-09 |
{{ $randomCPFDigitsOnly }} | 12345678909 |
{{ $randomCNPJ }} | 31.616.591/0001-50 |
{{ $randomCNPJDigitsOnly }} | 31616591000150 |
* CPF, CNPJ: Brazilian document numbers.
These variables can be applied both inside requests:
And inside collection and environments variables, to generate values:
Capturing response into variables
Read more here.