Authentication
n8n-gitops requires API credentials to connect to your n8n instance.
Authentication Methods
Authentication credentials are resolved in this priority order:
- CLI flags:
--api-urland--api-key - Environment variables:
N8N_API_URLandN8N_API_KEY .n8n-authfile in repository root
Method 1: CLI Flags
Pass credentials directly via command-line flags:
n8n-gitops export \
--api-url https://your-n8n-instance.com \
--api-key your-api-key-here
This method overrides all other authentication sources.
Method 2: Environment Variables
Set environment variables:
export N8N_API_URL=https://your-n8n-instance.com
export N8N_API_KEY=your-api-key-here
n8n-gitops export
Or use a .env file with a tool like direnv:
# .env
N8N_API_URL=https://your-n8n-instance.com
N8N_API_KEY=your-api-key-here
Method 3: .n8n-auth File (Recommended)
Create a .n8n-auth file in your repository root:
cp .n8n-auth.example .n8n-auth
Edit .n8n-auth:
N8N_API_URL=https://your-n8n-instance.com
N8N_API_KEY=your-api-key-here
Important: The .n8n-auth file is gitignored by default to prevent accidentally committing secrets.
.n8n-auth File Format
The file supports:
- Simple
KEY=VALUEformat - Comments with
# - Empty lines
- Values with or without quotes
Example:
# n8n API Configuration
N8N_API_URL=https://your-n8n-instance.com
N8N_API_KEY="your-api-key-here"
# Optional: Custom timeout
# TIMEOUT=60
Getting Your API Key
To get your n8n API key:
- Log in to your n8n instance
- Go to Settings → API
- Create a new API key
- Copy the key (you won't be able to see it again)
Security Best Practices
- Never commit
.n8n-authto version control - Use environment variables in CI/CD pipelines
- Rotate API keys regularly
- Use separate API keys for different environments (dev, staging, prod)
- Limit API key permissions if your n8n version supports it
CI/CD Usage
For CI/CD pipelines, use environment variables:
# GitHub Actions example
- name: Deploy workflows
run: n8n-gitops deploy --git-ref ${{ github.ref }}
env:
N8N_API_URL: ${{ secrets.N8N_API_URL }}
N8N_API_KEY: ${{ secrets.N8N_API_KEY }}
# GitLab CI example
deploy:
script:
- n8n-gitops deploy --git-ref $CI_COMMIT_TAG
variables:
N8N_API_URL: $N8N_API_URL
N8N_API_KEY: $N8N_API_KEY
Troubleshooting
Error: Missing credentials
If you see this error:
Error: Missing N8N_API_URL or N8N_API_KEY
Check that:
- Your
.n8n-authfile exists and is in the repository root - The file has the correct format (KEY=VALUE)
- Both
N8N_API_URLandN8N_API_KEYare set
Error: Authentication failed
If you see authentication errors:
- Verify your API key is correct
- Check that your n8n instance URL is accessible
- Ensure the API key hasn't been revoked
- Test the API key manually with curl:
curl 'https://your-n8n-instance.com/api/v1/workflows' \
--header 'X-N8N-API-KEY: your-api-key-here'