Create Environment Variable
Endpoint
POST /apiops/projects/{projectName}/environmentVariables/{name}/
Authentication
Requires a Personal API Access Token.
Header
Authorization: Bearer YOUR_TOKEN
Request
Headers
| Header | Value | Required |
|---|---|---|
| Authorization | Bearer {token} | Yes |
| Content-Type | application/json | Yes |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| projectName | string | Yes | Project name (can be "admin" for admin project) |
| name | string | Yes | Environment variable name (unique identifier) |
Request Body
Full JSON Body Example - Global Environment Variable
{
"name": "API_KEY",
"description": "API Key for external service",
"global": true,
"globalValue": "secret-api-key-12345",
"globalVisible": false,
"environmentValueList": null
}
Full JSON Body Example - Environment-Specific Variable
{
"name": "API_BASE_URL",
"description": "Base URL for API calls",
"global": false,
"globalValue": null,
"globalVisible": true,
"environmentValueList": [
{
"environmentName": "production",
"value": "https://api.production.example.com",
"visible": true
},
{
"environmentName": "staging",
"value": "https://api.staging.example.com",
"visible": true
},
{
"environmentName": "development",
"value": "https://api.dev.example.com",
"visible": true
}
]
}
Full JSON Body Example - Environment-Specific with Secret Values
{
"name": "DATABASE_PASSWORD",
"description": "Database password",
"global": false,
"globalValue": null,
"globalVisible": true,
"environmentValueList": [
{
"environmentName": "production",
"value": "prod-secret-password",
"visible": false
},
{
"environmentName": "staging",
"value": "staging-secret-password",
"visible": false
}
]
}
Request Body Fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| name | string | Yes | - | Environment variable name (should match path {name}; backend uses the path value as the identifier) |
| description | string | No | - | Environment variable description |
| global | boolean | No | false | Whether the variable is global (true) or environment-specific (false) |
| globalValue | string|null | No | null | Global value (required if global=true) |
| globalVisible | boolean | No | true | Whether the global value may be read back. false marks it Secret — never returned by any read endpoint. Does not control encryption: every value is stored encrypted |
| environmentValueList | array[object]|null | No | null | List of environment-specific values (required if global=false). See Environment Value Object |
Environment Value Object (environmentValueList)
| Field | Type | Required | Description |
|---|---|---|---|
| environmentName | string | Yes | Environment name |
| value | string | Yes | Value for this environment |
| visible | boolean | No | false |
Notes
- Path
{name}is the identifier; backend persists the path name (bodynameshould match for clarity) namemust be unique within the project- If
global=true, provideglobalValueand setenvironmentValueList=null - If
global=false, provideenvironmentValueListwith at least one environment value - Send values as plain text — every value is encrypted before it is stored, whether or not it is marked Secret
visible=falsemarks the value Secret: it is never returned by any read endpoint (null) and never carried as plain text in an export packageglobalVisible=falsemarks the global value Secret- Values that are not Secret are returned decrypted by the read endpoints, so a CI/CD pipeline can read the real configuration
- Variable is automatically deployed to all environments after creation
Response
Success Response (200 OK) - Deployment Successful
When the environment variable is created and successfully deployed to all environments:
{
"status": "SUCCESS",
"deploymentResult": {
"success": true,
"responseTime": 1500,
"detailList": [
{
"envName": "production",
"success": true,
"detail": "Deployed successfully",
"responseTime": 450
},
{
"envName": "staging",
"success": true,
"detail": "Deployed successfully",
"responseTime": 420
}
]
}
}
Error Response (400 Bad Request)
{
"status": "FAILURE",
"resultMessage": "Environment variable name can not be empty!"
}
or
{
"status": "FAILURE",
"resultMessage": "Environment variable name in path (API_KEY) does not match name in body (API_BASE_URL)!"
}
or
{
"status": "FAILURE",
"resultMessage": "Environment variable (name: API_KEY) already exists!"
}
Common Causes
- Missing or empty path
{name}parameter - Environment variable name already exists
- Invalid global/environment-specific configuration
- Project not found or insufficient access
Deployment Failure Note
When status is "SUCCESS" but deploymentResult.success is false, the environment variable was created in the Manager but failed to deploy to one or more Gateway environments. Common causes:
- Gateway not running or not reachable (e.g., "Connection refused" on port 8091)
- Network connectivity issues between Manager and Gateway
- Environment name mismatch or environment not configured
cURL Example
Example 1: Create Global Environment Variable
curl -X POST \
"https://demo.apinizer.com/apiops/projects/MyProject/environmentVariables/API_KEY/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "API_KEY",
"description": "API Key for external service",
"global": true,
"globalValue": "secret-api-key-12345",
"globalVisible": false
}'
Example 2: Create Environment-Specific Variable
curl -X POST \
"https://demo.apinizer.com/apiops/projects/MyProject/environmentVariables/API_BASE_URL/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "API_BASE_URL",
"description": "Base URL for API calls",
"global": false,
"environmentValueList": [
{
"environmentName": "production",
"value": "https://api.production.example.com",
"visible": true
},
{
"environmentName": "staging",
"value": "https://api.staging.example.com",
"visible": true
}
]
}'
Permissions
User must have GLOBAL_SETTINGS + MANAGE permission in the project. See Environment Variables API for read vs write permissions.
Notes and Warnings
-
Name identifier:
- Variable name comes from the path parameter
{name} - Provide the same
namein the body for consistency
- Variable name comes from the path parameter
-
Global vs Environment-Specific:
global=true- Single value for all environmentsglobal=false- Different values per environment
-
Encryption and Secret Values:
- Every value is stored encrypted at rest, whether or not it is marked Secret — send plain text
- Set
visible=falseorglobalVisible=falseto mark a value Secret - Secret values are never returned (
null) by any read endpoint and never leave in an export package as plain text - Non-Secret values are returned decrypted by the read endpoints
-
Environment Names:
- Environment names must exist
- Use
environmentName(notenvironmentId)
-
Automatic Deployment:
- Variable is automatically deployed to all environments
- Deployment results are returned in the response
Related Documentation
- List Environment Variables - List all environment variables
- Update Environment Variable - Update an environment variable