API Authentication
All requests to the Forest Public API require authentication using API tokens. This guide explains how to create, manage, and use API tokens securely.Authentication Overview
Forest uses Bearer token authentication for API requests. Each token:- Is associated with a specific Forest project
- Can have different permission scopes
- Should be treated as sensitive credentials
- Revocable at any time
Creating API Tokens
Step 1: Access Project Settings
- Log in to your Forest account
- Navigate to your project
- Go to Project Settings > API Access
- Click Generate New Token
Step 2: Configure Token
When creating a token, configure:- Token Name - A descriptive name to identify the token’s purpose
- Permissions - Read-only or Read-write access
- Expiration - Optional expiration date for added security
- Scopes - Specific endpoints the token can access
Step 3: Save Token
Using API Tokens
Include your API token in theAuthorization header of all requests using the Bearer scheme:
Example Requests
cURL:Token Security
Storing Tokens Securely
Environment Variables:- AWS Secrets Manager
- Google Cloud Secret Manager
- Azure Key Vault
- HashiCorp Vault
- 1Password Secrets Automation
What NOT to Do
❌ Never commit tokens to version control:Secure Practices
✅ Use environment variables:Token Permissions
Permission Levels
Read-Only:- View activity logs
- View admin logs
- Read notes
- Cannot create or modify data
- All read permissions
- Create and update notes
- Perform write operations (where available)
Scope Limitations
Limit token access to only the endpoints needed:| Scope | Access |
|---|---|
activity_logs:read | Read activity logs |
admin_logs:read | Read admin logs |
notes:read | Read notes |
notes:write | Create and update notes |
all | Full API access |
Token Management
Listing Active Tokens
View all active tokens in Project Settings > API Access:- Token name
- Creation date
- Last used
- Expiration date
- Scopes
Rotating Tokens
Regular token rotation improves security:- Generate a new token with same permissions
- Update all integrations to use new token
- Verify all integrations working
- Revoke the old token
- Production: Every 90 days
- Development: Every 180 days
- Testing: As needed
Revoking Tokens
Immediately revoke a token if:- It may have been compromised
- An integration is decommissioned
- An team member with access leaves
- You detect suspicious activity
- Go to Project Settings > API Access
- Find the token
- Click Revoke
- Confirm revocation
Authentication Errors
401 Unauthorized
Cause: Missing, invalid, or expired token Response:- Verify token is included in Authorization header
- Check token hasn’t expired
- Ensure token format is correct (
Bearer <token>) - Regenerate token if necessary
403 Forbidden
Cause: Token lacks required permissions Response:- Check token scopes include required permissions
- Generate new token with appropriate scopes
- Verify endpoint matches token permissions
Token Expired
Cause: Token past expiration date Response:- Generate a new token
- Update integration configuration
- Consider longer expiration or no expiration for stable integrations
Best Practices
1. One Token Per Integration
Create separate tokens for each integration:2. Principle of Least Privilege
Grant minimum necessary permissions:3. Monitor Token Usage
Track token activity in Project Settings > API Access:- Last used timestamp
- Request frequency
- Error rates
- Unusual patterns
4. Implement Error Handling
Handle authentication errors gracefully:5. Audit Token Access
Regular security reviews:- Review active tokens monthly
- Revoke unused tokens
- Update token names to reflect current usage
- Document token purpose and owner
Next Steps
Rate Limits
Understand API usage limits
Activity Logs
Start using the Activity Logs API
API Introduction
Back to API overview
Security
Learn about Forest security