How can I programmatically unenroll users as an admin (not as the learner) in Open edX?

Hello everyone :waving_hand:

I’m currently integrating Open edX with an external backend (built in Node.js) and I’m trying to programmatically unenroll users from courses as an administrator or staff user.

So far, I’ve tested several endpoints:

  • POST /change_enrollment → works only when the user themselves is logged in (not as admin).

  • DELETE /api/enrollment/v1/enrollment → returns 405 Method Not Allowed on my instance.

  • PATCH /api/enrollment/v1/enrollment → also 405 Method Not Allowed.

I know the Instructor Dashboard → Membership → Unenroll button performs a real unenrollment, but I’d like to reproduce that behavior via API or script — using admin credentials or a service account — without logging in as the learner.

:magnifying_glass_tilted_left: My question:
Is there an officially supported API endpoint or a recommended approach to unenroll a user as admin/staff (e.g., the same one used by the instructor dashboard’s “Unenroll” button)?

If not, would the correct approach be to directly call CourseEnrollment.unenroll(user, course_id) through a Django management command or a custom REST endpoint?

Any pointers to documentation, code references, or working examples (for current Open edX releases) would be greatly appreciated :folded_hands:

Environment:

  • Tutor (local) deployment

  • Open edX Palm (or later)

  • Using LMS REST APIs via admin session (CSRF + cookies)

Thanks in advance for your help!

@feanil do you know if such an endpoint exists?

I’m not exactly certain about this, haven’t tried any of it at all, but from what I can piece together you’ll need to use the /api/enrollment/v1/enrollment endpoint with a POST request with the key parameter used being is_active set to false.

There’s also a bulk enrollment api that can be enabled and used for unenrollment (according to this topic here: Programatically enroll or unenroll students)

1 Like

Hi @Edwin75206 ,

you can call /api/bulk_enroll/v1/bulk_enroll/ with action=unenroll. Check how we resolved it here: openedx-rest-api-client/openedx_rest_api_client/client.py at 63795dba8a74d7e6d11dc42355937561076ec932 · aulasneo/openedx-rest-api-client · GitHub

1 Like