As a Moodle administrator, enable web services at Site Administration > Advanced Features > Enable web services, then enable the REST protocol at Site Administration > Plugins > Web Services > Manage Protocols.
Create a dedicated service at Site Administration > Plugins > Web Services > External Services; add the specific API functions your integration needs (e.g., core_user_get_users, core_enrol_get_enrolled_users) to that service.
Create or designate a Moodle user with the appropriate capabilities, then generate a token for that user at Site Administration > Plugins > Web Services > Manage Tokens, associating it with your external service.
Call the REST endpoint using HTTPS: GET or POST to https://yourmoodle.example.com/webservice/rest/server.php?wstoken=your_token&wsfunction=function_name&moodlewsrestformat=json plus any function-specific parameters.
Parse the JSON response; Moodle wraps successful responses directly in the returned object, but errors return an object with an exception key and message field — always check for the exception key before processing the result.
For bulk operations (e.g., enrolling many users), batch calls where the function supports array parameters rather than making one HTTP call per user to avoid hitting server timeout or rate limits.
Known gotchas
The REST protocol must be explicitly enabled in Manage Protocols — installing Moodle does not enable any web service protocols by default, and a missing protocol returns a generic error that may not indicate the root cause.
Tokens are bound to a specific user and service; using a token against a function not added to its associated service returns an accessexception error, not a 403 HTTP status — the HTTP status will be 200 with an error payload.
Moodle's default REST endpoint uses query string parameters for all inputs regardless of HTTP method; sending a JSON request body is not natively supported unless you install the RESTful protocol plugin, which uses a different URL and authentication scheme.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp