PATCH method requires a JSON payload. The action field is mandatory and dictates the state transition. All other fields are optional and will only update the database if explicitly provided.
| Field | Type | Required | Description |
|---|
action | string | Yes | Operation type: approve, reject, or save |
titleEn | string | No | Updated English title |
contentEn | string | No | Updated English content (Markdown/HTML) |
monetization | string | No | Sets isPremium to true if value is "premium", otherwise false |
difficultyLevel | string/number | No | Updates qualityDetails.difficulty_level |
Note on DELETE: The DELETE method requires no request body. Only the path parameter id is needed.
Example Payload (PATCH)
{
"action": "approve",
"titleEn": "Advanced State Management Patterns",
"contentEn": "# Advanced State Management\n\nThis guide covers...",
"monetization": "premium",
"difficultyLevel": "advanced"
}
Success Responses (200 OK)
Successful requests return a JSON object indicating completion. The structure varies slightly between PATCH and DELETE.
PATCH Success:
{
"success": true,
"message": "Article approved successfully",
"data": {
"id": "art_8f3k29d1",
"status": "PUBLISHED",
"isPublished": true,
"publishedAt": "2024-05-20T14:32:10.000Z",
"titleEn": "Advanced State Management Patterns",
"contentEn": "# Advanced State Management\n\nThis guide covers...",
"isPremium": true,
"qualityDetails": {
"difficulty_level": "advanced",
"read_time_minutes": 8
}
}
}
DELETE Success:
{
"success": true,
"message": "Article deleted"
}
Error Responses
| Status Code | Condition | Response Example |
|---|
400 Bad Request | Missing or invalid action value | {"error": "Unknown action: publish"} |
500 Internal Server Error | Malformed JSON, database connection failure, or Supabase constraint violation | {"error": "invalid input syntax for type uuid"} |
Usage Example
Approve & Publish an Article
curl -X PATCH "https://codcompass.com/api/admin/articles/art_8f3k29d1" \
-H "Content-Type: application/json" \
-d '{
"action": "approve",
"titleEn": "Advanced State Management Patterns",
"contentEn": "# Advanced State Management\n\nThis guide covers...",
"monetization": "premium",
"difficultyLevel": "advanced"
}'
Archive an Article
curl -X PATCH "https://codcompass.com/api/admin/articles/art_8f3k29d1" \
-H "Content-Type: application/json" \
-d '{"action": "reject"}'
Permanently Delete an Article
curl -X DELETE "https://codcompass.com/api/admin/articles/art_8f3k29d1"
Common Pitfalls
-
Omitting the action Field
The endpoint strictly requires an action value (approve, reject, or save). If omitted or misspelled, the API returns a 400 error. Always validate the payload before sending.
-
Partial qualityDetails Updates
The endpoint safely merges difficultyLevel into the existing qualityDetails object rather than overwriting it entirely. However, if you expect other nested fields (e.g., read_time_minutes, tags) to be modified, you must handle them separately or via a different endpoint. This route only touches difficulty_level within qualityDetails.
-
monetization Boolean Mapping
The monetization field does not accept arbitrary strings. It explicitly checks for "premium" to set isPremium: true. Any other truthy value (e.g., "free", "1") will set isPremium: false. If the field is omitted, the existing isPremium value remains unchanged.
-
Public Accessibility
This endpoint is configured without authentication. In production environments, ensure it is protected via network-level restrictions, reverse proxy rules, or internal routing to prevent unauthorized modifications or deletions.
/api/admin/articles β Retrieve paginated lists of articles or create new drafts. Use this endpoint to discover article IDs before calling the management route.
/api/articles/[id] β Public-facing read endpoint. Fetches the latest published version of an article for frontend rendering. Changes made via the admin endpoint are immediately visible here once status is set to PUBLISHED.
/api/admin/articles/bulk β Batch operations for status transitions. Prefer this endpoint when moderating large volumes of submissions to reduce network overhead.
For integration support or schema validation details, refer to the platform's OpenAPI specification or contact the developer relations team.