Authentication

The CaseHug API supports two authentication methods: API Keys for server-to-server integrations, and OAuth 2.0 for integrations that act on behalf of firm users.

API Key Authentication

The simplest way to authenticate. Pass your API key in the X-Api-Key request header. API keys are scoped to specific resources and operations.

⚠️
Keep your API key secret. Never expose it in client-side code or public repositories. Use environment variables and server-side code only.
API Key Request
curl -X GET https://api.calmintake.com/api/v1/matters \
  -H "X-Api-Key: ch_live_sk_abc123xyz" \
  -H "Content-Type: application/json"

Available Scopes

ScopeDescription
matters:readList and retrieve matters
matters:writeCreate, update, and archive matters
clients:readList and retrieve clients
clients:writeCreate and update clients
documents:readList and retrieve documents
documents:writeRequest, approve, and manage uploads
webhooks:readList webhook endpoints
webhooks:writeCreate, update, and delete webhooks
firms:readRead firm details and settings
firms:writeUpdate firm settings and manage users

Code Examples

curl -X GET https://api.calmintake.com/api/v1/matters \
  -H "X-Api-Key: ch_live_sk_abc123xyz" \
  -H "Content-Type: application/json"

OAuth 2.0

Use OAuth 2.0 when your integration needs to act on behalf of a specific firm user. CaseHug supports the Authorization Code flow.

Step 1 — Redirect to Authorization

Authorization URL
https://app.calmintake.com/oauth/authorize
  ?client_id=your_client_id
  &redirect_uri=https://your-app.com/callback
  &response_type=code
  &scope=matters:read+clients:read
  &state=random_state_string

Step 2 — Exchange Code for Token

Token Request
POST /oauth/token HTTP/1.1
Host: api.calmintake.com
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
&code=AUTH_CODE_FROM_REDIRECT
&redirect_uri=https://your-app.com/callback
&client_id=your_client_id
&client_secret=your_client_secret

Token Response

Token Response
{
  "access_token": "ch_oauth_eyJhbGciOiJSUzI1NiJ9...",
  "token_type": "Bearer",
  "expires_in": 3600,
  "refresh_token": "ch_refresh_eyJhbGciOiJSUzI1NiJ9...",
  "scope": "matters:read matters:write clients:read"
}

Step 3 — Use the Token

Authenticated Request
curl -X GET https://api.calmintake.com/api/v1/matters \
  -H "Authorization: Bearer ch_oauth_eyJhbGciOiJSUzI1NiJ9..." \
  -H "Content-Type: application/json"

Token Refresh Flow

Access tokens expire after 1 hour. Use the refresh token to get a new access token without requiring the user to re-authorize.

Refresh Token Request
POST /oauth/token HTTP/1.1
Host: api.calmintake.com
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token
&refresh_token=ch_refresh_eyJhbGciOiJSUzI1NiJ9...
&client_id=your_client_id
&client_secret=your_client_secret

Rate Limits

Rate limits are applied per API key per minute. Responses include headers showing your current usage.

PlanRate LimitBurst
Standard100 req/min150 req/min for 10s
Pro500 req/min750 req/min for 10s
Enterprise1,000 req/minCustom

Rate Limit Headers

HeaderDescription
X-RateLimit-LimitTotal requests allowed per window
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetUnix timestamp when window resets
Retry-AfterSeconds to wait before retrying (429 only)

429 Response

Rate Limit Exceeded
HTTP/1.1 429 Too Many Requests
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1709856000
Retry-After: 47

{
  "error": {
    "code": "rate_limit_exceeded",
    "message": "Too many requests. Please retry after 47 seconds.",
    "details": {
      "limit": 100,
      "window": "60s",
      "reset_at": "2024-03-07T14:00:00Z"
    }
  }
}

Auth Error Codes

StatusCodeDescription
401missing_api_keyNo X-Api-Key header provided
401invalid_api_keyAPI key is malformed or does not exist
401expired_tokenOAuth access token has expired
403insufficient_scopeAPI key lacks required scope for this action
403firm_suspendedFirm account is suspended
429rate_limit_exceededToo many requests, see Retry-After header