Skip to main content
TrailBase provides a comprehensive REST API for authentication, record management, subscriptions, and file operations. All APIs are versioned and follow RESTful conventions.

Base URLs

TrailBase REST APIs are organized into the following base paths:
  • Authentication: /api/auth/v1
  • Records: /api/records/v1
  • Transactions: /api/transaction/v1
  • Query: /api/query/v1
  • Admin: /api/_admin
All API paths are relative to your TrailBase instance URL (e.g., https://your-instance.com/api/auth/v1/login).

Versioning

TrailBase uses path-based versioning. The current API version is v1 and is included in the base path for all public APIs.
  • Authentication APIs: /api/auth/v1/*
  • Records APIs: /api/records/v1/*
Future versions will be introduced as /api/auth/v2, /api/records/v2, etc., while maintaining backward compatibility.

Authentication

TrailBase supports multiple authentication methods:

Bearer Token Authentication

Include the JWT auth token in the Authorization header:
For web applications hosted on the same origin, TrailBase automatically sets cookies:
  • auth_token: Short-lived JWT token for authentication
  • refresh_token: Long-lived token for refreshing auth tokens

CSRF Protection

For state-changing operations (POST, PATCH, DELETE), you may need to include the CSRF token in the CSRF-Token header when using cookie-based authentication.

Token Refresh

Include the refresh token in the Refresh-Token header:

Request Formats

TrailBase accepts multiple request content types:

JSON (application/json)

Form Data (application/x-www-form-urlencoded)

Multipart Form Data (multipart/form-data)

Used for file uploads:

Response Formats

All responses are in JSON format with appropriate HTTP status codes.

Success Response

Error Response

In production mode, error messages are intentionally minimal to avoid leaking internal details. Debug mode provides more detailed error information.

Error Handling

TrailBase uses standard HTTP status codes to indicate success or failure:

Success Codes

OK
Request succeeded, response body contains the result.
Created
Resource created successfully.
See Other
Redirect to another URL (typically after successful form submission).

Client Error Codes

Bad Request
Invalid request parameters, malformed JSON, or constraint violation.
Unauthorized
Authentication required but not provided or invalid.
Forbidden
Authenticated but not authorized to access the resource.
Not Found
Resource or API endpoint not found.
Method Not Allowed
API not found or HTTP method not supported for this endpoint.
Conflict
Resource already exists (e.g., duplicate registration).
Failed Dependency
External dependency failed (e.g., email service unavailable).
Too Many Requests
Rate limit exceeded.

Server Error Codes

Internal Server Error
Unexpected server error occurred.

Database Constraint Errors

When database constraints are violated, TrailBase returns 400 Bad Request with specific error messages:
  • db constraint: check - CHECK constraint failed
  • db constraint: fk - Foreign key constraint failed
  • db constraint: not null - NOT NULL constraint failed
  • db constraint: pk - Primary key constraint failed
  • db constraint: unique - UNIQUE constraint failed

Rate Limiting

Certain endpoints (like password reset and email verification) are rate-limited to prevent abuse. Exceeding rate limits returns 429 Too Many Requests.

CORS

TrailBase supports Cross-Origin Resource Sharing (CORS) for web applications. Configure CORS settings in your TrailBase configuration.

Pagination

List endpoints support cursor-based pagination:
integer
Number of records to return (default varies by API, configurable hard limit)
string
Encrypted cursor from previous response for fetching the next page
integer
Zero-based offset for pagination (alternative to cursor)

Filtering

Records API supports filtering via query parameters:
See the Records API documentation for detailed filtering syntax.

Ordering

Results can be ordered by specifying column names:

Best Practices

  1. Always use HTTPS in production to protect authentication tokens
  2. Store tokens securely - never expose tokens in client-side code or logs
  3. Implement token refresh to maintain sessions without re-authentication
  4. Handle errors gracefully - check status codes and parse error messages
  5. Use appropriate content types - JSON for most requests, multipart for file uploads
  6. Respect rate limits - implement exponential backoff for retry logic
  7. Validate inputs on the client side to reduce unnecessary API calls

SDK Support

TrailBase provides TypeScript types for all API endpoints, which can be found in the generated client package. See the Client Libraries documentation for more details.