Get Environment Variables
Returns the environment variables configured in the project.
Required permissions
Reading requires project.env.read on project:<project-id>. Updating requires project.env.update on the same project. Seeing the values also requires project.env.secrets.read on the project; without it, the response carries names only (see Protected values). owner has full access, and whoever creates a project receives all three permissions on it; assistant, member, and organization API Keys need the specific scope. Values may be sensitive and must not be logged.
GET /v1/project/:id/envsRate limit: 50 requests per minute (counted per source IP).
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Project ID |
Headers
| Header | Required | Description |
|---|---|---|
x-api-key or Authorization | Yes | Organization API Key or user token |
x-organization-id | With a user token | Active project organization. Not needed with an organization API key |
Content-Type: application/json | Conditional | Required only for PATCH calls |
Response
Environment variable values can include sensitive data. With project.env.secrets.read, the response returns every value in plain text, so treat it as sensitive. Without that permission, every variable comes back masked, as in the example below.
{
"status": "success",
"message": "get envs with success",
"data": [
{
"name": "DATABASE_URL",
"value": "",
"masked": true,
"restricted": true
},
{
"name": "NODE_ENV",
"value": "",
"masked": true,
"restricted": true
}
]
}Protected values
A variable's name does not tell what it holds, so no value goes out without project.env.secrets.read on the project:
- the list returns each variable with
value: "",masked: true, andrestricted: true; - with
?masked=true, the response is the same; - reading any variable by name returns
403, as shown below; - updating is still possible with
project.env.update, without knowing the value (see Keep masked values).
In the Console, this permission is shown as View environment values.
Get one variable
GET /v1/project/:id/envs/:nameRequires project.env.read and project.env.secrets.read. Returns 200 with data: { "name": "...", "value": "..." }, and 404 with code: "PROJECT_ENV_NOT_FOUND" when the variable does not exist. Without project.env.secrets.read:
{
"status": "failed",
"code": "PROJECT_ENV_SECRET_RESTRICTED",
"message": "insufficient organization permission",
"required_permission": { "resource": "project", "action": "project.env.secrets.read" },
"hint": "Your organization permissions do not include project.env.secrets.read. Ask the organization owner to grant it.",
"docs_url": "https://docs.zenifra.com/pt/docs/organizations/api-keys#catálogo-completo-de-scopes"
}Update Environment Variables
Updates the environment variables of the project.
The list you send replaces all current variables: variables left out are removed. To change a single variable, read the list with GET, adjust the item, and send the full list. The change restarts the application instances and adds an entry to the deployment history.
PATCH /v1/project/:id/envsRate limit: 20 requests per minute (counted per source IP).
Path Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | Project ID |
Body
| Field | Type | Required | Description |
|---|---|---|---|
envs | array | Yes | Array of objects with name and value (maximum 50 variables, each name up to 120 characters, each value up to 32760 characters). The value can be empty ("") |
Keep masked values
An entry sent back exactly as it came in the masked list (value: "" and masked: true) keeps the variable's current value. The same applies to { "name": "...", "keep": true }, without value. If the entry carries a new value, the new value is saved. This way, someone who cannot see a secret can still save the full list without erasing it. To clear a value on purpose, send value: "" without masked.
Name rules
The name must start with a letter, _, -, or . and can contain only unaccented letters, numbers, _, -, and ., with no spaces. Valid examples: NODE_ENV, api.timeout, _INTERNAL_FLAG. Invalid examples: 1TOKEN (starts with a number), MY VAR (contains a space), and PREÇO (contains an accent).
Example
{
"envs": [
{
"name": "DATABASE_URL",
"value": "postgres://user:pass@host:5432/db"
},
{
"name": "API_KEY",
"value": "new-api-key"
}
]
}Response
{
"status": "success",
"message": "updated with success"
}Errors
| Status | When it happens |
|---|---|
400 | Invalid body (for example, a name outside the rules or above the limits on this page) |
400 | PROJECT_ENV_KEEP_UNKNOWN: an entry marked to keep its value (masked or keep) does not exist in the project |
404 | Project not found |
409 | PROJECT_STATE_CONFLICT: the application does not have a running version yet (for example, a Git project before its first build) or is momentarily unavailable. Try again after the first deploy |
422 | PROJECT_OPERATION_NOT_SUPPORTED: the project type does not use environment variables (databases and managed services) |
Examples
Get Environment Variables
curl -X GET "https://api.zenifra.com/v1/project/507f1f77bcf86cd799439011/envs" \
-H "x-api-key: your-api-key" \
-H "x-organization-id: your-organization-id"Update Environment Variables
curl -X PATCH "https://api.zenifra.com/v1/project/507f1f77bcf86cd799439011/envs" \
-H "x-api-key: your-api-key" \
-H "x-organization-id: your-organization-id" \
-H "Content-Type: application/json" \
-d '{"envs": [{"name": "NODE_ENV", "value": "production"}]}'Python
import requests
API_KEY = "your-api-key"
ORGANIZATION_ID = "your-organization-id"
PROJECT_ID = "507f1f77bcf86cd799439011"
headers = {"x-api-key": API_KEY, "x-organization-id": ORGANIZATION_ID}
# Get environment variables
envs = requests.get(
f"https://api.zenifra.com/v1/project/{PROJECT_ID}/envs",
headers=headers
).json()
print(envs)
# Update environment variables
requests.patch(
f"https://api.zenifra.com/v1/project/{PROJECT_ID}/envs",
headers=headers,
json={
"envs": [
{"name": "NODE_ENV", "value": "production"},
{"name": "DATABASE_URL", "value": "postgres://user:pass@host:5432/db"}
]
}
)Limits
- Maximum of 50 environment variables per project
- Each name can have up to 120 characters and must follow the name rules
- Each value can have up to 32760 characters
Last updated on
Project alerts
Read and enable email alerts for a Zenifra application, database, or Valkey service through the API, with the CPU, memory, and storage thresholds it returns.
Storage
Increase your project's storage via the Zenifra API, from 1 to 250 GB, and read current usage in bytes, with contract rules, the legacy Free plan, and errors.