Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
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.
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. 🙂
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.
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.
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
{
"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.
I'm trying to copy an assignment from one course to another (API content_migration). Like hztasker07, I do not understand how to set up the 'select' parameter in the payload. I don't see where (how) to get a "hash" for the specific assignment. The API documentation (content_migration, request parameter: select) makes no sense .." The keys are object types like 'files', 'folders', 'pages', etc. The value for each key is a list of object ids. An id can be an integer or a string." Anyone successful? Migrating a Page, an Assignment, or anything?
I am trying to do the same thing. Has this been resolved?
I have gotten this to partially work, but even if selecting just one sub-item for assignments, as an example, it will bring the entire group of assignments.
This is a multi-step process:
Create a content migration
https://canvas.instructure.com/doc/api/content_migrations.html#method.content_migrations.create
POST /api/v1/courses/<receiving_course_id>/content_migrations
JSON BODY:
{"migration_type": "course_copy_importer",
"settings": {"source_course_id": <course_id_that_has_content>}
}
From the json returned, grab the id (this is the migration ID)
List items for selective import
https://canvas.instructure.com/doc/api/content_migrations.html#method.content_migrations.content_lis...
GET /api/v1/courses/<receiving_course_id>/content_migrations/<migration_id>/selective_data
From the json returned, grab the property for the item / subitem
Update to import items
https://canvas.instructure.com/doc/api/content_migrations.html#method.content_migrations.update
PUT /api/v1/courses/<receiving_course_id>/content_migrations/<migration_id>
JSON BODY
{"copy[assignments][<id_here>]": 1}
To participate in the Instructure Community, you need to sign up or log in:
Sign In