API Overview
AFFiNE provides a comprehensive GraphQL API for managing workspaces, documents, users, and collaborative features. The API is designed for building integrations, automation tools, and custom clients.Base URL
The GraphQL API endpoint is available at:your-affine-instance.com with your server’s domain.
GraphQL Endpoint
AFFiNE uses GraphQL as its primary API protocol, providing a single endpoint for all operations:- Endpoint:
/graphql - Methods:
POST(for queries and mutations),GET(for GraphiQL in development) - Content-Type:
application/json
Why GraphQL?
- Flexible Queries: Request exactly the data you need
- Type Safety: Strongly typed schema with introspection
- Single Endpoint: All operations through one URL
- Efficient: Reduce over-fetching and under-fetching
GraphiQL Playground
In development mode, you can access the interactive GraphiQL playground:- Interactive query builder
- Schema documentation
- Auto-completion
- Query history
Rate Limiting
AFFiNE implements rate limiting to ensure service stability:Default Rate Limits:
- Default Throttler: 120 requests per 60 seconds
- Strict Throttler: 20 requests per 60 seconds (for sensitive operations)
- Authenticated Users: Higher limits and bypass on certain endpoints
Handling Rate Limits
When you exceed the rate limit, you’ll receive a429 Too Many Requests response:
Making Your First Request
Here’s a simple example to get the current user:Response Format
All GraphQL responses follow this structure:Successful Response
Error Response
Error Codes
AFFiNE uses standardized error codes to help you handle different scenarios:| Code | Description |
|---|---|
AUTHENTICATION_REQUIRED | User must be authenticated |
ACCESS_DENIED | User doesn’t have permission |
NOT_FOUND | Resource doesn’t exist |
VALIDATION_ERROR | Input validation failed |
SPACE_NOT_FOUND | Workspace not found |
DOC_NOT_FOUND | Document not found |
TOO_MANY_REQUEST | Rate limit exceeded |
QUOTA_EXCEEDED | Storage or feature quota exceeded |
COPILOT_QUOTA_EXCEEDED | AI copilot quota exceeded |
BLOB_QUOTA_EXCEEDED | File storage quota exceeded |
For a complete list of error codes, see the
ErrorNames enum in the GraphQL schema.API Versioning
The AFFiNE API uses client version headers to ensure compatibility:- Minimum Required Version:
>=0.25.0 - Recommended: Always use the latest stable client version
Schema Introspection
GraphQL supports introspection, allowing you to query the schema itself:Core Resources
The API provides access to these primary resources:- Users: User accounts, profiles, and authentication
- Workspaces: Collaborative workspace management
- Documents: Pages and docs within workspaces
- Blobs: File attachments and media
- Comments: Document comments and replies
- Copilot: AI-powered features and chat sessions
- Notifications: User notifications and alerts
- Subscriptions: Payment and subscription management
Next Steps
- Set up authentication - Learn how to authenticate API requests See Authentication
- Explore the schema - Browse available queries and mutations in GraphiQL
- Try example queries - Start with simple operations like fetching workspaces
- Build your integration - Combine operations to create powerful workflows
Additional Resources
- GraphQL Schema: Available at
/schema.gqlin the repository - GraphiQL Playground: Available in development mode
- Community: Join our Discord for API discussions
- GitHub: Report issues or contribute to the API