Developers/Lawmatics

Lawmatics Developer Documentation

Technical reference for the CaseHug–Lawmatics integration. API endpoints, data models, webhook events, pipeline stage mapping, and OAuth 2.0 authentication flow.

Lawmatics API v1.21.0OAuth 2.0REST

Authentication Flow

CaseHug uses Lawmatics' OAuth 2.0 Authorization Code Grant flow. Firms must have developer settings enabled (contact support@lawmatics.com).

1. User clicks "Connect to Lawmatics"
2. CaseHug generates CSRF state, stores in oauth_states table
3. Redirect → https://app.lawmatics.com/oauth/authorize
   ?response_type=code
   &client_id={LAWMATICS_CLIENT_ID}
   &redirect_uri={callback_url}
   &scope=read write
   &state={csrf_state}

4. User authorizes in Lawmatics
5. Lawmatics redirects → /api/v1/integrations/lawmatics/callback?code=xxx&state=xxx

6. CaseHug validates CSRF state
7. POST https://app.lawmatics.com/oauth/token
   grant_type=authorization_code
   &code={code}
   &client_id={LAWMATICS_CLIENT_ID}
   &client_secret={LAWMATICS_CLIENT_SECRET}
   &redirect_uri={callback_url}

8. Store access_token + refresh_token in firm_integrations
9. Redirect to dashboard with success message

⚠️ Token refresh: Access tokens expire. CaseHug automatically refreshes tokens 5 minutes before expiration using the refresh_token grant type. If refresh fails, the firm must reconnect.

API Endpoints

GET/api/v1/integrations/lawmatics/connect

Initiates OAuth flow. Generates CSRF state, stores in DB, redirects to Lawmatics authorize URL.

Auth: Firm AdminResponse: 302 Redirect to Lawmatics
GET/api/v1/integrations/lawmatics/callback

OAuth callback. Validates CSRF state, exchanges authorization code for tokens, stores in firm_integrations, redirects to dashboard.

Auth: None (OAuth flow)Response: 302 Redirect to dashboard
POST/api/v1/integrations/lawmatics/disconnect

Revokes Lawmatics OAuth access, removes tokens from DB, deactivates integration.

Auth: Firm AdminResponse: { "success": true }
GET/api/v1/integrations/lawmatics/status

Returns connection status, sync settings, and last sync time.

Auth: AuthenticatedResponse: { "connected": true, "settings": {...}, "last_sync": {...} }
PATCH/api/v1/integrations/lawmatics/status

Update integration settings (auto-sync toggles, case type mappings).

Auth: AuthenticatedResponse: { "success": true, "settings": {...} }
POST/api/v1/integrations/lawmatics/sync

Sync a specific matter to Lawmatics. Body: { "matter_id": "uuid", "action": "sync_matter" | "pull_matters" }

Auth: AuthenticatedResponse: { "success": true, "lawmatics_matter_id": 12345 }
GET/api/v1/integrations/lawmatics/sync

Get sync history for the firm. Query: ?matter_id=xxx&limit=20

Auth: AuthenticatedResponse: { "logs": [...], "total": 20 }
POST/api/v1/integrations/lawmatics/webhooks

Receives webhook events from Lawmatics. Validates signature, processes events, stores in audit log.

Auth: Webhook signatureResponse: { "received": true }

Data Models

firm_integrations

ColumnTypeDescription
firm_idUUIDForeign key to firms table
platformTEXT"lawmatics"
access_tokenTEXTOAuth access token (encrypted)
refresh_tokenTEXTOAuth refresh token
token_expires_atTIMESTAMPTZToken expiration time
is_activeBOOLEANConnection active status
webhook_secretTEXTHMAC secret for webhook verification
settingsJSONBAuto-sync toggles, case type mappings
connected_atTIMESTAMPTZWhen the connection was established

matters (Lawmatics columns)

ColumnTypeDescription
lawmatics_matter_idBIGINTLawmatics matter ID (indexed)
lawmatics_synced_atTIMESTAMPTZLast sync timestamp

lawmatics_webhook_events

ColumnTypeDescription
idUUIDPrimary key
firm_idUUIDForeign key to firms
event_typeTEXTe.g. contact.created, matter.stage_changed
resource_idBIGINTLawmatics resource ID
payloadJSONBRaw webhook payload
processedBOOLEANWhether event has been processed
processed_atTIMESTAMPTZProcessing timestamp
error_messageTEXTError details if processing failed

Webhook Events

EventDescriptionCaseHug Action
contact.createdNew contact added in LawmaticsLogged for future import
matter.stage_changedMatter moved to different pipeline stageUpdates linked CaseHug matter status
form.submittedForm submission received in LawmaticsLogged for audit
envelope.completedE-signature envelope completedLogged for audit

Example webhook payload:

{
  "event": "matter.stage_changed",
  "data": {
    "id": 12345,
    "name": "Smith Divorce",
    "stage": "Retained",
    "previous_stage": "Consultation"
  },
  "timestamp": "2026-04-07T04:30:00Z"
}

Default Stage Mappings

CaseHug maps case types to Lawmatics pipeline stages. Firms can override in Settings → Integrations.

CaseHug Case TypeLawmatics StagePractice Area
divorce_standardFamily Law IntakeFamily Law
custody_onlyFamily Law IntakeFamily Law
immigration_asylumImmigration IntakeImmigration
personal_injury_autoPI IntakePersonal Injury
estate_planning_willEstate Planning IntakeEstate Planning
estate_planning_probateProbate IntakeProbate

Error Codes

StatusMeaning
400Bad Request — Missing required fields or invalid payload
401Unauthorized — Invalid or expired access token
403Forbidden — Insufficient permissions or wrong role
404Not Found — Matter or integration record doesn't exist
429Rate Limited — Too many requests. Retry with exponential backoff
500Internal Error — Check sync logs for details
503Service Unavailable — Lawmatics credentials not configured

Environment Variables

# Lawmatics OAuth credentials (obtain from Lawmatics Developer App)
LAWMATICS_CLIENT_ID=your_client_id
LAWMATICS_CLIENT_SECRET=your_client_secret
LAWMATICS_REDIRECT_URI=https://calmintake.com/api/v1/integrations/lawmatics/callback

# Note: Firms must contact support@lawmatics.com to enable developer settings
# before they can authorize OAuth connections.

Related Resources