stable.se

API-Tokens und Webhooks gehören heute zu keinem unserer Pläne. Schreiben Sie uns, bevor Sie auf der API aufbauen.

Die Entwicklerdokumentation ist derzeit nur auf Englisch verfügbar.

Authentication

Learn how to authenticate with the Stable API using API tokens and manage access scopes.

3 min read

Overview

Every request authenticates with a bearer token in the Authorization header. Integrations use API tokens: long-lived tokens that belong to an API application in your organization and carry a set of scopes. API tokens start with stl_sk_.

Each endpoint applies its own access rules. Endpoints that act on behalf of a signed-in person do not accept API tokens and respond with 401 or 403. Use GET /v1/auth/token-info to check what a token is and which scopes it has.

Creating an API Token

An organization Owner or Admin creates API applications and tokens with the API Tokens endpoints, signed in with their Stable account:

  1. Create an application with POST /v1/organizations/{org_public_id}/applications, giving it a name and its scopes.
  2. Create a token with POST /v1/applications/{app_public_id}/tokens, giving it a name and an optional expiry date.
  3. Copy the token from the response. The full token is shown only when it is created or rotated.

Creating, rotating and revoking tokens can ask the signed-in person to confirm with two-factor authentication first. See the API reference for the exact request and response fields.

Making Authenticated Requests

Send the token in the Authorization header:

curl https://api.stable.se/v1/auth/token-info \
  -H "Authorization: Bearer stl_sk_your_api_token"

API Scopes

Scopes control what a token can access. Each scope has the form action:resource. Reading (GET) needs the read: scope; creating, changing and deleting need the write: scope. A write: scope includes the matching read: scope, so write:horses grants both. Role and resource permissions still apply on top of scopes.

Read ScopeWrite ScopeDescription
read:horseswrite:horsesHorse profiles, health records, ownership
read:bookingswrite:bookingsReservations and booking management
read:invoiceswrite:invoicesInvoices and payment information
read:organizationwrite:organizationOrganization members and roles
read:taskswrite:tasksTask series, instances, and workflows
read:calendarwrite:calendarCalendar events and scheduling
read:trainingwrite:trainingTraining programs and sessions
read:pimwrite:pimProduct catalog and inventory
read:equipmentwrite:equipmentEquipment tracking
read:documentswrite:documentsDocument storage and management
read:expenseswrite:expensesExpense tracking
read:locationswrite:locationsLocations, stalls, paddocks
read:consumableswrite:consumablesConsumable supplies tracking
read:messagingwrite:messagingMessaging and communications
admin:*--All of the scopes above

Principle of Least Privilege

Only request the scopes your integration needs. You can create separate applications and tokens with different scopes for different purposes.

Error Responses

Missing Authentication

{
  "status": "401 Unauthorized",
  "message": "Authentication required",
  "code": "unauthorized"
}

Insufficient Scopes

{
  "status": "403 Forbidden",
  "message": "Missing required scope: ReadHorses",
  "code": "forbidden"
}

Invalid Token

A token that is unknown, expired or revoked gets a 401 with a reason:

{
  "status": "401 Unauthorized",
  "message": "Invalid API token",
  "code": "UNAUTHORIZED",
  "reason": "token_invalid"
}

Check the HTTP status first. Compare code without regard to case: both unauthorized and UNAUTHORIZED mean the request was not authenticated.

Token Security Best Practices

  • Never commit tokens to source control
  • Store tokens in environment variables or a secrets manager
  • Rotate tokens periodically
  • Use separate tokens for development and production
  • Revoke tokens immediately if compromised
  • Review when each token was last used