@kmeeusen ,
Oops - I originally misread External Tool as External URL.I updated the original instructions. Sorry about that.
Yes, it can be done using the API.
Prerequisites
With External Tools, you will need to configure it on the Account Level first before doing this process. You could alternatively put it into each course if the configuration needs to be different for each course. You will need the id of the External Tool for step 3 of the process. You can obtain that through the External Tools API or by adding it to one course and then getting the content_id from List Module Items method in the Module API.
Example: Use the List External Tools method from the External Tools
GET /api/v1/accounts/:account_id/external_tools
You may want to add ?per_page=100 to the end if you have more than 10 external tools and the one you want doesn't show up.
It returns a list of external tools. Find the one that you want and make a note of the id. That will be used in step 3 for the content_id.
Big NOTE! This assumes that you are not actually returning a grade back into the course. If you are, then you need to create an assignment and use the content_id of the assignment rather than the content_id of the external tool. According to the ModuleItem Object documentation, the content_id is the id of the object referred to applies to 'File', 'Discussion', 'Assignment', 'Quiz', 'ExternalTool' types
Procedure
Once you have that prerequisite information, you can do the following:
The flow is like this:
- Obtain a list of courses where you want this to be added and then iterate through them
- Create a module in each course
- Create a module item in the newly created module for each course
- Publish the item and module ???
Step 1: You may already have a list of courses somewhere, if not, you can use the List active courses in an account method from the Accounts API. Specify the enrollment_term_id (using the Canvas ID, not the SIS ID, for the term).
Step 2: Use the Create a module method from the Modules API
POST /api/v1/courses/:course_id/modules
The only required information is the module[name]. You'll want the name to be unique across all the courses and identifiable to the students.
This POST should return a Module object, which will contain an id field. That is the :module_id needed for the next step.
Step 3: Use the Create a module item method from the Modules API
POST /api/v1/courses/:course_id/modules/:module_id/items
You'll want to specify:
- module_item[title] which is how the object displays on the modules page
- module_item[type]=ExternalTool to specify it's an external Tool
- module_item[content_id] contains the content_id of the external tool (see the prerequisite information)
This POST should return a ModuleItem object that will contain an id field that may be needed for the publishing
Step 4: Publish things ???
The create module and create module_item methods don't document a publish feature. That suggests that creating the module and publishing it are two different things. If it turns out that they come out published by default (I haven't tested), then you can skip this step completely.
Test the first three steps for a single course in our test site and see whether or not they come out published. If they don't, then you'll need one or two extra steps.
Step 4a: Use the Update a Module method from the Modules API to publish the module.
PUT /api/v1/courses/:course_id/modules/:id
The :id is the module id found in step 2.
The only thing you should need to put is module[published]=true
Step 4b: Use the Update a Module Item method from the Modules API to publish the External Tool in the module.
If the Publishing of the module automatically updates publishing of everything in it, this step will be unnecessary. But I haven't tested it, so I don't know.
PUT /api/v1/courses/:course_id/modules/:module_id/items/:id
The :course_id is from step 1, the :module_id is from step 2, and the :id is from step 3.
The only thing you should need to put is module[published]=true
Repeat steps 2-4 for each course obtained in step 1.
As with any POST, PUT, or DELETE command, test the whole thing in your test instance first. I generally use the live site if all I'm doing is a GET.