cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
hztasker07
Community Member

Selective Content Migrations in Canvas REST API

Hi, everyone!

I'm an instructional admin and I've been working with the Canvas API using Python3  -- essentially putting post and get requests in a python wrapper.

I suppose I have two questions here: Firstly, in the past I have been using the copy_course API endpoint as in, 

```payload={'source_course':str(original_course_id),'only[]':'modules'}
requests.post('https://mydomain.instructure.com/api/v1/courses/'+ str(destination_course_id)+ '/course_copy', params=payload, headers = {'Authorization': 'Bearer ' + API_KEY})```

However, this is deprecated and I can't select only one module to import/copy into the course (which is what I really want to do).

My first question is, how in the world do I format my request using the content_migrations endpoint for a course_copy_importer type? I'm guessing it's something like: 

```payload={'migration_type':'course_copy_importer','source_course':str(original_course_id),'select':'modules'}
requests.post('https://mydomain.instructure.com/api/v1/courses/'+ str(destination_course_id)+ '/content_migrations', params=payload, headers = {'Authorization': 'Bearer ' + API_KEY})```

but I’m getting 422s.

My second question is, how should I format my post request when I want to do a selective module import (i.e., I only want to import the first module in a parent course)? I get that the module value should be of type hash, but I'm really scratching my head over how to get the hash, and how to input that into the request. Should I be putting in something like `

``payload= {'source_course':str(original_course_id),'select':1aedffeeds}```

where 1aedffeeds is a placeholder for a hash value? Or should it be a sub-dictionary with ```'module'``` as the key and a hash value?

Again, I'm ultimately looking to simply import one module using the content_migrations endpoint, but any help would be welcomed!

Apologies for being a bit of a newb here.

0 Kudos
4 Replies
cbirdsong
Community Participant

I'm having the same issue. I use Postman so I just need to know what to put in as the Key and the Value. According to Canvas' API docs, to use Select, you have to use the object type as the key ('announcements', 'quizzes', etc), and the object id as the value. This is not working when I run the call, so obviously some critical info is missing from the API docs. Would love to get this resolved. 🙂

hztasker07
Community Member

Hmm, well your response is validating, at least. To be transparent, I'm responding to this so it has more comments (and hopefully gets more visibility). I've taken a break from this specific project, but I promise to let you know if I "crack" it once I return to it.

cbirdsong
Community Participant

I even had a Canvas API trainer working with me the other day and he couldn't get it to work either. Canvas' docs need to be more specific in this area.

Alexandre_Sch
Community Contributor

Hi, 

 

I'm trying to run a Postman Post using the content_migrations and got the same issue. Dont know what to use on params -> select...  I know the id's and page names that i want to copy, but need to know how to design it inside postman to make it work. 

 

So far: /api/v1/courses/xxxx/content_migrations?migration_type=course_copy_importer&settings[source_course_id]=xxxx&select=????

 

Edit: 

 

Tried this and got a 200 response

Alexandre_Sch_0-1610973218620.png

 

 

{
"id": xxxxx,
"user_id": xxxxx,
"workflow_state": "running",
"started_at": "2021-01-18T12:31:54Z",
"finished_at": null,
"migration_type": "course_copy_importer",
"created_at": "2021-01-18T12:31:54Z",
"migration_issues_url": "xxxxx/content_migrations/xxxxxx/migration_issues",
"migration_issues_count": 0,
"settings": {
"source_course_id": xxxx,
"source_course_name": "xxxxx",
"source_course_html_url": "xxxx"
},
"progress_url": xxxxxx",
"migration_type_title": "course_copy"
}

But, as the response show, the Select params are been ignored and not created on Canvas.

A course_copy has been created, but not quizzes imported.

Alexandre_Sch_1-1610973344353.png