Skip to main content
GET
/
api
/
course
/
:id
Get Course
curl --request GET \
  --url https://api.example.com/api/course/:id
{
  "success": true,
  "courseData": {
    "_id": "65f8a2b3c4d5e6f7a8b9c0d1",
    "courseTitle": "Complete Web Development Bootcamp",
    "courseDescription": "Learn web development from scratch with HTML, CSS, JavaScript, React, Node.js and more. This comprehensive course covers everything you need to become a full-stack web developer.",
    "courseThumbnail": "https://example.com/thumbnails/web-dev-bootcamp.jpg",
    "coursePrice": 49.99,
    "isPublished": true,
    "discount": 20,
    "courseContent": [
      {
        "chapterId": "ch_001",
        "chapterOrder": 1,
        "chapterTitle": "Introduction to Web Development",
        "chapterContent": [
          {
            "lectureId": "lec_001",
            "lectureTitle": "Welcome to the Course",
            "lectureDuration": 5,
            "lectureUrl": "https://example.com/videos/welcome.mp4",
            "isPreviewFree": true,
            "lectureOrder": 1
          },
          {
            "lectureId": "lec_002",
            "lectureTitle": "Setting Up Your Development Environment",
            "lectureDuration": 12,
            "lectureUrl": "",
            "isPreviewFree": false,
            "lectureOrder": 2
          }
        ]
      },
      {
        "chapterId": "ch_002",
        "chapterOrder": 2,
        "chapterTitle": "HTML Fundamentals",
        "chapterContent": [
          {
            "lectureId": "lec_003",
            "lectureTitle": "HTML Basics and Structure",
            "lectureDuration": 18,
            "lectureUrl": "https://example.com/videos/html-basics.mp4",
            "isPreviewFree": true,
            "lectureOrder": 1
          },
          {
            "lectureId": "lec_004",
            "lectureTitle": "Working with Forms and Inputs",
            "lectureDuration": 22,
            "lectureUrl": "",
            "isPreviewFree": false,
            "lectureOrder": 2
          }
        ]
      }
    ],
    "averageRating": 4.7,
    "totalRatings": 342,
    "totalLectures": 156,
    "totalDurationMinutes": 1840,
    "educatorId": {
      "_id": "65f8a1b2c3d4e5f6a7b8c9d0",
      "name": "John Smith",
      "imageUrl": "https://example.com/profiles/john-smith.jpg"
    },
    "totalEnrolledStudents": 1523,
    "createdAt": "2024-03-15T10:30:00.000Z",
    "updatedAt": "2024-03-20T14:22:00.000Z"
  }
}

Endpoint

GET /api/course/:id

Authentication

No authentication required. This is a public endpoint.

Path Parameters

id
string
required
The unique MongoDB ObjectId of the course to retrieve

Response

success
boolean
required
Indicates whether the request was successful
message
string
Error message when the course is not found (only present when success is false)
courseData
object
Detailed course information including content structure

Success Response

{
  "success": true,
  "courseData": {
    "_id": "65f8a2b3c4d5e6f7a8b9c0d1",
    "courseTitle": "Complete Web Development Bootcamp",
    "courseDescription": "Learn web development from scratch with HTML, CSS, JavaScript, React, Node.js and more. This comprehensive course covers everything you need to become a full-stack web developer.",
    "courseThumbnail": "https://example.com/thumbnails/web-dev-bootcamp.jpg",
    "coursePrice": 49.99,
    "isPublished": true,
    "discount": 20,
    "courseContent": [
      {
        "chapterId": "ch_001",
        "chapterOrder": 1,
        "chapterTitle": "Introduction to Web Development",
        "chapterContent": [
          {
            "lectureId": "lec_001",
            "lectureTitle": "Welcome to the Course",
            "lectureDuration": 5,
            "lectureUrl": "https://example.com/videos/welcome.mp4",
            "isPreviewFree": true,
            "lectureOrder": 1
          },
          {
            "lectureId": "lec_002",
            "lectureTitle": "Setting Up Your Development Environment",
            "lectureDuration": 12,
            "lectureUrl": "",
            "isPreviewFree": false,
            "lectureOrder": 2
          }
        ]
      },
      {
        "chapterId": "ch_002",
        "chapterOrder": 2,
        "chapterTitle": "HTML Fundamentals",
        "chapterContent": [
          {
            "lectureId": "lec_003",
            "lectureTitle": "HTML Basics and Structure",
            "lectureDuration": 18,
            "lectureUrl": "https://example.com/videos/html-basics.mp4",
            "isPreviewFree": true,
            "lectureOrder": 1
          },
          {
            "lectureId": "lec_004",
            "lectureTitle": "Working with Forms and Inputs",
            "lectureDuration": 22,
            "lectureUrl": "",
            "isPreviewFree": false,
            "lectureOrder": 2
          }
        ]
      }
    ],
    "averageRating": 4.7,
    "totalRatings": 342,
    "totalLectures": 156,
    "totalDurationMinutes": 1840,
    "educatorId": {
      "_id": "65f8a1b2c3d4e5f6a7b8c9d0",
      "name": "John Smith",
      "imageUrl": "https://example.com/profiles/john-smith.jpg"
    },
    "totalEnrolledStudents": 1523,
    "createdAt": "2024-03-15T10:30:00.000Z",
    "updatedAt": "2024-03-20T14:22:00.000Z"
  }
}

Error Responses

{
  "success": false,
  "message": "Course not found"
}

Error Codes

200
Success (with error message)
The request was processed successfully, but the course was not found. Check the success field and message in the response.
500
Internal Server Error
An unexpected error occurred while fetching the course. This typically indicates a database connection issue, invalid ObjectId format, or server error.

Implementation Notes

  • Both published and unpublished courses can be retrieved with this endpoint
  • The following fields are excluded from the response:
    • courseRatings (individual user ratings array)
    • enrolledStudents (list of enrolled student IDs)
  • The educatorId field is populated with basic educator information (name and image)
  • Free Preview Protection: Lectures where isPreviewFree is false will have their lectureUrl field set to an empty string to prevent unauthorized access
  • If an invalid MongoDB ObjectId is provided, a 500 error will be returned
  • The course content structure is fully included, allowing clients to build course curriculum displays

Code Examples

const courseId = '65f8a2b3c4d5e6f7a8b9c0d1';
const response = await fetch(`https://api.skillrise.com/api/course/${courseId}`);
const data = await response.json();

if (data.success) {
  const course = data.courseData;
  console.log(`Course: ${course.courseTitle}`);
  console.log(`Instructor: ${course.educatorId.name}`);
  console.log(`Chapters: ${course.courseContent.length}`);
  
  // Calculate total lectures
  const totalLectures = course.courseContent.reduce(
    (sum, chapter) => sum + chapter.chapterContent.length,
    0
  );
  console.log(`Total lectures: ${totalLectures}`);
  
  // Get free preview lectures
  const freeLectures = course.courseContent.flatMap(chapter =>
    chapter.chapterContent.filter(lecture => lecture.isPreviewFree)
  );
  console.log(`Free preview lectures: ${freeLectures.length}`);
} else {
  console.error('Error:', data.message);
}

Use Cases

Display Course Details Page

const CourseDetailsPage = async ({ courseId }) => {
  const response = await fetch(`https://api.skillrise.com/api/course/${courseId}`);
  const { success, courseData } = await response.json();
  
  if (!success) {
    return { error: 'Course not found' };
  }
  
  return {
    title: courseData.courseTitle,
    description: courseData.courseDescription,
    thumbnail: courseData.courseThumbnail,
    instructor: {
      name: courseData.educatorId.name,
      image: courseData.educatorId.imageUrl
    },
    pricing: {
      original: courseData.coursePrice,
      discount: courseData.discount,
      final: courseData.coursePrice * (1 - courseData.discount / 100)
    },
    stats: {
      rating: courseData.averageRating,
      totalRatings: courseData.totalRatings,
      students: courseData.totalEnrolledStudents,
      lectures: courseData.totalLectures,
      duration: courseData.totalDurationMinutes
    },
    curriculum: courseData.courseContent
  };
};

Show Free Preview Content

const getFreePreviews = async (courseId) => {
  const response = await fetch(`https://api.skillrise.com/api/course/${courseId}`);
  const { success, courseData } = await response.json();
  
  if (!success) return [];
  
  const freeLectures = [];
  
  courseData.courseContent.forEach(chapter => {
    chapter.chapterContent.forEach(lecture => {
      if (lecture.isPreviewFree && lecture.lectureUrl) {
        freeLectures.push({
          chapterTitle: chapter.chapterTitle,
          lectureTitle: lecture.lectureTitle,
          duration: lecture.lectureDuration,
          url: lecture.lectureUrl
        });
      }
    });
  });
  
  return freeLectures;
};

Build Course Table of Contents

const buildTableOfContents = async (courseId) => {
  const response = await fetch(`https://api.skillrise.com/api/course/${courseId}`);
  const { success, courseData } = await response.json();
  
  if (!success) return null;
  
  return courseData.courseContent.map(chapter => ({
    id: chapter.chapterId,
    title: chapter.chapterTitle,
    order: chapter.chapterOrder,
    lectures: chapter.chapterContent.map(lecture => ({
      id: lecture.lectureId,
      title: lecture.lectureTitle,
      duration: lecture.lectureDuration,
      isFree: lecture.isPreviewFree,
      isLocked: !lecture.lectureUrl,
      order: lecture.lectureOrder
    })).sort((a, b) => a.order - b.order)
  })).sort((a, b) => a.order - b.order);
};