Brightspace APIs expose functionality to allow users to add and remove content from courses. The following examples show how these APIs could be used to create a standard outline for a course.
Suppose all courses must have the following modules:
- Introduction
- Marking Scheme
- Midterm Review
- Exam Review
If we have a list of courses identified by their Org Unit ID we can check to see if there is any content assigned and modify them as required.
We can consult the Valence documentation for routes that let us manipulate course content.
First we'll retrieve the current content for a course with an Org Unit ID of 121535.
GET /d2l/api/le/1.0/121535/content/root/200 OK[{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": 97657,"Title": "Customs","ShortTitle": "","Type": 0}]
There appears to already be a module created for this course. Let's delete it before we add our own modules.
DELETE /d2l/api/le/1.0/121535/content/modules/97657200 OK
If we re-check the course content root we should receive an empty array.
GET /d2l/api/le/1.0/121535/content/root/200 OK[]
Now we're ready to add our own modules.
POST /d2l/api/le/1.0/121535/content/root/{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": null,"Title": "Marking Scheme","ShortTitle": "","Type": 0}200 OKPOST /d2l/api/le/1.0/121535/content/root/{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": null,"Title": "Introduction","ShortTitle": "","Type": 0}200 OKPOST /d2l/api/le/1.0/121535/content/root/{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": null,"Title": "Midterm Review","ShortTitle": "","Type": 0}200 OKPOST /d2l/api/le/1.0/121535/content/root/{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": null,"Title": "Exam Review","ShortTitle": "","Type": 0}200 OK
Now we can recheck the course content root and retrieve the module IDs. (If you're making calls against a version 10.2.0 Learning Environment or later, the calls to create topics and modules should return to you information about each structure as you create them, so you'll have the Module or Topic ID value at that point.)
GET /d2l/api/le/1.0/121535/content/root/200 OK[{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": 97657,"Title": "Introduction","ShortTitle": "","Type": 0},{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": 97658,"Title": "Marking Scheme","ShortTitle": "","Type": 0},{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": 97659,"Title": "Midterm Review","ShortTitle": "","Type": 0},{"Structure": [],"ModuleStartDate": null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": 97660,"Title": "Exam Review","ShortTitle": "","Type": 0}]
Now the course has a standard set of modules created. Let's set the start and end dates for the introduction module.
PUT /d2l/api/le/1.0/121535/content/modules/97657{"Structure": [],"ModuleStartDate": "2013-05-20T13:00:00.000Z","ModuleEndDate": "2013-05-24T22:00:00.000Z","IsHidden": false,"IsLocked": false,"Id": 97657,"Title": "Introduction","ShortTitle": "","Type": 0}200 OK
As a final step let's add a sub-module to the introduction. (Edit: Corrected the route below to POST, rather than PUT.)
POST /d2l/api/le/1.0/121535/content/modules/97657/structure/{"Structure": [],"ModuleStartDate":null,"ModuleEndDate": null,"IsHidden": false,"IsLocked": false,"Id": null,"Title": "Professor-Student Mixer","ShortTitle": "","Type": 0}200 OK
This covers the basics of manipulating modules in a course.