SELMA SISResource CentreResource Centre
support@selmasis.comAU +61(0)7 3103 9873 / NZ +64(0)9 366 0789

Updated on

Moodle Integration Set-Up

The SELMA-Moodle Integration serves as a connector between your Moodle instance and your SELMA instance. This allows you to provision students from…

The Moodle integration connects SELMA to one or more Moodle sites. SELMA creates student and staff accounts in Moodle, enrols them in courses and adds them to groups. Grades and course completions come back from Moodle to SELMA. Optionally, timetable sessions are pushed to Moodle's Attendance activity and the marks taken there come back too.

This page covers the Moodle side and is written for a Moodle site administrator. The SELMA side is covered in: Moodle Set-Up (In SELMA).



Before you start

  • Ask SELMA Support to enable the Moodle integration on your SELMA account.
  • You need site administrator access to Moodle.
  • If you will use the attendance integration, it needs the Attendance plugin and extra permissions, marked Attendance on this page. Everything else is marked Core or Groups.

Moodle's own checklist at Site administration > Server > Web services > Overview shows the status of most of the steps below.

Site administration > Server > Web services > Overview
Site administration > Server > Web services > Overview

1. Check the site settings

Each setting can be found by typing its name into the 'Site administration' search box.

SettingWhereValueWhy
Enable web servicesGeneral > Advanced featuresOnLets SELMA connect.
REST protocolServer > Web services > Manage protocolsEnabledThe protocol SELMA/Moodle uses to communicate.
Allow extended characters in usernames (extendedusernamechars)General > Security > Site security settingsOnSELMA uses the email address as the Moodle username.
Show user identity (showuseridentity)Users > Permissions > User policiesIncludes Email address (the default)SELMA finds existing users by email.

Attendance only:

SettingWhereValueWhy
Attendance plugin (mod_attendance)Plugins > Install plugins/Plugins overviewInstalledHolds the sessions and attendance marks.
Allow stealth activities (allowstealth)General > Advanced featuresOnOnly needed when SELMA is set to create Stealth attendance activities.

Each course SELMA enrols users into also needs the Manual enrolments method enabled, which it is by default.

2. Create the web service user

SELMA acts in Moodle as one dedicated user.

  1. Go to Site administration > Users > Accounts > Add a new user.
  2. Create a user for SELMA only, for example with the username selma_webservice. Do not use a personal or administrator account.

3. Create the SELMA Webservices role

The role holds every permission the web service user needs. Import it from a role file, or create it by hand.

Choose one file below, download and unzip/uncompress it so that it's ready to be uploaded to Moodle:

  1. Core and Groups permissions. Use this when attendance is not needed.
selmabasewebservicesrole.xml.zipZIP · 6 KBDownload selmabasewebservicesrole.xml.zip
  1. Core, Groups and Attendance permissions.
selmaattendancewebservicesrole.xml.zipZIP · 6 KBDownload selmaattendancewebservicesrole.xml.zip

Then:

  1. Go to Site administration > Users > Permissions > Define roles and select Add a new role.
  2. Under Use role preset, upload the role file, then select Continue.
  3. Check Allow role assignments (see step 4 of Option B below), then select Create this role.
Upload role file
Add a new role, with the role file uploaded under 'Use role preset'.

To add attendance to a role created from the first file, add the Attendance capabilities below by hand.

Option B: Create the role by hand

  1. Go to Site administration > Users > Permissions > Define roles, select Add a new role, then Continue.
  2. Enter the short name selmawebservicesrole and the custom full name SELMA Webservices Role - add a description if you wish to clarify the purpose of the role.
  3. Under Context types where this role may be assigned, tick System.
  4. Under Allow role assignments, tick the roles SELMA will give to students and staff when it enrols them - usually Student, and Teacher or Non-editing teacher.
  5. Use the capability filter to find each capability below and tick Allow.
  6. Select Create this role.
The role form: short name, System context and Allow role assignments.
The role form: short name, System context and Allow role assignments.
The capability filter, with a capability set to 'Allow'.
The capability filter, with a capability set to 'Allow'.
CapabilityLets SELMANeeded for
webservice/rest:useUse the REST protocolCore
moodle/course:viewReach courses without being enrolled in themCore
moodle/course:viewhiddencoursesImport and use hidden coursesCore
moodle/user:createCreate accountsCore
moodle/user:updateUpdate, suspend and reactivate accountsCore
moodle/user:viewdetailsLook users upCore
moodle/user:viewalldetailsRead the full user recordCore
moodle/site:viewuseridentityRead the email address when looking a user upCore
enrol/manual:enrolEnrol users, set enrolment dates, revoke and restore course accessCore
moodle/role:assignGive the student or teacher role when enrollingCore
moodle/course:viewparticipantsRead a user's course enrolmentsCore
moodle/course:enrolreviewRead a user's course enrolmentsCore
gradereport/user:viewRead the gradebookCore
moodle/grade:viewallRead other users' gradesCore
moodle/grade:viewhiddenRead hidden gradebook itemsCore
report/completion:viewRead course completionCore
moodle/site:accessallgroupsRead grades and completion in courses that use separate groupsCore
moodle/course:managegroupsRead and create groups, and add membersGroups
mod/attendance:addinstanceCreate the Attendance activityAttendance
moodle/course:manageactivitiesCreate/Update the Attendance activityAttendance
mod/attendance:manageattendancesAdd, remove and read sessionsAttendance
moodle/grade:manageSet the activity's grade typeAttendance
moodle/course:activityvisibilityHide the activity or make it stealthAttendance
moodle/course:viewhiddenactivitiesUse the activity once it is hiddenAttendance
moodle/course:viewhiddensectionsUse the activity when it sits in a hidden sectionAttendance
moodle/course:ignoreavailabilityrestrictionsUse the activity when a teacher has restricted access to itAttendance
moodle/course:updateRead the group mode a course forces, so sessions are pushed with the right groupAttendance

4. Assign the role to the web service user

  1. Go to Site administration > Users > Permissions > Assign system roles.
  2. Select SELMA Webservices Role.
  3. Add the web service user from step 2.
Assign system roles, with the web service user added to SELMA Webservices Role.
Assign system roles, with the web service user added to SELMA Webservices Role.

5. Create the service and add its functions

  1. Go to Site administration > Server > Web services > External services and select Add under Custom services.
  2. Enter a name, for example SELMA Webservice. Tick Enabled and Authorised users only, then select Add service.
The external service form, with Enabled and Authorised users only ticked.
The external service form, with 'Enabled' and 'Authorised users only' ticked.
  1. Select Add functions and add each function below.
The service's function list.
Add all the service's required functions to the list.
  1. Back on External services, select Authorised users for the service and add the web service user.

Here's the list of functions/endpoints that need to be added to the service:

FunctionUsed toNeeded for
core_webservice_get_site_infoTest the connection and read the Moodle versionCore
core_course_get_coursesImport coursesCore
core_user_get_usersFind a user by email and read whether an account is suspendedCore
core_user_create_usersCreate student and staff accountsCore
core_user_update_usersUpdate, suspend and reactivate accountsCore
enrol_manual_enrol_usersEnrol users, set enrolment dates, revoke and restore course accessCore
core_enrol_get_users_coursesCheck existing enrolments and show course access in SELMACore
gradereport_user_get_grade_itemsImport gradebook items and read gradesCore
core_completion_get_course_completion_statusRead course completionCore
core_group_get_course_groupsFind a course group by nameGroups
core_group_create_groupsCreate a missing Class or Intake groupGroups
core_group_add_group_membersAdd a student or staff member to a groupGroups
core_course_get_contentsFind a course's Attendance activityAttendance
mod_attendance_add_attendanceCreate the Attendance activityAttendance
core_grades_update_gradesSet the activity's grade type to noneAttendance
core_courseformat_update_courseHide the activity or make it stealthAttendance
mod_attendance_add_sessionPush a timetable sessionAttendance
mod_attendance_remove_sessionRemove a sessionAttendance
mod_attendance_get_sessionRead a session's marksAttendance
mod_attendance_get_sessionsList an activity's sessionsAttendance

Test connection in SELMA lists any function(s) missing from the service.

6. Create the token

  1. Go to Site administration > Server > Web services > Manage tokens and select Create token.
  2. Select the web service user and the service created earlier.
  3. You can leave IP restriction empty and Valid until switched off. For enhanced security you can set these up - however it'll be up to you to track when the token needs to be refreshed and updated in SELMA to prevent any interruptions.
  4. Save, then copy the token straight away, as Moodle only shows it once. Store it somewhere secure.
Create token, with the user and service selected.
Create token, with the user and service selected.

7. Note the role IDs

SELMA needs the ID of the Moodle role to give students, and of the role to give staff.

  1. Go to Site administration > Users > Permissions > Define roles and select the role.
  2. The ID is the roleid value in the page's address/URL.

On a standard site, Student is 5, Teacher is 3 and Non-editing teacher is 4. Both roles must be ticked under Allow role assignments on the SELMA Webservices Role.

What to enter in SELMA

From MoodleExampleSELMA field
Site addresshttps://moodle.example.comEndpoint URL
Token-Web service token
Student role ID5Default student role ID
Staff role ID3Default teacher role ID

Continue with Moodle Set-Up (In SELMA).

Troubleshooting

ProblemCheck
SELMA cannot connectWeb services and the REST protocol are enabled, the token is correct and has not expired, and the web service user is an authorised user of the service.
Test connection lists missing functionsAdd them to the service (step 5).
Accounts are created but enrolments failThe student or staff role is ticked under Allow role assignments (step 3), and the course has the Manual enrolments method enabled.
Accounts cannot be createdAllow extended characters in usernames is on (step 1).
Existing Moodle users are not foundShow user identity includes Email address (step 1).
Attendance sessions are not pushedThe Attendance plugin is installed, and the Attendance capabilities and functions are in place.

More about web services in Moodle: Using web services.

Last updated

Was this page helpful?

On this page