Use API Client environments

GET {{ baseUrl }}/users/{{ userId }}
Authorization: Bearer {{ apiKey }}

Variables resolve in URLs, headers, request bodies, authentication fields, and scripts.

Create an environment#

Open collection settings, choose Environment Variables, select Add Environment, name it, choose a color, and add key-value pairs.

Switch the active environment#

Use the globe icon in the request header to open the environment picker. Only one environment is active at a time. Select No Environment to clear the selection.

Collection and workspace environments#

  • Collection — Belongs to one OpenAPI document and travels with it when exported.
  • Workspace — Available to every collection in the current workspace and excluded from exported documents.

The two levels merge at request time. A collection variable overrides a workspace variable with the same name.

Variable scopes#

Scope Where it lives Lifetime
Local One request execution Cleared after the request runs
Environment Active environment Persists with the collection or workspace
Collection Current collection Shared by its requests
Global Workspace Available everywhere

When a name exists at several scopes, resolution order is local, environment, collection, then global.

Use variables in scripts#

Pre-request and post-response scripts use the same stores through the Postman-compatible pm API.

const token = pm.environment.get('apiKey')
pm.environment.set('timestamp', new Date().toISOString())
pm.collectionVariables.get('baseUrl')
pm.globals.set('requestId', crypto.randomUUID())

You can also define environments in an OpenAPI document with x-scalar-environments.

Updated

Was this page helpful?