Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.easelms.org/llms.txt

Use this file to discover all available pages before exploring further.

List Enrollments

Retrieves all enrollments for the authenticated user.

Response

enrollments
array
Array of enrollment objects

Example Request

curl https://your-domain.com/api/enrollments

Example Response

{
  "enrollments": [
    {
      "id": 1,
      "user_id": "uuid-here",
      "course_id": 42,
      "status": "active",
      "progress": 65,
      "enrolled_at": "2024-01-15T10:30:00Z",
      "completed_at": null,
      "courses": {
        "id": 42,
        "title": "Introduction to Programming",
        "image": "https://example.com/image.jpg"
      }
    }
  ]
}

Create Enrollment

Enrolls a user in a course. Checks prerequisites and updates enrollment count.

Request Body

courseId
number
required
Course ID to enroll in
userId
string
Admin only: Enroll another user by their UUID
bypassPrerequisites
boolean
Admin only: Skip prerequisite checks (default: false)

Response

enrollment
object
Created enrollment object

Example Request

curl -X POST https://your-domain.com/api/enrollments \
  -H "Content-Type: application/json" \
  -d '{
    "courseId": 42
  }'

Example Response

{
  "enrollment": {
    "id": 1,
    "user_id": "uuid-here",
    "course_id": 42,
    "status": "active",
    "progress": 0,
    "enrolled_at": "2024-01-15T10:30:00Z"
  }
}

Update Enrollment Status

Updates the status of an enrollment (e.g., mark as completed).

Request Body

courseId
number
required
Course ID
status
string
required
New status: “active”, “completed”, “suspended”

Response

enrollment
object
Updated enrollment object

Example Request

curl -X PATCH https://your-domain.com/api/enrollments \
  -H "Content-Type: application/json" \
  -d '{
    "courseId": 42,
    "status": "completed"
  }'

Notes

  • Setting status to “completed” automatically sets completed_at timestamp and progress to 100%
  • Triggers email notifications for course completion
  • Sends admin notification about the completion

Prerequisite Validation

When enrolling in a course with prerequisites, the API validates:
  1. All prerequisite courses must be completed
  2. Completion is verified by completed_at timestamp being set
  3. In-progress enrollments are not sufficient

Prerequisite Error Response

{
  "error": "Prerequisites not met",
  "missingPrerequisites": [
    {
      "id": 10,
      "title": "Introduction to Programming",
      "status": "not_started"
    },
    {
      "id": 15,
      "title": "Basic JavaScript",
      "status": "in_progress"
    }
  ]
}

Enrollment Notifications

The API automatically triggers email notifications:
  • On Enrollment: Welcome email with course access details
  • On Completion: Congratulations email with certificate link (if enabled)
  • Admin Notification: Notifies admin when a user completes a course

Admin Enrollment

Admins can enroll other users by providing the userId parameter:
curl -X POST https://your-domain.com/api/enrollments \
  -H "Content-Type: application/json" \
  -d '{
    "courseId": 42,
    "userId": "target-user-uuid",
    "bypassPrerequisites": true
  }'

Error Codes

Status CodeDescription
200Success
400Bad Request - Prerequisites not met or invalid parameters
401Unauthorized - Authentication required
403Forbidden - Admin access required
404Not Found - Enrollment or course not found
409Conflict - User already enrolled
500Internal Server Error