Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
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.
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!
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!
Thanks, Matt. It worked. I really appreciate your help!
Hi Matt,
I have the same issue, the user can not be removed, here is the code.
def RemoveATeacherFromACourse(mycourseid,userid):
removeuserurl = url+'/api/v1/courses/'+ str(mycourseid)+'/enrollments/'+ str(userid)
print(adduserurl)
payload = {'task' : 'delete'}
remove_response = requests.delete(removeuserurl, headers=headers,params=params,data=payload)
print('removed')
return remove_response
could you help?
li
I think I see the problem in your code. It appears you are sending a userID when you actually need be sending an enrollmentID. It's an annoying extra step, but you have to do a GET call on that person's enrollment to get the enrollment ID you need to remove them.
it worked. thank you so much!
li
To participate in the Instructure Community, you need to sign up or log in:
Sign In