Connecting Moodle
The Moodle capa lets agents read and work in your Moodle site. It needs Moodle 4.1 LTS or newer. Agents use one dedicated service account, so oc8 sees and can do only what that account may.
Budget about 15 minutes. You do the Moodle side once, then the oc8 side.
What it does
Reading. Agents can look at:
- courses and course contents;
- participants and users;
- grades and activity completion;
- assignments and submissions, including who hasn't submitted;
- forums and their discussions.
Acting. Agents can:
- create and update courses and users;
- enrol and unenrol users;
- grade a submission with feedback;
- send messages;
- post to forums.
Every action runs through oc8 guardrails and approvals. See Guardrails below.
Before you start
- Moodle 4.1 LTS or newer.
- Admin rights in Moodle.
- A site that oc8 can reach over https. Plain
httpis accepted only forlocalhostandhost.docker.internal.
Moodle side
Do these steps in Moodle as an administrator.
1. Enable web services
Go to Site administration → General → Advanced features. Tick Enable web services and save.
2. Enable the REST protocol
Go to Site administration → Server → Web services → Manage protocols. Enable REST protocol.
3. Create a dedicated user
Go to Site administration → Users → Accounts → Add a new user. Create a
user such as oc8-service. Use a strong password. Nobody needs to sign in as
this user.
4. Give the user a role
oc8 can use only what this user may do in Moodle. Give the user a role with the capabilities you want agents to have.
The simplest choice is the Manager role at system level:
- Go to Site administration → Users → Permissions → Assign system roles.
- Open Manager and add
oc8-service. - Go to Site administration → Users → Permissions → Define roles, open
Manager and allow
webservice/rest:use.
If you prefer a narrower role, create one with only the capabilities you need,
plus webservice/rest:use.
The service user does not need to be enrolled in courses. oc8 asks Moodle for the courses the user can see without being enrolled, which a Manager can.
5. Create the external service
-
Go to Site administration → Server → Web services → External services.
-
Under Custom services, click Add.
-
Name it
oc8, tick Enabled and Authorised users only, and save. -
Click Functions next to the service, then Add functions, and add all of these:
core_completion_get_activities_completion_statuscore_course_create_coursescore_course_get_contentscore_course_get_courses_by_fieldcore_course_search_coursescore_course_update_coursescore_enrol_get_enrolled_userscore_message_send_instant_messagescore_user_create_userscore_user_get_users_by_fieldcore_user_update_userscore_webservice_get_site_infoenrol_manual_enrol_usersenrol_manual_unenrol_usersgradereport_user_get_grade_itemsmod_assign_get_assignmentsmod_assign_get_submission_statusmod_assign_get_submissionsmod_assign_save_grademod_forum_add_discussionmod_forum_add_discussion_postmod_forum_get_discussion_postsmod_forum_get_forum_discussions -
Go back to External services, click Authorised users next to
oc8, and addoc8-service.
If you leave out a function, the tool that needs it stops working. You can add it later. The site-info tool tells you which ones are missing (see Troubleshooting).
6. Create a token
- Go to Site administration → Server → Web services → Manage tokens.
- Click Create token.
- Choose the user
oc8-serviceand the serviceoc8, then save. - Copy the token. You enter it in oc8 in the next section.
oc8 side
- Go to Capas → Moodle → Set up.
- Pick a Department. Agents in that department use the connection automatically.
- For Moodle site, create a Moodle site credential. Enter the site URL and the web service token. See Credentials.
- Click Save & test.
The card then shows Connected, and the connection lists 19 tools.
Connected means only that oc8 started the Moodle bridge. It does not yet
prove that the token works or that the oc8 service has every function. To
confirm both, ask an agent to run site info (moodle_site_info) and check
that missing_functions is empty. See Check the connection.
The URL must be exactly Moodle's own web address (its wwwroot), for example
https://lms.example.org. Don't add /login or any other path. A different
address, such as one that redirects to the real site, fails.
Then allow the tools for the team under Departments → Integrations & Permissions. See Capas and Departments.
Guardrails
Each guardrail is a ready-made set of tools. Pick the one that fits the team. Reading is always free. Every change waits for a person to approve it, except in Read only, which cannot change anything.
| Guardrail | What it allows |
|---|---|
| Read only | Looks at courses, participants, grades, submissions and forums. Changes nothing and contacts nobody. |
| Assist with approval (recommended) | Reads freely. Every change waits for approval: grades, enrolments, accounts, courses, messages and forum posts. |
| Teaching assistant | Reviews submissions and progress and enters grades with feedback after approval. Cannot enrol, change accounts or courses, or send messages and forum posts. |
| Administration with approval | Creates and updates courses and accounts and manages enrolments, each after approval. Moodle may send its own account and welcome emails. Never grades, messages or posts to a forum. |
| Communication with approval | Sends Moodle messages and forum posts, such as reminders, announcements and answers, each only after approval. Changes no grades, enrolments, accounts or courses. |
Actions that reach people outside oc8
Three tools put text in front of a learner. oc8 marks them outward and irreversible, because a message cannot be recalled. An agent may use each outward tool only once per person in a task, so put every recipient of a reminder in one message.
| Tool | Who is reached |
|---|---|
| Grade a submission with feedback | Moodle may notify the student, depending on the assignment's own "Notify student" setting. |
| Send a message | The recipients get a direct message. |
| Post to a forum | Subscribers are emailed. |
Two more tools can make Moodle send its own system email. oc8 marks them irreversible, so the approval asks for confirmation, but not outward, so one task can create many accounts or enrol a person in several courses:
| Tool | What Moodle may send |
|---|---|
| Create a user | Moodle emails the generated password to the new user. |
| Enrol a user | Moodle sends the course welcome message, if the course sends one. |
Approve these with care.
Unenrolling a user is destructive: Moodle can drop the user's course data.
Troubleshooting
Errors reach the agent and show in the run. Find the text in the table.
| Error text | Cause | Fix |
|---|---|---|
| The Moodle token is invalid or expired. Create a new token for the oc8 service user. | The token is wrong, was deleted or has expired. | In Moodle, create a new token under Manage tokens and update the credential in oc8. |
| The external service does not allow function. Add it to the oc8 service in Moodle. | The function is missing from the oc8 service, or the user isn't authorised for it. | Add the function under External services → Functions. Check that oc8-service is under Authorised users. |
| The Moodle service user lacks permission for this: … | The service user's role doesn't allow this action. | Give the role the capability named in the message, or use a broader role such as Manager. Check that webservice/rest:use is allowed. |
| Moodle rejected the request (code): … | Moodle refused the call for another reason, for example a missing or invalid value. | Read the message after the colon. It comes straight from Moodle. |
| Moodle at URL redirected the request … Use Moodle's own web address (its wwwroot). | The URL is not Moodle's wwwroot, for example http instead of https, or a missing www. | Enter the address exactly as Moodle is configured. |
| Moodle at URL is not reachable (timed out after 20 s). | The site is slow, down, or blocked by a firewall. | Check that the site is up and that oc8 can reach it. |
| Moodle at URL is not reachable (…) | The connection failed, for example a DNS or certificate error. | Check the address, DNS and the site's certificate. |
| Moodle at URL did not answer with JSON. | The address is not a Moodle site, or the REST protocol is off. | Check the address. Enable REST under Manage protocols. |
| Moodle must be reached over https, not URL. | The URL uses plain http. | Use an https address. Plain http works only for localhost and host.docker.internal. |
Check the connection
Ask an agent to run the site info tool. It returns the site name, the
Moodle version and the service user. It also returns missing_functions: a
list of functions that the oc8 service lacks, each with the tool it disables.
If the list is not empty, add those functions to the service in Moodle. If your
Moodle is older than 4.1, it also returns a version warning.
Limits
- Lists return 50 items by default, up to 200. When a list is cut off, the tool says so, and the agent can ask for the next page.
- Course search covers the first 200 matches.
- Forum listing covers the 200 most recent discussions. Older ones aren't listed.
- A message goes to at most 50 users at once.
- Grading a submission needs the assignment's course as well as the assignment. oc8 refuses a grade above the assignment's maximum, and it refuses assignments graded on a scale: grade those in Moodle.