-
Notifications
You must be signed in to change notification settings - Fork 40
ApiMoodle
The following API hooks are supported for Moodle instances:
- Membership service (including group information)
- Resource link level
- Context level
The implementation 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::$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 tool consumer record; for example:
$toolConsumer->setSetting('moodle.per_page', '75');
The options must be specified for each Moodle instance defined within the tool provider 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 provider. 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
WebPA Service) (seeSite administration | Users | Accounts) - Create a role (e.g. named
WebPAand assign it to the user (see below) (seeSite administration | Users | Permissions | Define roles) - Add an external service (e.g. named
WebPA web servicewith a short name ofwebpa) (seeSite administration | Plugins | Web services)
- add functions to the service (see below)
- add the WebPA user as an authorised user of the service
- Create an access token for the WebPA user (an IP restriction can also be added here if desired) (see
Site administration | Plugins | Web services | Manage tokens)
The role assigned to the WebPA user must have the following capabilities:
moodle/course:enrolreviewmoodle/course:managegroupsmoodle/course:useremailmoodle/course:viewmoodle/user:viewdetailsmoodle/user:viewhiddendetailswebservice/rest:usemoodle/site:accessallgroupsmoodle/site:viewfullnames
This will mean that the access token generated can access all courses in the Modle instance. If it is preferred to limit this, then do not assign the moodle/course:view capability to the WebPA user, but enrol them in each course for which you wish to give WebPA access.
The WebPA 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.
© 2025 Stephen P Vickers. All Rights Reserved.