AnsweredAssumed Answered

API Delete Enrollment using Python Requests?

Question asked by Joni Miller Expert on May 3, 2018
Latest reply on Jan 27, 2019 by Li Zhu

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)
    payload = {'enrollment[task]' : 'delete'}
    r_delete = requests.delete(enroll_url, headers=json_headers, data=payload)



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.