API Delete Enrollment using Python Requests?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to write a script to remove me from courses that I get enrolled in as an admin when I create a new course. I'm trying to use the Python Requests to delete the enrollment. When I do it through my python script, it only concludes the enrollment (so it stays on my list) instead of deleting it. At least then I'm not getting notifications or visible to students.
json_headers = {'Authorization' : 'Bearer ' + api_token}
def api_unenroll_admin_course(course_id, enrollment_id):
enroll_url = url + "/courses/" + str(course_id) + "/enrollments/" + str(enrollment_id)
print(enroll_url)
payload = {'enrollment[task]' : 'delete'}
print(payload)
r_delete = requests.delete(enroll_url, headers=json_headers, data=payload)
print(r_delete.text)
print(r_delete.url)
print(r_delete)
when I do it using PostMan as shown below, it actually deletes the enrollment (but I have to go look up each enrollment ID and then go run each delete call).
Does anyone have ideas about what I am doing wrong? I think I'm leaving something out of the python code but not sure what.
Thanks!
Joni
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I didn't test this but it appears that your payload would need to be changed to
payload = {'task' : 'delete'}
That would match your postman script. I think the server is ignoring your payload because it isn't formatted correctly and if the "task" argument that it's expecting isn't given, it concludes the enrollment instead of deleting.
Hope that helps!