Ana içeriğe geç
Versiyon: 1.0.6

Environments

Environments allow you to run the same API tests against different servers (development, staging, production) without modifying requests.

Coming Soon

This feature is currently in development.

Environment Basics​

What is an Environment?​

An environment is a set of variables that define the context for API requests:

EnvironmentBase URLPurpose
Developmenthttp://localhost:3000Local testing
Staginghttps://staging-api.example.comPre-production
Productionhttps://api.example.comLive system

Variable Types​

TypeScopeUse Case
EnvironmentPer environmentURLs, API keys
CollectionPer collectionShared values
GlobalAll collectionsCommon settings
LocalCurrent sessionTemporary values

Managing Environments​

Creating Environments​

  1. Navigate to Environments
  2. Click New Environment
  3. Add variables:
    • Variable name
    • Initial value
    • Current value
    • Type (text, secret)

Environment Structure​

{
"name": "Staging",
"values": [
{
"key": "baseUrl",
"value": "https://staging-api.example.com",
"type": "text"
},
{
"key": "apiKey",
"value": "stg_key_xxxxx",
"type": "secret"
},
{
"key": "timeout",
"value": "5000",
"type": "text"
}
]
}

Using Variables​

In Requests​

Reference variables with double curly braces:

URL: {{baseUrl}}/api/v1/users
Header: Authorization: Bearer {{accessToken}}
Body: {"email": "{{testEmail}}"}

In Scripts​

Access and modify variables programmatically:

// Get variable
const baseUrl = pm.environment.get('baseUrl');

// Set variable
pm.environment.set('accessToken', response.token);

// Clear variable
pm.environment.unset('tempValue');

Variable Resolution​

Priority order (highest to lowest):

  1. Local variables
  2. Collection variables
  3. Environment variables
  4. Global variables

Secret Management​

Sensitive Data​

Handle secrets securely:

PracticeDescription
Type: SecretMask values in UI
No ExportExclude from exports
Vault IntegrationExternal secret storage
RotationRegular key rotation

Best Practices​

  • Never commit secrets to version control
  • Use secret type for sensitive values
  • Rotate credentials regularly
  • Use different keys per environment

Environment Switching​

Quick Switch​

Toggle between environments:

  • Dropdown in header
  • Keyboard shortcut
  • Script-based switching

Dynamic Environments​

Switch environments programmatically:

// Set active environment based on condition
if (pm.variables.get('region') === 'eu') {
pm.environment.set('baseUrl', 'https://eu-api.example.com');
} else {
pm.environment.set('baseUrl', 'https://us-api.example.com');
}

Common Variables​

Standard Variables​

VariableExamplePurpose
baseUrlhttps://api.example.comAPI base URL
apiVersionv1API version
apiKeykey_xxxxxAPI authentication
accessTokenjwt_tokenBearer token
timeout5000Request timeout

Dynamic Variables​

Built-in dynamic values:

VariableDescriptionExample
{{$timestamp}}Current timestamp1699876543
{{$randomInt}}Random integer42
{{$guid}}Random UUIDa1b2c3d4-...
{{$randomEmail}}Random email[email protected]

Environment Templates​

Creating Templates​

Define reusable environment structures:

{
"template": "Standard API",
"variables": [
{ "key": "baseUrl", "required": true },
{ "key": "apiKey", "required": true, "type": "secret" },
{ "key": "timeout", "default": "5000" }
]
}

Sharing Templates​

  • Export template structure
  • Share with team
  • Create environments from templates

CI/CD Integration​

Environment Files​

Use environment files in pipelines:

# GitHub Actions example
- name: Run API Tests
run: smartapi run collection.json -e staging.json
env:
API_KEY: ${{ secrets.STAGING_API_KEY }}

Environment Variables​

Map CI/CD secrets to SmartAPI variables:

CI/CD VariableSmartAPI Variable
$API_KEY{{apiKey}}
$BASE_URL{{baseUrl}}
$AUTH_TOKEN{{accessToken}}

Best Practices​

Naming Conventions​

  • Use camelCase for variable names
  • Prefix environment-specific vars
  • Document variable purposes

Security​

  • Never use production secrets locally
  • Rotate keys regularly
  • Audit environment access

Maintenance​

  • Review unused variables
  • Keep environments in sync
  • Document environment purposes