Overview
Thelms-progress API provides a unified endpoint for retrieving progress, enrollment, and financial metrics across the platform. The Teacher and Admin Dashboards use this data to display performance statistics.
The endpoint returns two datasets:
- Overall — Aggregated metrics for the entire platform.
- Per category — Detailed metrics broken down by course category.
Authentication
The API supports two methods of authentication:- API Key (Recommended for server-to-server) — Pass your API key in the
x-api-keyheader. - Session Cookie (For frontend clients) — Pass the browser session cookie.
Method 1: Using an API Key (Recommended)
Generate an API Key in the Kunci API sidebar under the Teacher Dashboard. Once generated, include it in your HTTP requests using thex-api-key header:
Method 2: Using Session Cookies (Development)
To test the endpoint locally or via curl using browser cookies:- Sign in to the LMS dashboard via your browser.
- Open the browser’s developer tools and copy the session cookie value (usually named
authjs.session-tokenor similar). - Run the curl command below, replacing
<cookie-value>with your token:
Requesting from the browser (Frontend)
When fetching the API from frontend React components, you must include credentials. This ensures the browser attaches session cookies to the request.Frontend integration guide
Use these TypeScript interfaces and React hooks to integrate the progress metrics into your dashboard page.TypeScript type definitions
Define the structure of the API response to ensure strict type safety.Code example: React fetch hook
This example shows a custom React state approach to fetch, handle errors, and manage loading states:Technical calculation logic
The backend uses Drizzle ORM to perform queries and aggregates. Here is how the complex metrics are processed:Completion rate calculation
To calculate thecompletionRate, the API computes the progress of each student in each enrolled course and averages them. It runs a SQL CTE (Common Table Expression) to perform the math:
- Calculate total chapters per course: Counts all chapters within modules mapped to the course.
- Calculate completed chapters per student:
Counts unique records in
student_progresswherecompleted = true. - Compute enrollment progress:
Divides the completed chapters by the total chapters. If a course has 0 chapters, progress defaults to
0. - Average the progress: Calculates the average progress across all enrollments.