How to enroll user using the REST API?
-
I’m trying to use litfer-lms as a headless with my next.js application. I want to enrol users grammatically, the problem is when I make the request, I get:
code: 'llms_rest_unauthorized_request', message: 'Sorry, you are not allowed to create an enrollment as this user.',
function getAuthHeader() { const username = process.env.LIFTER_LMS_CONSUMER_KEY as string; const password = process.env.LIFTER_LMS_CONSUMER_SECRET as string; const authString =
${username}:${password}
; const base64AuthString = Buffer.from(authString).toString("base64"); returnBasic ${base64AuthString}
; } class LMSHeadlessAPI { /** * Axios instance for making HTTP requests to the LifterLMS Headless API. */ private static api: AxiosInstance = axios.create({ baseURL: process.env.NEXT_PUBLIC_WORDPRESS_URL +/wp-json/llms/v1
, headers: { Authorization: getAuthHeader(), }, }); static async enrollInCourse(params: Enrollment): Promise<void> { try { const url =/students/${params.userId}/enrollments/${params.courseId}
; const a = await LMSHeadlessAPI.api.post(url); } catch (err) { const error = err as AxiosError; console.log("err", err); LMSHeadlessAPI.handleError(error); } }I added the code above of how I make the request. I maybe the request should include any info about the user? or cookie or something? I don’t know because the doc didn’t say anything about that.
this is the endpoint I’m using:
https://developer.lifterlms.com/rest-api/#tag/Student-Enrollments/paths/~1students~1{id}~1enrollments~1{post_id}/post
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘How to enroll user using the REST API?’ is closed to new replies.