AnsweredAssumed Answered

API Delete Enrollment using Python Requests?

Question asked by Joni Miller Expert on May 3, 2018
Latest reply on May 7, 2018 by Joni Miller

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

Outcomes