Skip to main content
Creates new content with file upload. This endpoint requires admin authentication and accepts multipart/form-data for file uploads.
This endpoint requires admin authentication. Include a valid JWT token in the Authorization header: Bearer <token>

Request Headers

Authorization
string
required
Bearer token for admin authentication
Content-Type
string
required
Must be multipart/form-data

Request Body (multipart/form-data)

title
string
required
Content title
description
string
required
Content description
type
string
required
Content type. Must be one of: pdf, video, audio
category
string
required
Category ID
price
number
required
Content price (minimum: 0)
file
file
required
The content file to upload (PDF, video, or audio file)
thumbnail
file
Optional thumbnail image for the content
status
string
default:"draft"
Content status. Must be one of: draft, published
tags
string
JSON stringified array of tags. Example: ["javascript", "advanced"]

Response

message
string
Success message
content
object
Created content object

Error Responses

400 Bad Request

{
  "error": "Content file is required"
}

401 Unauthorized

Returned when authentication token is missing or invalid.

403 Forbidden

Returned when the authenticated user is not an admin.

500 Internal Server Error

{
  "error": "Error message"
}
Files are uploaded to Cloudinary. The fileUrl and filePublicId are automatically generated and stored. The duration field is automatically populated for video/audio files, and fileSize is captured in bytes.
{
  "message": "Content created successfully",
  "content": {
    "_id": "507f1f77bcf86cd799439011",
    "title": "Advanced JavaScript Patterns",
    "description": "Learn advanced design patterns in JavaScript",
    "type": "pdf",
    "category": "507f1f77bcf86cd799439012",
    "price": 29.99,
    "fileUrl": "https://res.cloudinary.com/example/raw/upload/v1234567890/content.pdf",
    "filePublicId": "vaniyk/content/abc123",
    "thumbnailUrl": "https://res.cloudinary.com/example/image/upload/v1234567890/thumbnail.jpg",
    "thumbnailPublicId": "vaniyk/thumbnails/xyz789",
    "fileSize": 5242880,
    "status": "draft",
    "tags": ["javascript", "patterns", "advanced"],
    "createdBy": {
      "_id": "507f1f77bcf86cd799439013",
      "name": "John Doe",
      "email": "[email protected]"
    },
    "createdAt": "2024-03-01T12:00:00.000Z",
    "updatedAt": "2024-03-01T12:00:00.000Z"
  }
}

Build docs developers (and LLMs) love