Authentication Troubleshooting
Common Issues
401 Unauthorized
Problem: API key authentication failed.
Possible causes:
- API key is missing or incorrectly formatted
- Key has expired
- Key has been revoked
- Incorrect header format
Solutions:
- Check header format:
# Correct format
Authorization: Key your-api-key-here
# Common mistakes
Authorization: Bearer your-api-key-here # Wrong
apikey: your-api-key-here # Wrong
Key: your-api-key-here # Wrong
- Verify key is not expired:
# Option 1: Check user info (key validation)
curl -H "Authorization: Key YOUR_KEY" \
http://your-tobealert.com:9000/api/user/me
# Option 2: Get specific key info
curl -H "Authorization: Key YOUR_KEY" \
http://your-tobealert.com:9000/api/key/YOUR_KEY_ID
# Note: API keys don't have explicit expiration in the response
# Key expiration is handled by the system internally
- Test with a new key:
- Create a fresh API key
- Test with the new key
- If it works, the old key may be revoked
403 Forbidden
Problem: API key doesn't have required permissions or license issue.
License-related causes:
- License validation failed
- License integrity check failed
- Feature not enabled in license
- License expired
Permission-related causes:
- Key lacks required scope
- User role insufficient
Solutions:
- Check license status:
# Option 1: Validate license (POST)
curl -X POST -H "Content-Type: application/json" \
http://your-tobealert.com:9000/api/license/validate
# Option 2: Get license details (GET, requires admin)
curl -H "Authorization: Key YOUR_KEY" \
http://your-tobealert.com:9000/api/license/details
# Option 3: Check user info (includes roles and permissions)
curl -H "Authorization: Key YOUR_KEY" \
http://your-tobealert.com:9000/api/user/me
- Check what permissions the key has:
# Option 1: Check user info (includes roles and scopes)
curl -H "Authorization: Key YOUR_KEY" \
http://your-tobealert.com:9000/api/user/me
# Option 2: List API keys (write:keys = your keys; admin = all keys)
curl -H "Authorization: Key YOUR_KEY" \
http://your-tobealert.com:9000/api/keys
# Option 3: Get specific key info (write:keys for your key; admin for any)
curl -H "Authorization: Key YOUR_KEY" \
http://your-tobealert.com:9000/api/key/YOUR_KEY_ID
- Ensure the key has required permissions:
write:alertsfor sending alertswrite:webhooksfor creating webhookswrite:keysto manage your API keys; globaladminto see all keys and assign Owner (same as Users and Groups)
API Key Not Working in Code
Problem: API key works with curl but not in your application.
Common issues:
- Encoding problems:
# Wrong - key might be URL encoded
headers = {"Authorization": f"Key {quote(api_key)}"}
# Correct - use raw key
headers = {"Authorization": f"Key {api_key}"}
- Trailing spaces or newlines:
# Clean the key
api_key = api_key.strip()
- Environment variable issues:
# Check if variable is set
echo $API_KEY
# In Python, check if loaded
import os
api_key = os.getenv('API_KEY')
if not api_key:
raise ValueError("API_KEY not set")
Backend Error Responses
Based on the backend implementation, here are the actual error responses:
License Errors (403)
- License integrity check failed:
{
"status": "error",
"message": "integrity check failed",
"code": 403,
"errors": null,
"requestId": "uuid-here"
}
- License validation failed:
{
"status": "error",
"message": "License validation failed",
"code": 403,
"errors": null,
"requestId": "uuid-here"
}
- Invalid or expired license:
{
"status": "error",
"message": "Invalid or expired license",
"code": 403,
"errors": null,
"requestId": "uuid-here"
}
- All files are pristine (when integrity check passes):
{
"status": "error",
"message": "all files are pristine",
"code": 403,
"errors": null,
"requestId": "uuid-here"
}
Authentication Errors (401)
- Invalid API key:
{
"status": "error",
"message": "API key parameter 'invalid-key' is invalid",
"code": 401,
"errors": null,
"requestId": "uuid-here"
}
- Missing authorization:
{
"status": "error",
"message": "Missing authorization API Key or Bearer Token",
"code": 401,
"errors": null,
"requestId": "uuid-here"
}
Permission Errors (403)
- Missing required scope:
{
"status": "error",
"message": "Missing required scope: write:alerts",
"code": 403,
"errors": null,
"requestId": "uuid-here"
}
Getting Help
- Check the exact error message - Look at the full response body including requestId
- Verify the URL - Ensure you're using the correct endpoint
- Test with curl - Eliminate client-side issues
- Check system time - Ensure your system clock is correct
- Contact your administrator - If you need permissions or license issues
Emergency Procedures
If All Keys Fail
- Contact your ToBeAlert administrator immediately
- Check license status - The problem might be license-related
- Use the web UI to create a new key if you have UI access
- Check for system-wide outages - The problem might not be your key
If Key is Compromised
- Immediately revoke the compromised key:
curl -X DELETE -H "Authorization: Key ADMIN_KEY" \
http://your-tobealert.com:9000/api/key/COMPROMISED_KEY_ID
- Create a new key with different permissions
- Update all applications using the old key
- Review audit logs to see what was accessed with the compromised key