Testnizer

Variables reference

Complete reference for variable types, scope hierarchy, and dynamic value functions in Testnizer.

Variables let you parameterize requests so the same collection works across environments, users, and test runs without manual edits.


Variable scope hierarchy

Testnizer resolves variables using four scopes. When the same key exists in multiple scopes, the more specific scope wins. From lowest to highest priority:

  1. Global variables — apply across the entire workspace and every project inside it. Set and read at runtime with pm.globals.set() / pm.globals.get(). Useful for values that never differ between environments, such as a shared API version string.

  2. Collection variables — scoped to a single project (Testnizer uses “collection” as the script-API term for the project scope). Set with pm.collectionVariables.set(). Good for base paths and shared test data that belong to the project but should not vary per environment.

  3. Environment variables — pulled from the currently active environment. See Environments & variables for how to create and manage environments. These are the most common place to put values that differ between staging and production.

  4. Local variables — live only for the duration of a single request execution. Set with pm.variables.set() in a pre-request or test script. Cleared automatically once the response is received.

Resolution example. Suppose baseUrl is defined in three places:

ScopeValue
Globalhttps://prod.api.example.com
Collectionhttps://staging.api.example.com
Environment (active: Staging)https://staging-v2.api.example.com

When a request uses {{baseUrl}}, Testnizer resolves it to https://staging-v2.api.example.com because the environment scope has the highest priority among the three.


{{variable}} syntax

Double curly braces work in every request field:

  • URLhttps://{{baseUrl}}/{{version}}/users
  • Query parameters — value column of any query param row
  • Headers — both name and value columns
  • Request body — raw JSON, form fields, GraphQL variables, and XML body
  • Pre-request and test scripts — use the pm.* API instead (see below)

Testnizer resolves all placeholders before the request is sent. If a variable is not defined in any scope, the placeholder is left as-is — the literal text {{variableName}} is sent. Undefined variables are highlighted in orange in the URL bar so you can spot them before clicking Send.

Nested substitution works. A URL such as:

https://{{baseUrl}}/{{version}}/users

resolves both baseUrl and version independently. Variables cannot reference each other (circular or chained resolution is not supported).

Managing variables in scripts

Pre-request and test scripts use the pm API to read and write variables at runtime:

// Read a value from the active environment
const token = pm.environment.get('accessToken')

// Write a value extracted from the response
const body = pm.response.json()
pm.environment.set('userId', body.data.id)

// Write a local variable that lasts only for this execution
pm.variables.set('requestId', '12345')

// Collection-level (project-level) read/write
pm.collectionVariables.set('sharedCounter', 1)

Dynamic values

Dynamic value functions generate a fresh value each time the request is sent. Use them with the {{$functionName}} syntax directly in URLs, headers, or body fields.

FunctionReturnsExample output
{{$randomInt}}Random integer 0–1000742
{{$randomInt(1,100)}}Random integer in given range37
{{$randomFloat}}Random float 0.0–1.00.4821
{{$randomBoolean}}true or falsetrue
{{$randomUUID}}Version 4 UUIDf47ac10b-58cc-4372-a567-0e02b2c3d479
{{$timestamp}}Unix epoch in seconds1715000000
{{$isoTimestamp}}ISO 8601 date-time2024-05-06T14:30:00.000Z
{{$randomEmail}}Synthetic email addressalice.smith@example.com
{{$randomFirstName}}First nameMarcus
{{$randomLastName}}Last nameChen
{{$randomFullName}}Full nameSarah Okafor
{{$randomPhoneNumber}}Phone number+1-555-0147
{{$randomAlphaNumeric}}8-character alphanumeric stringx4Kp9mQr
{{$randomHexColor}}Hex color code#a3c4e8
{{$randomIP}}IPv4 address192.168.14.23
{{$randomLoremWord}}Single lorem ipsum wordpariatur
{{$randomLoremParagraph}}Lorem ipsum paragraphLorem ipsum dolor sit amet…

Dynamic values in scripts

{{$functionName}} syntax is not evaluated inside script code. If you write the following, you get the literal string {{$randomUUID}}, not a UUID:

// WRONG — $randomUUID is not expanded inside a script string
pm.variables.set('traceId', '{{$randomUUID}}')

Generate the value with standard JavaScript instead:

// CORRECT — use the crypto module available in the sandbox
const { randomUUID } = require('crypto')
pm.variables.set('traceId', randomUUID())

// Or for a random integer:
const requestId = Math.floor(Math.random() * 1000)
pm.variables.set('requestId', requestId)

Dynamic values are intended for fields that Testnizer substitutes before sending — URL, headers, query parameters, and body text.


Secrets and sensitive variables

Any environment variable can be marked as secret when it is created or edited. Secret variables are stored through electron-store backed by the OS keychain on macOS and the Windows Credential Manager on Windows.

Behavior of secret variables:

  • The value is masked with asterisks in the Environments panel, the console, and the request history viewer.
  • pm.environment.get('secretKey') returns the real value inside scripts so you can use it in Authorization headers.
  • pm.environment.toObject() returns an object where secret keys are replaced with "***". Do not rely on this method to read secret values.
  • Secret values are never written to exported collection files. If you export a collection that references a secret variable, the export contains the variable name only.

For guidance on creating and organizing environments, see Environments & variables.