lchallen
Community Contributor

Hi  @James ,

Very helpful, I updated the payload and added in those copy parameters and tested it - all seems to work fine and no calendar events so question answered. I have included the updated code below. My next step is to read in a CSV file of old and new courses to automate our course rollover process. If anybody is interested in the complete end code let me know and I'll keep you updated. In the meantime here is what I have right now (you can see the additional parameters in line 7):

import requests
import time

token='token 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','copy[all_course_settings]':'1','copy[all_syllabus_body]':'1','copy[all_context_modules]':'1','copy[all_assignments]':'1','copy[all_quizzes]':'1','copy[all_assessment_question_banks]':'1','copy[all_discussion_topics]':'1','copy[all_wiki_pages]':'1','copy[all_context_external_tools]':'1','copy[all_rubrics]':'1','copy[all_attachments]':'1'}
    r = requests.post('https://yourinstitution.instructure.com/api/v1/courses/'+ 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']

        time.sleep(2)

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


migrateContents(1840,3595)
#first number is source course and second is destination

View solution in original post

Who Me Too'd this solution