AnsweredAssumed Answered

Use the Content Migration API to copy courses but without their calendar events (or remove them after)

Question asked by Lawrence Challen on Feb 19, 2018
Latest reply on May 8, 2018 by Lawrence Challen



My end goal is to make a script that copies over courses without calendar events.


I have edited a script I found to use the content_migration api call to copy a canvas course from an old one to a new one. I have also explored using the course_copy api call to copy the course without calendar events but I can see it's been retired for a reason - other settings are not coming through and you are left with the default module view.


My long winded solution is to somehow use the content_migration and then check the course for calendar events without dates and remove them... Seems like a really long workaround and, as a total novice, I'm not even sure how to get a list of calendar events by course.


I saw an old feature request asking for a solution here but nothing else helpful. 


Does anybody else have any ideas or solutions?


Also - thanks to whoever originally made the code that I've based this all on.


import requests
import time

token='token goes here'

def migrateContents(old_course, new_course):
    payload={'migration_type':'course_copy_importer','settings[source_course_id]': str(old_course), 'date_shift_options[remove_dates]': 'True'}
    r ='https://your'+ str(new_course)+ '/content_migrations/', params=payload, headers = {'Authorization': 'Bearer ' + token})
    data = r.json()
    print data
    progress_url = data[u'progress_url']
    print "Migration URL is: " + str(progress_url)

    progress = 0
    while progress != 100:
        progress_check = requests.get(progress_url, headers = {'Authorization': 'Bearer ' + token})
        progress_result = progress_check.json()
        print "Migration Status is: " + str(data[u'workflow_state']) + ", | progress: " + str(progress_result[u'completion']) + "%"
        #print progress_result
        progress = progress_result[u'completion']


        if progress_result[u'completion'] == 100:
                print "------------------------------"
                print "Migration completed."

def copyContents(old_course, new_course):
    payload={'source_course':str(old_course),'except[]': 'calendar_events'}
    r ='https://your'+ str(new_course)+ '/course_copy/', params=payload, headers = {'Authorization': 'Bearer ' + token})
    data = r.json()
    print data

#comment out the def you don't want to call before running!