Edit

Admin API

lh.admin manages your organization's learners from your own server: create accounts, enroll them, read and change their progress, award certificates, manage groups, and sign them in. It wraps the headless Admin API (/api/v1/admin/{org_slug}/...), with types generated from the API like the rest of the SDK.

import { createClient } from '@learnhouse/sdk'

const lh = createClient({ baseUrl: process.env.LEARNHOUSE_URL!, token: process.env.LEARNHOUSE_TOKEN! })
const ORG = 'your-school'

const user = await lh.admin.users.provision(ORG, { email: '[email protected]', username: 'ada', first_name: 'Ada' })
await lh.admin.enrollments.enroll(ORG, user.id, 'course_…')
const progress = await lh.admin.progress.get(ORG, user.id, 'course_…')
console.log(progress.completion_percentage)

Auth: an org API token (lh_…) only. Every method takes the token's org slug first; another org's slug, a user session or a missing right answers 403. Users are referenced by their numeric LearnHouse id (user.id). Pro plan on LearnHouse Cloud.

The Right column is the API token permission the method needs (Dashboard → Developers → API Access).

Users

MethodEndpointReturnsRight
users.provision(org, input)POST /admin/{org_slug}/usersAdminUserusers: create
users.getByEmail(org, email)GET /admin/{org_slug}/users/by-email/{email}AdminOrgMemberusers: read
users.update(org, userId, input)PATCH /admin/{org_slug}/users/{user_id}AdminOrgMemberusers: update
users.changeRole(org, userId, roleId)PATCH /admin/{org_slug}/users/{user_id}/role{ user_id, role_id }users: update + roles: update
users.remove(org, userId)DELETE /admin/{org_slug}/users/{user_id}{ detail }users: delete
users.listGroups(org, userId)GET /admin/{org_slug}/users/{user_id}/groupsAdminUserGroupOfUser[]usergroups: read
users.export(org, userId)GET /admin/{org_slug}/users/{user_id}/exportAdminUserExport (everything stored about them)users: read
users.anonymize(org, userId)POST /admin/{org_slug}/users/{user_id}/anonymize{ detail, user_id, anonymized_email, api_tokens_revoked }users: delete

provision input: email, username (required), first_name, last_name, password, role_id, extra_metadata. It creates the account and adds it to the org in one call, with no email verification step (built for SSO / JIT provisioning). An email that already has an account answers 409 (invite that person instead); a taken username 400. Without password, the user signs in with a magic link or SSO.

remove takes the member out of the organization; the account stays. anonymize erases the person's identifying data and can't be undone.

Enrollments

MethodEndpointReturnsRight
enrollments.enroll(org, userId, courseUuid)POST /admin/{org_slug}/enrollments/{user_id}/{course_uuid}AdminTrailcourses: update
enrollments.unenroll(org, userId, courseUuid)DELETE /admin/{org_slug}/enrollments/{user_id}/{course_uuid}{ detail }courses: update
enrollments.listForUser(org, userId)GET /admin/{org_slug}/enrollments/{user_id}AdminTrailcourses: read
enrollments.listForCourse(org, courseUuid, { page, limit })GET /admin/{org_slug}/courses/{course_uuid}/enrollmentsAdminCourseEnrollment[]courses: read
enrollments.bulkEnroll(org, courseUuid, userIds)POST /admin/{org_slug}/enrollments/bulk{ enrolled, already_enrolled, skipped }courses: update
enrollments.bulkUnenroll(org, courseUuid, userIds)POST /admin/{org_slug}/enrollments/bulk/unenroll{ unenrolled, not_enrolled }courses: update
enrollments.checkAccess(org, courseUuid, userId)GET /admin/{org_slug}/courses/{course_uuid}/access/{user_id}{ has_access, is_enrolled, is_public, is_published }courses: read

AdminTrail is the learner's trail, so courseProgress() works on it.

Progress

MethodEndpointReturnsRight
progress.get(org, userId, courseUuid)GET /admin/{org_slug}/progress/{user_id}/{course_uuid}AdminCourseProgresscourses: read
progress.listForUser(org, userId)GET /admin/{org_slug}/progress/{user_id}AdminProgressSummary[], one per enrolled coursecourses: read
progress.getTrail(org, userId)GET /admin/{org_slug}/trails/{user_id}AdminTrailDetail: courses → chapters → activitiescourses: read
progress.getCourseTrail(org, userId, courseUuid)GET /admin/{org_slug}/trails/{user_id}/courses/{course_uuid}AdminTrailDetailcourses: read
progress.completeActivity(org, userId, activityUuid)POST /admin/{org_slug}/progress/{user_id}/activities/{activity_uuid}/complete{ completed, is_new_completion, course_completed }courses: update
progress.uncompleteActivity(org, userId, activityUuid)DELETE …/activities/{activity_uuid}/complete{ completed }courses: update
progress.completeCourse(org, userId, courseUuid)POST /admin/{org_slug}/progress/{user_id}/{course_uuid}/complete{ completed_count, course_completed, certificate_awarded, … }courses: update
progress.reset(org, userId, courseUuid)POST /admin/{org_slug}/progress/{user_id}/{course_uuid}/reset{ steps_deleted }courses: update

AdminCourseProgress has total_activities, completed_activities, completion_percentage and completed_activity_ids. Completing activities from the server fires the same webhooks and certificate logic as a learner doing it.

Certificates

MethodEndpointReturnsRight
certificates.listForUser(org, userId)GET /admin/{org_slug}/certifications/{user_id}AdminCertificate[]certifications: read
certificates.award(org, userId, courseUuid)POST /admin/{org_slug}/certifications/{user_id}/{course_uuid}/award{ user_certification_uuid, user_id, course_uuid }certifications: create
certificates.revoke(org, userId, userCertificationUuid)DELETE /admin/{org_slug}/certifications/{user_id}/{user_certification_uuid}{ detail, user_certification_uuid }certifications: delete

award needs a course with a certificate configured. Anyone can then check it with certificates.verify(); after revoke that returns null.

User groups

MethodEndpointReturnsRight
usergroups.create(org, { name, description })POST /admin/{org_slug}/usergroupsAdminUserGroupusergroups: create
usergroups.delete(org, usergroupUuid)DELETE /admin/{org_slug}/usergroups/{usergroup_uuid}{ detail, usergroup_uuid }usergroups: delete
usergroups.listMembers(org, usergroupUuid, { page, limit })GET /admin/{org_slug}/usergroups/{usergroup_uuid}/membersAdminUserGroupMember[]usergroups: read
usergroups.addMember(org, usergroupUuid, userId)POST …/usergroups/{usergroup_uuid}/members/{user_id}{ status, … }usergroups: update
usergroups.removeMember(org, usergroupUuid, userId)DELETE …/usergroups/{usergroup_uuid}/members/{user_id}{ status, … }usergroups: update
usergroups.addCourse(org, usergroupUuid, courseUuid)POST …/usergroups/{usergroup_uuid}/courses/{course_uuid}{ detail, … }usergroups: update
usergroups.removeCourse(org, usergroupUuid, courseUuid)DELETE …/usergroups/{usergroup_uuid}/courses/{course_uuid}{ detail, … }usergroups: update

Course analytics

courses.analytics(org, courseUuid) returns AdminCourseAnalytics: enrollment_count, completed_count, in_progress_count, total_activities, average_completion_percentage and certificate_count. GET /admin/{org_slug}/courses/{course_uuid}/analytics. Right: courses: read.

Three ways to let one of your users act in LearnHouse. All need users: update, and all refuse org admins, maintainers and platform staff (403): an API token can't take over a privileged account.

MethodWhat you getLifetimeUse it for
auth.magicLink(org, { userId, redirectTo, ttlSeconds, host }){ url, token, expires_at }: a one-time sign-in URL on the org's site60–900 s (default 300)Sending the user into the LearnHouse site, signed in
embed.createSession({ orgSlug, userId, ttlSeconds })A learner session limited to the embed routes60–3600 s (default 900)Your page with @learnhouse/react / @learnhouse/vue
auth.issueToken(org, userId){ access_token, user_id, user_uuid }: a full access token8 hoursCalling the API as the user from your server
// "Continue to your course" button in your app: redirect the browser to link.url.
const link = await lh.admin.auth.magicLink('your-school', { userId, redirectTo: '/course/abc' })

The link works once. redirectTo must be a path on the org's site; host picks one of the org's verified custom domains. A user with two-factor enabled is still asked for their code. Your own frontend can also redeem link.token with auth.verifyMagicLink().

Errors

StatusWhen
401No token, or an invalid, expired or revoked one
403Not an API token, the slug isn't the token's org, the plan lacks the Admin API, the token lacks the right, or the target is privileged
404Unknown user, course, group or certificate, or the user isn't in this org
409users.provision: the email already has an account
429Rate limited; the SDK waits out Retry-After up to maxDelayMs