Authentication
Authenticate your API requests with API keys or OAuth
Authentication
Coherence supports two authentication methods: API keys for server-to-server integration and OAuth 2.0 for user-authorized applications.
API Keys
When to Use
Use API keys for:
- Backend integrations
- Automated scripts
- Server-to-server communication
- Zapier and other automation tools
Creating an API Key
- Go to Settings > API
- Click Create API Key
- Name your key (e.g., "Production Integration")
- Set permissions
- Copy and securely store the key
API keys are shown only once. Store them securely - you cannot retrieve them later.
Using API Keys
Include the key in the Authorization header:
curl -X GET "https://api.getcoherence.io/v1/modules/contacts/records" \
-H "Authorization: Bearer ck_live_abc123xyz789"Key Prefixes
| Prefix | Environment |
|---|---|
ck_live_ | Production |
ck_test_ | Sandbox/Test |
Key Permissions
Limit what each key can access:
| Permission | Description |
|---|---|
| Read | View records and data |
| Write | Create and update records |
| Delete | Remove records |
| Admin | Manage settings and users |
Revoking Keys
To revoke an API key:
- Go to Settings > API
- Find the key
- Click Revoke
Revocation is immediate - all requests using that key will fail.
OAuth 2.0
When to Use
Use OAuth for:
- Third-party applications
- User-installed apps
- Apps that act on behalf of users
- Public integrations
OAuth Flow
- Redirect to authorization URL
- User grants permission
- Receive authorization code
- Exchange for access token
- Use token for API requests
Authorization URL
https://app.getcoherence.io/oauth/authorize
?client_id=YOUR_CLIENT_ID
&redirect_uri=https://yourapp.com/callback
&response_type=code
&scope=read write
Token Exchange
Exchange the authorization code for tokens:
curl -X POST "https://api.getcoherence.io/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=authorization_code" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "code=AUTHORIZATION_CODE" \
-d "redirect_uri=https://yourapp.com/callback"Response:
{
"access_token": "at_abc123...",
"refresh_token": "rt_xyz789...",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "read write"
}Using Access Tokens
curl -X GET "https://api.getcoherence.io/v1/users/me" \
-H "Authorization: Bearer at_abc123..."Refreshing Tokens
Access tokens expire after 1 hour. Use the refresh token:
curl -X POST "https://api.getcoherence.io/oauth/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=refresh_token" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "refresh_token=rt_xyz789..."OAuth Scopes
| Scope | Description |
|---|---|
read | Read all accessible data |
write | Create and update records |
delete | Delete records |
email:read | Read email data |
email:send | Send email on behalf of user |
users:read | Read user information |
admin | Administrative access |
Security Best Practices
API Key Storage
Do:
- Store keys in environment variables
- Use secret management services
- Rotate keys regularly
Don't:
- Commit keys to source control
- Share keys in plain text
- Use production keys in development
Token Storage
For OAuth tokens:
- Store tokens encrypted
- Use secure, httpOnly cookies for web apps
- Implement secure storage for mobile apps
IP Restrictions
Limit API key usage by IP:
- Go to API key settings
- Add allowed IP addresses
- Requests from other IPs will fail
Audit Logging
Monitor API usage:
- View request logs in Settings
- See which keys are active
- Track rate limit usage
Error Handling
Authentication Errors
| Code | Message | Solution |
|---|---|---|
| 401 | Invalid API key | Check key is correct and active |
| 401 | Token expired | Refresh the access token |
| 403 | Insufficient permissions | Check key/token scopes |
Example Error
{
"error": {
"code": "authentication_failed",
"message": "Invalid API key provided",
"status": 401
}
}Testing Authentication
Verify Your Key
Test your API key:
curl -X GET "https://api.getcoherence.io/v1/users/me" \
-H "Authorization: Bearer YOUR_API_KEY"Success response:
{
"data": {
"id": "usr_abc123",
"email": "[email protected]",
"name": "Your Name"
}
}Use test API keys in development to avoid affecting production data.
Related: API Overview