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.

1. Check the site settings
Each setting can be found by typing its name into the 'Site administration' search box.
| Setting | Where | Value | Why |
|---|---|---|---|
| Enable web services | General > Advanced features | On | Lets SELMA connect. |
| REST protocol | Server > Web services > Manage protocols | Enabled | The protocol SELMA/Moodle uses to communicate. |
Allow extended characters in usernames (extendedusernamechars) | General > Security > Site security settings | On | SELMA uses the email address as the Moodle username. |
Show user identity (showuseridentity) | Users > Permissions > User policies | Includes Email address (the default) | SELMA finds existing users by email. |
Attendance only:
| Setting | Where | Value | Why |
|---|---|---|---|
Attendance plugin (mod_attendance) | Plugins > Install plugins/Plugins overview | Installed | Holds the sessions and attendance marks. |
Allow stealth activities (allowstealth) | General > Advanced features | On | Only 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.
- Go to Site administration > Users > Accounts > Add a new user.
- 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.
Option A: Import the role file (recommended)
Choose one file below, download and unzip/uncompress it so that it's ready to be uploaded to Moodle:
- Core and Groups permissions. Use this when attendance is not needed.
- Core, Groups and Attendance permissions.
Then:
- Go to Site administration > Users > Permissions > Define roles and select Add a new role.
- Under Use role preset, upload the role file, then select Continue.
- Check Allow role assignments (see step 4 of Option B below), then select Create this role.

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
- Go to Site administration > Users > Permissions > Define roles, select Add a new role, then Continue.
- Enter the short name
selmawebservicesroleand the custom full nameSELMA Webservices Role- add a description if you wish to clarify the purpose of the role. - Under Context types where this role may be assigned, tick System.
- 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.
- Use the capability filter to find each capability below and tick Allow.
- Select Create this role.


| Capability | Lets SELMA | Needed for |
|---|---|---|
webservice/rest:use | Use the REST protocol | Core |
moodle/course:view | Reach courses without being enrolled in them | Core |
moodle/course:viewhiddencourses | Import and use hidden courses | Core |
moodle/user:create | Create accounts | Core |
moodle/user:update | Update, suspend and reactivate accounts | Core |
moodle/user:viewdetails | Look users up | Core |
moodle/user:viewalldetails | Read the full user record | Core |
moodle/site:viewuseridentity | Read the email address when looking a user up | Core |
enrol/manual:enrol | Enrol users, set enrolment dates, revoke and restore course access | Core |
moodle/role:assign | Give the student or teacher role when enrolling | Core |
moodle/course:viewparticipants | Read a user's course enrolments | Core |
moodle/course:enrolreview | Read a user's course enrolments | Core |
gradereport/user:view | Read the gradebook | Core |
moodle/grade:viewall | Read other users' grades | Core |
moodle/grade:viewhidden | Read hidden gradebook items | Core |
report/completion:view | Read course completion | Core |
moodle/site:accessallgroups | Read grades and completion in courses that use separate groups | Core |
moodle/course:managegroups | Read and create groups, and add members | Groups |
mod/attendance:addinstance | Create the Attendance activity | Attendance |
moodle/course:manageactivities | Create/Update the Attendance activity | Attendance |
mod/attendance:manageattendances | Add, remove and read sessions | Attendance |
moodle/grade:manage | Set the activity's grade type | Attendance |
moodle/course:activityvisibility | Hide the activity or make it stealth | Attendance |
moodle/course:viewhiddenactivities | Use the activity once it is hidden | Attendance |
moodle/course:viewhiddensections | Use the activity when it sits in a hidden section | Attendance |
moodle/course:ignoreavailabilityrestrictions | Use the activity when a teacher has restricted access to it | Attendance |
moodle/course:update | Read the group mode a course forces, so sessions are pushed with the right group | Attendance |
4. Assign the role to the web service user
- Go to Site administration > Users > Permissions > Assign system roles.
- Select SELMA Webservices Role.
- Add the web service user from step 2.

5. Create the service and add its functions
- Go to Site administration > Server > Web services > External services and select Add under Custom services.
- Enter a name, for example
SELMA Webservice. Tick Enabled and Authorised users only, then select Add service.

- Select Add functions and add each function below.

- 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:
| Function | Used to | Needed for |
|---|---|---|
core_webservice_get_site_info | Test the connection and read the Moodle version | Core |
core_course_get_courses | Import courses | Core |
core_user_get_users | Find a user by email and read whether an account is suspended | Core |
core_user_create_users | Create student and staff accounts | Core |
core_user_update_users | Update, suspend and reactivate accounts | Core |
enrol_manual_enrol_users | Enrol users, set enrolment dates, revoke and restore course access | Core |
core_enrol_get_users_courses | Check existing enrolments and show course access in SELMA | Core |
gradereport_user_get_grade_items | Import gradebook items and read grades | Core |
core_completion_get_course_completion_status | Read course completion | Core |
core_group_get_course_groups | Find a course group by name | Groups |
core_group_create_groups | Create a missing Class or Intake group | Groups |
core_group_add_group_members | Add a student or staff member to a group | Groups |
core_course_get_contents | Find a course's Attendance activity | Attendance |
mod_attendance_add_attendance | Create the Attendance activity | Attendance |
core_grades_update_grades | Set the activity's grade type to none | Attendance |
core_courseformat_update_course | Hide the activity or make it stealth | Attendance |
mod_attendance_add_session | Push a timetable session | Attendance |
mod_attendance_remove_session | Remove a session | Attendance |
mod_attendance_get_session | Read a session's marks | Attendance |
mod_attendance_get_sessions | List an activity's sessions | Attendance |
Test connection in SELMA lists any function(s) missing from the service.
6. Create the token
- Go to Site administration > Server > Web services > Manage tokens and select Create token.
- Select the web service user and the service created earlier.
- 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.
- Save, then copy the token straight away, as Moodle only shows it once. Store it somewhere secure.

7. Note the role IDs
SELMA needs the ID of the Moodle role to give students, and of the role to give staff.
- Go to Site administration > Users > Permissions > Define roles and select the role.
- The ID is the
roleidvalue 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 Moodle | Example | SELMA field |
|---|---|---|
| Site address | https://moodle.example.com | Endpoint URL |
| Token | - | Web service token |
| Student role ID | 5 | Default student role ID |
| Staff role ID | 3 | Default teacher role ID |
Continue with Moodle Set-Up (In SELMA).
Troubleshooting
| Problem | Check |
|---|---|
| SELMA cannot connect | Web 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 functions | Add them to the service (step 5). |
| Accounts are created but enrolments fail | The student or staff role is ticked under Allow role assignments (step 3), and the course has the Manual enrolments method enabled. |
| Accounts cannot be created | Allow extended characters in usernames is on (step 1). |
| Existing Moodle users are not found | Show user identity includes Email address (step 1). |
| Attendance sessions are not pushed | The Attendance plugin is installed, and the Attendance capabilities and functions are in place. |
More about web services in Moodle: Using web services.
Last updated
Microsoft 365 (User-Level Emails)
Enabling the Microsoft 365 integration in SELMA allows you to use your organisation's Microsoft mailbox(es) to send emails directly from SELMA. Emails…
Moodle Set-Up (In SELMA)
The Endpoint will be your unique Moodle URL (e.g. https://moodle.yourdomain.com), and the Token will be the Web Service Token you created and saved,…