cancel
Showing results for 
Search instead for 
Did you mean: 
bpoullio1
Surveyor II

Using Content Migrations API to copy courses w/o Announcements?

Jump to solution

I'm looking for a little more clarity on the Content Migrations API. I can usually rely on documentation, but for these enpoints, it's woefully lacking. I've figured out how to do a couple things thanks to a previous post about setting up Content Migrations.

  1. Start a content migration
  2. Include/exclude based on certain categories (e.g., the components listed in the copy JSON array)

Does anybody know if this can be broken down in any additional way? There are no examples of how to use the "select" parameter or how to select as you would in the UI. Does anybody have any idea of how to select specific content without object IDs? I'm hoping to write a script that will:

  1. Start a content migration
  2. Exclude Announcements
  3. Set old start date and end date
  4. Set new start date and end date

I know how to do all except number 2. Is it possible? 

1 Solution

Accepted Solutions
James
Navigator

 @bpoullio1  

The create a content migration endpoint allows you to do a selective import. One of the values that you can pass for the select hash is announcements. It seems like you might be able to list all the other values you want and then not include announcements.

The select is a hash. When you import a course, Canvas had used the PUT version to modify an existing migration and it sent a copy property instead of select, but it's likely to work the same way.

When I told it to copy content pages and announcements, it looked like this and I would try the same thing with select.

copy: {all_wiki_pages: "1", all_announcements: "1"}

If you want to exclude all announcements, I would first try all_announcements: "0". Based on the comment I left in February 2018, you might just leave out all_announcements to not get it copied.

I have had other issues with selective contents -- the one I'm thinking of is that it doesn't include and set the course grading scheme. So, I've started doing complete course copies and then deleting then things that I don't want to keep. If you find that's an issue, you may want to copy the entire course, then go back after the import is done and delete the announcements.

View solution in original post

8 Replies
James
Navigator

 @bpoullio1  

The create a content migration endpoint allows you to do a selective import. One of the values that you can pass for the select hash is announcements. It seems like you might be able to list all the other values you want and then not include announcements.

The select is a hash. When you import a course, Canvas had used the PUT version to modify an existing migration and it sent a copy property instead of select, but it's likely to work the same way.

When I told it to copy content pages and announcements, it looked like this and I would try the same thing with select.

copy: {all_wiki_pages: "1", all_announcements: "1"}

If you want to exclude all announcements, I would first try all_announcements: "0". Based on the comment I left in February 2018, you might just leave out all_announcements to not get it copied.

I have had other issues with selective contents -- the one I'm thinking of is that it doesn't include and set the course grading scheme. So, I've started doing complete course copies and then deleting then things that I don't want to keep. If you find that's an issue, you may want to copy the entire course, then go back after the import is done and delete the announcements.

View solution in original post

 @James ‌

Thanks for your response! I think where I'm struggling is there aren't any examples of what this should look like. I tried using select, but was unable to format it so that anything happened; the course copy simply stalled at waiting to select content. Reading the documentation, the select hash is supposed to be object IDs, which doesn't lend itself to re-use for more than one application.

I'll give the copy hash a try, that seems to be the clearest solution posed so far. Slightly frustrating that it's not documented. I saw mention elsewhere of using an exclude parameter...is that a possibility? Have you seen anything of the sort?

exclude: {announcements: "1"}

Definitely happy to create something more verbose if necessary, but explicitness is definitely preferred when choosing the parameters. Out of curiosity, how did you figure out about the copy hash? I don't see it documented anywhere and the community posts were the only way I saw anything about it...

 @bpoullio1  

Do you know where you saw the exclude ? I mentioned it in the first thread as a "if exclude was there, it would make life easier." As far as I know, the conditional portion of that sentence is false.

I did a search through the source code for :exclude, which is how parameters are most likely to show up. For the migrations, the only place it showed up was for vericite_settings. Definitely not what we're looking for here.

The select only works under certain conditions. According to the source, it needs to have a migration_type of 'course_copy_importer' to read what's supplied under select. Otherwise, it will most likely use copy instead. What Canvas does is to start the migration and then come back with a PUT to update it and specify the content.

I figure out a lot of the API call stuff by going to the browser's developer tools (F12) and the Network tab. I set Canvas up to do what I want to emulate, then clear out all the stuff in the network tab, and then click the button for Canvas to do it's thing. The first new entry is what the web interface is sending back to the server and so that's what I try to mimic. You can also often filter by the XHR requests to cut down on the noise.

The Headers tab (in Chrome) is what you're after. The general section has the URL and then there is a Request Headers section that shows what was sent to the server.

In the case of a redirect or page refresh, I tell the developer tools to use persistent logs (the wording varies) so that it won't disappear when the page loads.

I've been trying to figure out the best way to approach this for a hot minute now, so I may have read your reference and logged it in my brain as "this exists somewhere" despite that not being the case. I can't locate it now, regardless. I'll see if I can find the info I'm looking for through the developer tools, but sounds like you may have already provided the best approach. Thanks for your responses!

UPDATE: I had my first opportunity to give copy[all_announcements]: 0 a shot using Postman to test (and speed up) some processes before I have time to build. I copied a full course minus announcements using this syntax. Definitely important to document that this answer worked, so thank you again  @James ‌!

I'm glad that option works. It's good to be able to exclude things, even if you can't use the word exclude itself.

Hi Brandon,

Would you mind sharing how you had your Postman request set up (i.e. a screenshot with api key removed)? This seems like something very useful to me as I also like to copy course content forward sans announcements.

Thanks in advance.

@themidiman I'm so sorry I missed this! I took the standard call in the documentation and added things I was interested in to the query params below. I use a variable for my domain and undeclared variables for anything I want to use the Runner on in Postman. This allows me to create a CSV that has only the info that changes for each copy. In this case, I used undeclared variables for source_id for the source course, old_start, old_end, new_start, new_end, and course_id. The dates all have to do with shifting dates from a previous semester's course and could be omitted if you're not interested in shifting dates. Here's a screenshot for anybody who comes back this way. I always hate never having a resolution...

Screen Shot 2021-01-21 at 10.14.52 AM.png