-
Notifications
You must be signed in to change notification settings - Fork 40
ApiMoodle
The following API hooks are supported for Moodle instances:
- Course Groups service
- Membership service (including group information)
- Resource link level
- Context level
The implementation of the Membership service is more equivalent to the unofficial Memberships service extension which includes support for passing group membership data as well as enrolments.
The hooks should be registered as follows:
use ceLTIc\LTI\ApiHook\ApiHook;
use ceLTIc\LTI\Context;
use ceLTIc\LTI\ResourceLink;
Context::registerApiHook(ApiHook::$GROUPS_SERVICE_HOOK, 'moodle', 'ceLTIc\LTI\ApiHook\moodle\MoodleApiContext');
Context::registerApiHook(ApiHook::$MEMBERSHIPS_SERVICE_HOOK, 'moodle', 'ceLTIc\LTI\ApiHook\moodle\MoodleApiContext');
ResourceLink::registerApiHook(ApiHook::$MEMBERSHIPS_SERVICE_HOOK, 'moodle', 'ceLTIc\LTI\ApiHook\moodle\MoodleApiResourceLink');
The following configuration options are supported:
| Name | Required? | Description | Example |
|---|---|---|---|
| moodle.url | Yes | The base URL for the Moodle server | https://myinst.edu/moodle |
| moodle.token | Yes | The web service access token authorising API requests | 53963338ec4b160c1e774060a723c0f3 |
| moodle.grouping_prefix | No | A prefix which a grouping name must match before it is considered to be included in the results | Group |
| moodle.per_page | No | Maximum number of records to be requested per message. The default is 50; use a value of 0 to remove the limit. | 100 |
These configuration options should be saved in the settings area of the platform record; for example:
$platform->setSetting('moodle.per_page', '75');
The options must be specified for each Moodle instance defined within the tool at least the base URL and access token will be different for each.
The API hook uses the Moodle web services which are documented on the Moodle site and within Moodle on the page at Site administration / Plugins / Web services. The Moodle instance must be configured to authorise the access from the tool. This involves the following steps:
- Enable web services (see
Site administration / Advanced features) - Enable the REST protocol (see
Site administration / Plugins / Web services / Manage protocols) - Create a user (e.g. named
My LTI Tool Service) (seeSite administration | Users | Accounts) - Create a role (e.g. named
My LTI Tooland assign it to the user (see below) (seeSite administration | Users | Permissions | Define roles) - Add an external service (e.g. named
My LTI Tool web servicewith a short name ofmyltitool) (seeSite administration | Plugins | Web services)- add functions to the service (see below)
- add the
My LTI Tooluser as an authorised user of the service
- Create an access token for the
My LTI Tooluser (an IP restriction can also be added here if desired) (seeSite administration | Plugins | Web services | Manage tokens)
The role assigned to the My LTI Tool user must have the following capabilities:
moodle/course:enrolreviewmoodle/course:managegroupsmoodle/course:useremailmoodle/course:viewmoodle/role:reviewmoodle/user:viewalldetailsmoodle/user:viewdetailsmoodle/user:viewhiddendetailswebservice/rest:usemoodle/site:accessallgroupsmoodle/site:viewfullnames
This will mean that the access token generated can access all courses in the Moodle instance. If it is preferred to limit this, then do not assign the moodle/course:view capability to the My LTI Tool user, but enrol them in each course for which you wish to give tool access.
The My LTI Tool external service must have the Enabled and Authorised users only boxes checked and have the
following functions added:
- core_enrol_get_enrolled_users
- core_group_get_course_groupings
- core_group_get_course_groups
- core_group_get_groupings
The current implementation has the following limitations:
- The roles returned for each user do not include any administrator roles which may apply to the user and would be included in an LTI message.
- The value of the
lis_result_sourcedidparameter is not included. - Only groupings in which users only belong to one of its constituent groups are recognised.
© 2025 Stephen P Vickers. All Rights Reserved.