Skip to main content

Using Variables

Variables make your requests dynamic, reusable, and environment-independent. This guide covers everything you need to know about using variables in Nidra.

What are Variables?

Variables are placeholders that get replaced with actual values when a request is sent. They allow you to:

  • Reuse the same request across different environments
  • Avoid hardcoding sensitive values
  • Make requests dynamic based on previous responses
  • Share common values across multiple requests

Variable Syntax

Reference variables using double curly braces:

{{variableName}}

Examples

In URLs:

{{baseUrl}}/users/{{userId}}

In Headers:

Authorization: Bearer {{accessToken}}

In Request Bodies:

{
"email": "{{userEmail}}",
"environment": "{{env}}"
}

In Query Parameters:

?api_key={{apiKey}}&page={{currentPage}}

Variable Scopes

Variables exist at different scopes with different precedence levels:

1. Global Variables

Available everywhere in Nidra.

Use for: App-wide settings, defaults

2. Environment Variables

Specific to the selected environment.

Use for: Server URLs, environment-specific credentials

3. Collection Variables

Scoped to a specific collection.

Use for: Collection-wide settings, base paths

4. Conduit Variables

Temporary variables during conduit execution.

Use for: Extracted response data, intermediate values

5. Request Variables

Local to a single request (rare).

Use for: Request-specific overrides

Precedence

When the same variable name exists at multiple scopes:

Request > Conduit > Collection > Environment > Global

The most specific scope wins.

Setting Variables

In Environments

  1. Go to Environments
  2. Select or create an environment
  3. Add key-value pairs
  4. Save the environment

In Collections

  1. Open collection settings
  2. Go to the Variables tab
  3. Add variables
  4. Save

During Conduit Execution

Variables can be set dynamically:

  • Extracted from responses
  • Calculated in script steps
  • Set explicitly in variable steps

Learn about variable extraction →

Common Variable Patterns

Base URL

Most common variable:

baseUrl: https://api.example.com/v1

Used in requests:

{{baseUrl}}/users
{{baseUrl}}/posts

Authentication

Store credentials as variables:

apiKey: your-api-key-here
bearerToken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
username: admin
password: ******** (marked as secret)

Dynamic IDs

Store resource IDs for reuse:

userId: 12345
orderId: 67890
productId: abc-123

Configuration

Environment-specific settings:

timeout: 5000
retryCount: 3
debug: true

Dynamic Variables

Nidra provides built-in dynamic variables:

  • {{$timestamp}}: Current Unix timestamp
  • {{$randomInt}}: Random integer
  • {{$randomUUID}}: Random UUID
  • {{$randomEmail}}: Random email address

Example:

{
"id": "{{$randomUUID}}",
"timestamp": "{{$timestamp}}",
"email": "user-{{$randomInt}}@example.com"
}

Variable References in Assertions

Use variables in assertions to validate dynamic values:

Response field "userId" equals {{expectedUserId}}

Debugging Variables

View Active Variables

See all active variables for the current context:

  1. Open the Variables panel
  2. Select the active environment
  3. View resolved values

Variable Console

The variable console shows:

  • Which variables are set
  • Their current values
  • Which scope they come from
  • Any unresolved variables (showing as {{varName}})

Common Issues

Unresolved Variables

If a variable shows as {{varName}} in the response:

  • Check the variable name spelling
  • Verify the variable exists in the active scope
  • Ensure the environment is selected
  • Check variable precedence

Best Practices

  • Use descriptive names: baseUrl not url, userEmail not e
  • Follow naming conventions: camelCase or snake_case consistently
  • Mark secrets appropriately: Hide sensitive values
  • Don't duplicate: Use parent environments for shared variables
  • Document your variables: Add descriptions in environments
  • Keep it DRY: Don't repeat values, use variables instead

Advanced Patterns

Chained Variables

Variables can reference other variables:

domain: example.com
apiUrl: https://api.{{domain}}
authUrl: https://auth.{{domain}}

Conditional Variables

Different values based on environment:

Development:
baseUrl: http://localhost:3000
debug: true

Production:
baseUrl: https://api.example.com
debug: false

Computed Values

Use conduit steps to compute values:

Extract "userId" from response
Set "userProfileUrl" to "{{baseUrl}}/users/{{userId}}/profile"

Real-World Example

Environment: Production

baseUrl: https://api.example.com/v2
apiKey: prod_1234567890
tenantId: acme-corp
timeout: 10000

Request: Get User

GET {{baseUrl}}/tenants/{{tenantId}}/users/{{userId}}

Headers:
X-API-Key: {{apiKey}}
Accept: application/json

The request resolves to:

GET https://api.example.com/v2/tenants/acme-corp/users/42

Headers:
X-API-Key: prod_1234567890
Accept: application/json

Next Steps