Skip to content

HTTP API Reference

This reference documents all HTTP endpoints provided by Trokky.

All endpoints are relative to your API base path (default: /api).

https://your-domain.com/api

Protected endpoints require a JWT token in the Authorization header:

Authorization: Bearer <token>

GET /api/documents/:type

Query Parameters:

ParameterTypeDefaultDescription
limitnumber20Items per page
offsetnumber0Skip items
orderBystring_createdAtSort field
orderstringdescasc or desc
expandstring-Comma-separated references to expand
filter[field]any-Filter by field value

Example:

Terminal window
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 /api/documents/:type/:id

Query Parameters:

ParameterTypeDescription
expandstringReferences to expand

Example:

Terminal window
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"
}
}
}
POST /api/documents/:type

Headers:

Authorization: Bearer <token>
Content-Type: application/json

Body:

{
"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"
}
}
PUT /api/documents/:type/:id

Replaces the entire document.

Body:

{
"title": "Updated Title",
"content": "Updated content",
"status": "published"
}
PATCH /api/documents/:type/:id

Updates only specified fields.

Body:

{
"status": "published",
"publishedAt": "2024-01-20T10:00:00Z"
}
DELETE /api/documents/:type/:id

Response:

{
"success": true
}

GET /api/media

Query Parameters:

ParameterTypeDescription
limitnumberItems per page
offsetnumberSkip items
typestringFilter by MIME type prefix (e.g., image)
searchstringSearch 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 /api/media/:id
POST /api/media

Headers:

Authorization: Bearer <token>
Content-Type: multipart/form-data

Form Data:

FieldTypeRequiredDescription
fileFileYesThe file to upload
altstringNoAlt text
titlestringNoMedia title

Example (curl):

Terminal window
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"
}
}
}
PATCH /api/media/:id

Body:

{
"alt": "Updated description",
"title": "New title"
}
DELETE /api/media/:id

POST /api/auth/login

Body:

{
"username": "admin",
"password": "password"
}

Response:

{
"token": "eyJhbGciOiJIUzI1NiIs...",
"user": {
"id": "user-abc123",
"username": "admin",
"role": "admin",
"name": "Administrator"
},
"expiresAt": "2024-01-27T10:00:00Z"
}
GET /api/auth/me

Headers:

Authorization: Bearer <token>

Response:

{
"data": {
"id": "user-abc123",
"username": "admin",
"role": "admin",
"name": "Administrator"
}
}
POST /api/auth/refresh

Headers:

Authorization: Bearer <token>

Response:

{
"token": "eyJhbGciOiJIUzI1NiIs...",
"expiresAt": "2024-01-27T10:00:00Z"
}
POST /api/auth/logout

GET /api/config/schemas

Returns all registered schemas.

Response:

{
"data": [
{
"name": "post",
"title": "Blog Post",
"fields": [...]
},
{
"name": "author",
"title": "Author",
"fields": [...]
}
]
}
GET /api/config/studio

Returns Studio configuration.

GET /api/config/structure

Returns navigation structure (may be personalized based on user).


{
"error": {
"code": "ERROR_CODE",
"message": "Human readable message",
"details": [...]
}
}
CodeStatusDescription
VALIDATION_ERROR422Invalid input data
NOT_FOUND404Resource not found
UNAUTHORIZED401Authentication required
FORBIDDEN403Insufficient permissions
CONFLICT409Resource conflict
INTERNAL_ERROR500Server error
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Validation failed",
"details": [
{
"field": "title",
"message": "Required field"
},
{
"field": "email",
"message": "Invalid email format"
}
]
}
}

GET /api/documents/post?filter[status]=published
GET /api/documents/post?filter[status]=published&filter[featured]=true
GET /api/documents/post?filter[author]=author-abc123

GET /api/documents/post/abc123?expand=author
GET /api/documents/post/abc123?expand=author,categories
GET /api/documents/post/abc123?expand=author.company

When rate limited, the API returns:

HTTP/1.1 429 Too Many Requests
Retry-After: 60
{
"error": {
"code": "RATE_LIMITED",
"message": "Too many requests",
"retryAfter": 60
}
}

// Using fetch
const response = await fetch('http://localhost:3000/api/documents/post', {
headers: {
'Authorization': `Bearer ${token}`,
},
});
const { data } = await response.json();
// Create document
const 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',
}),
});
Terminal window
# List documents
curl http://localhost:3000/api/documents/post
# Create document
curl -X POST http://localhost:3000/api/documents/post \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"title": "New Post"}'
# Upload media
curl -X POST http://localhost:3000/api/media \
-H "Authorization: Bearer $TOKEN" \
-F "file=@image.jpg" \
-F "alt=Image description"