Overview
API tokens provide secure, programmatic access to the LearnHouse API. They are ideal for:- Integrations with third-party services
- CI/CD pipelines
- Automated scripts and tools
- Server-to-server communication
Token Features
Organization Scoped
Each token is scoped to a specific organization
Configurable Rights
Fine-grained permission control
Optional Expiration
Set expiration dates or create permanent tokens
Usage Tracking
Monitor last usage timestamp
Token Format
API tokens use a prefix-based format for easy identification:- Prefix:
lh_(first 12 characters visible) - Full token shown only once upon creation
- Stored as SHA-256 hash in database
Create API Token
POST /api/v1/orgs/{org_id}/api-tokensPath Parameters
Organization ID for the token scope
Request Body
Token name (max 100 characters)
Token description (max 500 characters)
Permission rights for the token (follows organization rights structure)
ISO 8601 timestamp for token expiration (null = never expires)
Response
Full API token - Only shown once! Store securely.
Unique token identifier (format:
apitoken_{uuid})Token name
Token description
First 12 characters of the token (e.g., “lh_abc12345”)
Organization ID
Token permissions
ID of user who created the token
ISO timestamp of creation
ISO timestamp of expiration
Example
List API Tokens
GET /api/v1/orgs/{org_id}/api-tokensPath Parameters
Organization ID
Response
Array of token objects (without thetoken field):
Token database ID
Token UUID
Token name
Token prefix (first 12 characters)
Whether token is active (false if revoked)
ISO timestamp of last usage
ISO timestamp of expiration
Example
Get API Token
GET /api/v1/orgs/{org_id}/api-tokens/{token_uuid}Path Parameters
Organization ID
Token UUID (format:
apitoken_{uuid})Example
Update API Token
PUT /api/v1/orgs/{org_id}/api-tokens/{token_uuid}Path Parameters
Organization ID
Token UUID
Request Body
All fields are optional:New token name
New token description
Updated permissions
New expiration timestamp
Example
Regenerate API Token
POST /api/v1/orgs/{org_id}/api-tokens/{token_uuid}/regeneratePath Parameters
Organization ID
Token UUID
Response
Returns the same response as creating a new token, including the new full token value.Example
Revoke API Token
DELETE /api/v1/orgs/{org_id}/api-tokens/{token_uuid}Path Parameters
Organization ID
Token UUID
Response
Example
Using API Tokens
Include the API token in theAuthorization header as a Bearer token:
Token Scope
API tokens can only access resources within their organization scope:- ✅ Can access:
/api/v1/orgs/123/courses(same org) - ❌ Cannot access:
/api/v1/orgs/456/courses(different org)
Rate Limiting
Token creation and regeneration are rate-limited to prevent abuse:Permissions Required
API token management requires specific organization permissions:- Create:
roles.action_createpermission - List/Get:
roles.action_readpermission - Update/Regenerate:
roles.action_updatepermission - Revoke:
roles.action_deletepermission
Security Best Practices
Store Tokens Securely
Store Tokens Securely
- Never commit tokens to version control
- Use environment variables or secret management systems
- Encrypt tokens at rest
- Limit access to token storage
Use Minimal Permissions
Use Minimal Permissions
- Grant only necessary rights to each token
- Create separate tokens for different purposes
- Review and update rights regularly
Set Expiration Dates
Set Expiration Dates
- Use expiration dates for temporary integrations
- Rotate tokens periodically
- Monitor expiring tokens
Monitor Usage
Monitor Usage
- Track
last_used_attimestamps - Revoke unused tokens
- Audit token activity regularly
Rotate Compromised Tokens
Rotate Compromised Tokens
- Immediately revoke compromised tokens
- Use regenerate endpoint to rotate secrets
- Investigate unauthorized usage
Error Codes
Invalid input (name too long, invalid rights structure, etc.)
Missing or invalid authentication
Insufficient permissions for the operation
Token or organization not found
Rate limit exceeded for token creation/regeneration
Related Resources
Authentication Overview
Learn about authentication methods
Permissions
Understand the rights system