Skip to content
Docs

Create one or more environment variables

POSThttps://api.vercel.com/v10/projects/{idOrName}/env
Create one or more environment variables for a project by passing its key, value, type and target and by specifying the project by either passing the project id or name in the URL. If you include upsert=true as a query parameter, a new environment variable will not be created if it already exists but, the existing variable's value will be updated.
https://api.vercel.com/v10/projects/{idOrName}/env
const response = await fetch('https://api.vercel.com/v10/projects/idOrName/env?upsert=string&teamId=string&slug=string', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"key": "API_URL",
"value": "https://api.vercel.com",
"type": "plain",
"target": [],
"gitBranch": "feature-1",
"comment": "database connection string for production",
"customEnvironmentIds": []
}),
});
const data = await response.json();
console.log(data);
Response
{
"created": {
"comment": "string",
"configurationId": "example_id",
"contentHint": {
"storeId": "example_id",
"type": "redis-url"
},
"createdAt": "123",
"createdBy": "string",
"customEnvironmentIds": [],
"decrypted": "false",
"edgeConfigId": "example_id",
"edgeConfigTokenId": "example_id",
"gitBranch": "string",
"id": "icfg_1234567890",
"internalContentHint": {
"encryptedValue": "string",
"type": "flags-secret"
},
"key": "string",
"legacyValue": "string",
"sunsetSecretId": "example_id",
"target": [],
"type": "encrypted",
"updatedAt": "123",
"updatedBy": "string",
"value": "string",
"visibility": "config",
"vsmValue": "string",
"system": "false"
},
"failed": [
{
"error": {
"action": "string",
"code": "string",
"envVarId": "example_id",
"envVarKey": "string",
"gitBranch": "string",
"key": "string",
"link": "string",
"message": "string",
"project": "string",
"target": [],
"value": "string"
}
}
]
}
AuthorizationbearerToken

Default authentication mechanism

idOrNamestringRequired
The unique project identifier or the project name
upsertstringOptional
Allow override of environment variable if it already exists
teamIdstringOptional
The Team identifier to perform the request on behalf of.
slugstringOptional
The Team slug to perform the request on behalf of.
application/json
keystringRequired
The name of the environment variable
valuestringRequired
The value of the environment variable
typestringRequired
The type of environment variable
targetarrayOptional
The target environment of the environment variable
gitBranchstringOptional
If defined, the git branch of the environment variable (must have target=preview)
commentstringOptional
A comment to add context on what this environment variable is for
customEnvironmentIdsarrayOptional
The custom environment IDs associated with the environment variable
201The environment variable was created successfully
createdobjectOptional
failedarrayRequired
400One of the provided values in the request body is invalid. One of the provided values in the request query is invalid. The environment variable coudn't be created because an ongoing update env update is already happening The environment variable coudn't be created because project document is too large
401The request is not authorized.
402The account is missing a payment so payment method must be updated
403You do not have permission to access this resource. The environment variable cannot be created because it already exists
404Error
409Error
410Error
429Error
500Error