How to create custom variables and secrets on n8n
Custom variables and secrets in n8n are created through the Settings menu by navigating to Environment Variables section. Variables store reusable values across workflows, while secrets store sensitive data like API keys securely.
Prerequisites
- n8n instance installed and running
- Admin access to n8n settings
- Basic understanding of n8n workflows
- Knowledge of environment variables
Step-by-Step Instructions
Access n8n Settings
Navigate to Environment Variables
Create a New Variable
API_BASE_URL or DEFAULT_EMAIL). In the Value field, input the actual value you want to store. Leave the Type as 'Variable' for non-sensitive data.Create a Secret Variable
API_SECRET_KEY). Change the Type dropdown from 'Variable' to 'Secret'. Enter the sensitive value in the Value field. Secrets will be masked in the interface and encrypted in storage.Configure Variable Scope
Use Variables in Workflows
${{$env.VARIABLE_NAME}}. For example, to use an API key secret, enter ${{$env.API_SECRET_KEY}} in the authentication field of an HTTP Request node. The variable will be automatically resolved during workflow execution.Test and Validate Variables
Manage and Update Variables
Common Issues & Troubleshooting
Environment Variables menu is not visible in Settings
Ensure you have admin privileges in n8n. For self-hosted instances, check that your user account has the necessary permissions. In n8n cloud, verify your subscription plan includes environment variables feature.
Variable not resolving in workflow execution
Verify the variable name spelling matches exactly (case-sensitive). Ensure you're using the correct syntax ${{$env.VARIABLE_NAME}} and that the variable scope includes your current workflow.
Cannot save or create new variables
Check your n8n instance has sufficient disk space and memory. For Docker installations, ensure the container has write permissions. Restart your n8n instance if the issue persists.
Secret values showing as undefined or empty
Ensure the secret was saved properly and contains a value. Check that your n8n version supports secrets (v0.190.0+). For self-hosted instances, verify the encryption key is properly configured in your environment.