Skip to content

Instantly share code, notes, and snippets.

@jstanley0
Forked from anonymous/canvas module sequence API
Last active December 21, 2015 09:39
Show Gist options
  • Save jstanley0/6286520 to your computer and use it in GitHub Desktop.
Save jstanley0/6286520 to your computer and use it in GitHub Desktop.

We need an API for the module sequence footer (the navigation at the bottom of an assignment, discussion, etc., that links to the previous and next items in the course module sequence).

How should we specify the object we want sequence information for?

The non-API endpoint takes an asset tag. An API call like this would look something like:

(A) GET /api/v1/courses/123/module_sequence/assignment_456

Or maybe we would rather see:

(B) GET /api/v1/courses/123/module_sequence?asset_type=Assignment&asset_id=456

Or maybe we would rather see:

(C) GET /api/v1/courses/123/assignments/456/module_sequence

Of course, this requires a route for each kind of asset that can be in a module.

/api/v1/courses/:course_id/files/:file_id/module_sequence /api/v1/courses/:course_id/pages/:url/module_sequence /api/v1/courses/:course_id/discussion_topics/:topic_id/module_sequence /api/v1/courses/:course_id/assignments/:assignment_id/module_sequence /api/v1/courses/:course_id/quizzes/:quiz_id/module_sequence /api/v1/courses/:course_id/external_tools/:external_tool_id/module_sequence /api/v1/courses/:course_id/modules/:module_id/items/:module_item_id/module_sequence

That last endpoint is the only one that is unambiguous when items are added to multiple modules (or more than once to the same module). Should the others return multiple sequences (one for each place the asset is used)? The first one? The first locked one? None? ("None" is most consistent with the non-API behavior.)

Next question: what should this API return?

The non-API endpoint returns complete JSON representations of three content tags (previous, current, and next module items), and two modules (previous and next; oddly not current, even though both the previous and next items are likely to be in the current module).

It's possible we could get by with a more minimal return, but I lean toward returning full API module item objects for the previous and next items. That way, callers can use the html_url to link to the Canvas web page, or the url to get the API object, or maybe they're just interested in the type and ID.

I'm not certain we need to return full module objects. But maybe we do want the title and ID of the module to associate with the returned module items. (Possibly we want the module's ID to be returned the module item JSON. It isn't currently.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment