Using Secrets in Routes
Learn how to inject encrypted secrets into your route requests using KnoxCall’s template system.Template Syntax
Secrets are injected using template syntax in your route configuration.Basic Format
{{- Opening delimitersecret:- Type identifier (required)SECRET_NAME- Your secret’s name}}- Closing delimiter
Example
If you have a secret namedstripe_prod_key:
Injecting Secrets in Headers
The most common use case - adding secrets to HTTP headers.Step 1: Edit Route
- Go to Routes
- Click on your route
- Scroll to Inject Headers section
Step 2: Add Header with Secret
Click Add Header or edit the JSON directly:Step 3: Save
Click Save Changes ✅ All requests through this route now have the secret injected!Common Header Patterns
Bearer Token
API Key Header
Basic Authentication
username:password
Custom Headers
Injecting Secrets in Body
For POST, PUT, PATCH requests, inject secrets into the request body.Step 1: Edit Route
- Go to route
- Scroll to Inject Body section
Step 2: Add Body with Secrets
Step 3: Save
✅ Body now includes decrypted secret value!Common Body Patterns
Simple API Key
Nested Objects
Database Connection
Multiple Secrets
Multiple Secrets in One Route
You can use multiple different secrets in the same route configuration.Example: Multi-Service Integration
Route:notification-service
Headers:
Environment-Specific Secrets
Use different secrets per environment (dev, staging, production).Setup
Create environment-specific secrets:-
Production:
-
Staging:
-
Development:
Configure Route Per Environment
Base environment (production):How to Set Up
- Go to route → Environment Overrides tab
- Select “staging”
- Edit Inject Headers:
- Save
- Repeat for “development”
- Production uses:
stripe_prod_key - Staging uses:
stripe_staging_key - Development uses:
stripe_dev_key
Method-Specific Secrets
Different secrets for different HTTP methods on the same route.Example Scenario
Route handles both GET (read) and POST (write) to same API:- GET needs read-only key
- POST needs full-access key
Setup
GET method config:- GET requests use read-only key
- POST requests use full-access key
Secret Resolution Order
When multiple environments and methods are involved, KnoxCall resolves secrets in this order:- Method-specific environment override
- Environment override (if method not specified)
- Base route configuration
Example
Template Syntax Rules
✅ Correct Syntax
- Double curly braces:
{{and}} - Prefix:
secret: - No spaces inside braces
- Lowercase with underscores for secret names
❌ Common Mistakes
Real-World Examples
Example 1: Stripe Payments
Secret:Example 2: SendGrid Email
Secret:Example 3: Database Access
Secret:Example 4: PrintNode Printing
Secret:Example 5: Multi-Service Orchestration
Secrets:Combining Secrets with Other Templates
You can combine secrets with other template variables (coming soon):{{secret:name}}- Inject secrets
{{header:name}}- Pass through headers{{env:name}}- Environment variables{{uuid}}- Generate UUID
Security Considerations
What Gets Logged
In KnoxCall logs:- Template syntax shown:
{{secret:stripe_key}} - Actual value: Never logged
Secret Transmission
Flow:Best Practices
✅ Do:- Use secrets for all sensitive values
- Separate secrets per environment
- Rotate secrets regularly
- Use descriptive secret names
- Document what each secret is for
- Hardcode API keys in route configs
- Use production secrets in development
- Share secrets via email or chat
- Commit secrets to git
- Use generic names like “key” or “secret”
Troubleshooting
Secret Not Replacing
Symptom: Backend receives{{secret:stripe_key}} literally.
Causes:
- Syntax error in template
- Secret doesn’t exist
- Secret name typo
- Check template syntax:
{{secret:name}} - Verify secret exists: Resources → Secrets
- Check spelling matches exactly (case-sensitive)
- Look at logs for error messages
Wrong Value Injected
Symptom: Wrong API key being used. Causes:- Using wrong environment
- Wrong secret name
- Secret not configured for environment
- Check which environment request is using
- Verify environment override has correct secret
- Check secret name spelling
Secret Not Found Error
Error:Secret 'api_key' not found
Solution:
- Go to Resources → Secrets
- Check secret exists
- Verify name matches template exactly
- Check no typos:
api_keyvsapi_key_
Value Not Decrypting
Symptom: Encrypted value sent instead of plaintext. Cause: KnoxCall internal error (very rare). Solution:- Check KnoxCall status
- Try creating new secret version
- Contact support if persists
Testing Secret Injection
Test Endpoint
Use a test endpoint to verify secret injection:-
Create test route:
- Target:
https://httpbin.org/anything - Method: POST
- Target:
-
Add secret in header:
-
Make request:
-
Check response:
Quick Reference
| Use Case | Template Syntax | Example |
|---|---|---|
| Header | {{secret:name}} | "Authorization": "Bearer {{secret:api_key}}" |
| Body | {{secret:name}} | "api_key": "{{secret:api_key}}" |
| Multiple | Multiple templates | {{secret:key1}} and {{secret:key2}} |
| Environment | Different secret per env | Production: {{secret:prod_key}} |
Next Steps
Creating Secrets
How to create and manage secrets
Secrets Overview
Complete secrets guide
Environment Basics
Environment-specific secrets
OAuth2 Flow
Auto-refreshing OAuth2 tokens
Pro Tip: Always test secret injection with a test endpoint (like httpbin.org) before using in production. This lets you verify the actual decrypted value is correct.