Create an environment variable via API
This method allows you to create a new environment variable for a project.
URL
/projects/<permalink>/environment_variables
- Replace
<permalink>with the permalink of the project.
HTTP Method
POST
Supported Parameters
name(required) - The variable name. Must start with a letter and contain only letters, numbers, and underscoresvalue(required) - The variable value. Will be encrypted at restlocked(optional) - Lock the variable to prevent changes. Default:false. Once locked, cannot be unlockedbuild_pipeline(optional) - Make the variable available in the Build Pipeline. Default:true
Example cURL request
curl -H "Content-type: application/json" \
-H "Accept: application/json" \
--user your-email@example.com:your-api-key \
-X POST \
-d '{ \
"environment_variable": { \
"name": "API_KEY", \
"value": "secret_value_here", \
"locked": false, \
"build_pipeline": true \
} \
}' \
https://your-account.deployhq.com/projects/your-project/environment_variables
Example response
{
"identifier": 125,
"name": "API_KEY",
"masked_value": "••••••••",
"locked": false,
"build_pipeline": true,
"created_at": "2025-01-27T12:30:00.000Z",
"updated_at": "2025-01-27T12:30:00.000Z"
}
Notes
- Variable names can be lowercase, uppercase, or mixed case (e.g.,
database_url,DATABASE_URL,DatabaseUrl) - Values are always encrypted and never visible after creation
- Locked variables provide an extra layer of security as their values cannot be viewed or changed once locked