HTTP API Reference
This reference documents all HTTP endpoints provided by Trokky.
Base URL
Section titled “Base URL”All endpoints are relative to your API base path (default: /api).
https://your-domain.com/apiAuthentication
Section titled “Authentication”Protected endpoints require a JWT token in the Authorization header:
Authorization: Bearer <token>Documents
Section titled “Documents”List Documents
Section titled “List Documents”GET /api/documents/:typeQuery Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
limit | number | 20 | Items per page |
offset | number | 0 | Skip items |
orderBy | string | _createdAt | Sort field |
order | string | desc | asc or desc |
expand | string | - | Comma-separated references to expand |
filter[field] | any | - | Filter by field value |
Example:
curl "http://localhost:3000/api/documents/post?limit=10&orderBy=publishedAt&order=desc"Response:
{ "data": [ { "_id": "abc123", "_type": "post", "_createdAt": "2024-01-15T10:00:00Z", "_updatedAt": "2024-01-16T14:30:00Z", "title": "My Post", "slug": { "current": "my-post" } } ], "meta": { "total": 42, "limit": 10, "offset": 0 }}Get Document
Section titled “Get Document”GET /api/documents/:type/:idQuery Parameters:
| Parameter | Type | Description |
|---|---|---|
expand | string | References to expand |
Example:
curl "http://localhost:3000/api/documents/post/abc123?expand=author"Response:
{ "data": { "_id": "abc123", "_type": "post", "title": "My Post", "author": { "_id": "author-xyz", "_type": "author", "name": "John Doe" } }}Create Document
Section titled “Create Document”POST /api/documents/:typeHeaders:
Authorization: Bearer <token>Content-Type: application/jsonBody:
{ "title": "New Post", "content": "Post content here", "status": "draft"}Response:
{ "data": { "_id": "new-id-123", "_type": "post", "_createdAt": "2024-01-20T10:00:00Z", "_updatedAt": "2024-01-20T10:00:00Z", "title": "New Post", "content": "Post content here", "status": "draft" }}Update Document
Section titled “Update Document”PUT /api/documents/:type/:idReplaces the entire document.
Body:
{ "title": "Updated Title", "content": "Updated content", "status": "published"}Partial Update
Section titled “Partial Update”PATCH /api/documents/:type/:idUpdates only specified fields.
Body:
{ "status": "published", "publishedAt": "2024-01-20T10:00:00Z"}Delete Document
Section titled “Delete Document”DELETE /api/documents/:type/:idResponse:
{ "success": true}List Media
Section titled “List Media”GET /api/mediaQuery Parameters:
| Parameter | Type | Description |
|---|---|---|
limit | number | Items per page |
offset | number | Skip items |
type | string | Filter by MIME type prefix (e.g., image) |
search | string | Search filename |
Response:
{ "data": [ { "_id": "media-abc123", "filename": "photo.jpg", "originalFilename": "IMG_1234.jpg", "mimeType": "image/jpeg", "size": 245678, "width": 1920, "height": 1080, "alt": "Description", "url": "/media/photo-abc123.jpg", "variants": { "thumb": "/media/photo-abc123-thumb.webp", "medium": "/media/photo-abc123-medium.webp" }, "createdAt": "2024-01-15T10:00:00Z" } ], "meta": { "total": 100, "limit": 20, "offset": 0 }}Get Media
Section titled “Get Media”GET /api/media/:idUpload Media
Section titled “Upload Media”POST /api/mediaHeaders:
Authorization: Bearer <token>Content-Type: multipart/form-dataForm Data:
| Field | Type | Required | Description |
|---|---|---|---|
file | File | Yes | The file to upload |
alt | string | No | Alt text |
title | string | No | Media title |
Example (curl):
curl -X POST http://localhost:3000/api/media \ -H "Authorization: Bearer <token>" \ -F "file=@photo.jpg" \ -F "alt=My photo"Response:
{ "data": { "_id": "media-new123", "filename": "photo.jpg", "url": "/media/photo-new123.jpg", "variants": { "thumb": "/media/photo-new123-thumb.webp" } }}Update Media Metadata
Section titled “Update Media Metadata”PATCH /api/media/:idBody:
{ "alt": "Updated description", "title": "New title"}Delete Media
Section titled “Delete Media”DELETE /api/media/:idAuthentication
Section titled “Authentication”POST /api/auth/loginBody:
{ "username": "admin", "password": "password"}Response:
{ "token": "eyJhbGciOiJIUzI1NiIs...", "user": { "id": "user-abc123", "username": "admin", "role": "admin", "name": "Administrator" }, "expiresAt": "2024-01-27T10:00:00Z"}Get Current User
Section titled “Get Current User”GET /api/auth/meHeaders:
Authorization: Bearer <token>Response:
{ "data": { "id": "user-abc123", "username": "admin", "role": "admin", "name": "Administrator" }}Refresh Token
Section titled “Refresh Token”POST /api/auth/refreshHeaders:
Authorization: Bearer <token>Response:
{ "token": "eyJhbGciOiJIUzI1NiIs...", "expiresAt": "2024-01-27T10:00:00Z"}Logout
Section titled “Logout”POST /api/auth/logoutConfiguration
Section titled “Configuration”Get Schemas
Section titled “Get Schemas”GET /api/config/schemasReturns all registered schemas.
Response:
{ "data": [ { "name": "post", "title": "Blog Post", "fields": [...] }, { "name": "author", "title": "Author", "fields": [...] } ]}Get Studio Config
Section titled “Get Studio Config”GET /api/config/studioReturns Studio configuration.
Get Structure
Section titled “Get Structure”GET /api/config/structureReturns navigation structure (may be personalized based on user).
Error Responses
Section titled “Error Responses”Error Format
Section titled “Error Format”{ "error": { "code": "ERROR_CODE", "message": "Human readable message", "details": [...] }}Error Codes
Section titled “Error Codes”| Code | Status | Description |
|---|---|---|
VALIDATION_ERROR | 422 | Invalid input data |
NOT_FOUND | 404 | Resource not found |
UNAUTHORIZED | 401 | Authentication required |
FORBIDDEN | 403 | Insufficient permissions |
CONFLICT | 409 | Resource conflict |
INTERNAL_ERROR | 500 | Server error |
Validation Error Example
Section titled “Validation Error Example”{ "error": { "code": "VALIDATION_ERROR", "message": "Validation failed", "details": [ { "field": "title", "message": "Required field" }, { "field": "email", "message": "Invalid email format" } ] }}Filtering
Section titled “Filtering”Basic Filtering
Section titled “Basic Filtering”GET /api/documents/post?filter[status]=publishedMultiple Filters
Section titled “Multiple Filters”GET /api/documents/post?filter[status]=published&filter[featured]=trueReference Filtering
Section titled “Reference Filtering”GET /api/documents/post?filter[author]=author-abc123Expanding References
Section titled “Expanding References”Single Reference
Section titled “Single Reference”GET /api/documents/post/abc123?expand=authorMultiple References
Section titled “Multiple References”GET /api/documents/post/abc123?expand=author,categoriesNested References
Section titled “Nested References”GET /api/documents/post/abc123?expand=author.companyRate Limiting
Section titled “Rate Limiting”When rate limited, the API returns:
HTTP/1.1 429 Too Many RequestsRetry-After: 60{ "error": { "code": "RATE_LIMITED", "message": "Too many requests", "retryAfter": 60 }}Examples
Section titled “Examples”JavaScript/TypeScript
Section titled “JavaScript/TypeScript”// Using fetchconst response = await fetch('http://localhost:3000/api/documents/post', { headers: { 'Authorization': `Bearer ${token}`, },});const { data } = await response.json();
// Create documentconst newPost = await fetch('http://localhost:3000/api/documents/post', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ title: 'New Post', content: 'Content here', }),});# List documentscurl http://localhost:3000/api/documents/post
# Create documentcurl -X POST http://localhost:3000/api/documents/post \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"title": "New Post"}'
# Upload mediacurl -X POST http://localhost:3000/api/media \ -H "Authorization: Bearer $TOKEN" \ -F "file=@image.jpg" \ -F "alt=Image description"