Skip to main content
GET
/
api
/
user
/
certificate
/
:courseId
Get Certificate
curl --request GET \
  --url https://api.example.com/api/user/certificate/:courseId
{
  "Student Name": "<string>",
  "Course Title": "<string>",
  "Completion Date": "<string>",
  "Certificate ID": "<string>",
  "Certificate Verification Link": "<string>"
}

Overview

Generates and returns a PDF certificate for a completed course. The certificate includes the student’s name, course title, completion date, and a unique certificate ID.
Certificates are automatically generated when a user completes 100% of a course’s lectures.

Authentication

Requires Clerk authentication. The user must be enrolled in the course and have completed all lectures.

Path Parameters

courseId
string
required
The MongoDB ObjectId of the course

Response

Returns a PDF certificate file with appropriate headers.

Success Response (200)

Content-Type: application/pdf
Content-Disposition: attachment; filename="SkillRise_Certificate_[CourseTitle].pdf"
The response body contains the PDF binary data.

Certificate Contents

The generated certificate includes:
Student Name
string
The authenticated user’s full name from Clerk
Course Title
string
The completed course title
Completion Date
date
The date when the course was completed (last lecture marked as completed)
Certificate ID
string
A unique identifier stored in the database for verification
A URL that can be used to verify the certificate’s authenticity

Error Responses

404 Not Found
  • User is not enrolled in the course
  • Course does not exist
  • User has not completed the course
500 Internal Server Error
Error generating the PDF certificate

Implementation Details

Certificate Generation Process

  1. Verify enrollment: Check that the user is enrolled in the course
  2. Check completion: Verify that all lectures are marked as completed
  3. Retrieve certificate record: Look up the Certificate model entry
  4. Generate PDF: Use Puppeteer to render HTML template as PDF
  5. Return file: Stream the PDF to the client

Database Model

Certificates are stored in the Certificate collection:
{
  userId: String,          // Clerk user ID
  courseId: ObjectId,      // Reference to Course
  certificateId: String,   // Unique verification ID
  issuedDate: Date,        // Completion date
  userName: String,        // Student name
  courseName: String       // Course title
}

Code Examples

const response = await fetch(
  `${BACKEND_URL}/api/user/certificate/${courseId}`,
  {
    headers: {
      'Authorization': `Bearer ${clerkToken}`
    }
  }
);

if (response.ok) {
  const blob = await response.blob();
  const url = window.URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = url;
  a.download = `SkillRise_Certificate_${courseTitle}.pdf`;
  a.click();
}

Use Cases

  1. Student downloads certificate after completing a course
  2. Share on LinkedIn by uploading the generated PDF
  3. Verify certificate authenticity using the certificate ID
  4. Track student achievements via the Certificate collection