Environment variables
Extensions can interact with Netlify’s environment variables. This includes both team-level shared environment variables and site-level environment variables.
Only teams on Pro and Enterprise plans can use shared environment variables
Keep in mind that team-level shared environment variables are available for Netlify customers on Core Pro
and Core Enterprise
plans only. If your extension user is not on one these plans, the API request will fail.
Create and update environment variables
To create or update an environment variable with your extension, you can use the createOrUpdateVariable
API in your endpoint code.
For example, this endpoint creates a site environment variable:
Alternatively, you can create or update multiple environment variables with one call using createOrUpdateVariables
.
Create secret environment variables
Your extension can also create secret environment variables on Netlify.
To create a secret environment variable, set isSecret
to true
, set explicit scopes, and set an explicit value for each deploy context. The explicit deploy context values and scopes are requirements to avoid unexpected exposure.
For example, this endpoint creates a secret site environment variable set to the builds
scope and with values set for each deploy context. Note that values set for the dev
deploy context are not considered secret to support local development.
You can also use the createOrUpdateVariables
API to create multiple secret environment variables at once.
Resources
- For a reference of the different methods available to interact with Netlify’s environment variables, check out the
NetlifyExtensionClient
API docs. - To learn more about environment variables on Netlify, visit the environment variable overview in the Netlify user docs.