Moodle

Moodle API development for systems that need your LMS data

We configure Moodle web services and write the external functions core does not have, with capability checks and tokens scoped to exactly what each consumer needs.

  • Core and custom functions
  • Least-privilege tokens
  • Documented for your developers
What is included
  • Web services setup
  • Token management
  • Custom external functions
  • Capability and context checks
  • Bulk and paged endpoints
  • Documentation and test collection
Get a free quote Reply within one business day. NDA on request.
The problem

What teams hit when calling Moodle

Sooner or later another system needs to talk to Moodle. HR wants to create accounts and read completions. The customer portal wants to show a learner their courses. A mobile app needs grades. Your developers open the web services documentation, find hundreds of functions with names like core_enrol_get_users_courses, and discover that the one call they need returns too much, returns too little or does not exist.

Moodle's API is capable and unusual. It is function-based instead of resource-based, errors do not arrive the way REST clients expect, and permissions depend on the user behind the token. We set it up properly, fill the gaps with custom functions inside a plugin, and document the result so the team on the other side can build against it without learning Moodle internals. For the wider picture of connecting systems, see Moodle integration.

  • The function you need is missing

    Core covers users, courses, enrolments and grades, but not your custom report, your plugin data or the exact combination your portal needs in one call.

  • One token can do everything

    To get things working, someone created a token for an administrator account. It can now do anything on the site, and it sits in another system's configuration file.

  • Calls are slow or time out

    A nightly sync asks for every user and every completion, one request at a time. It takes hours, overlaps with cron and occasionally fails halfway with no way to resume.

  • Errors are hard to detect

    The integration reports success because the HTTP status looked fine, while the response body carried an exception. Enrolments fail silently and nobody notices for weeks.

What we do

Our Moodle web services work

Our starting point is that every system calling Moodle deserves its own permissions, limits and documentation.

Web services setup

The REST protocol enabled, a dedicated service user and role created, and a custom service defined that lists only the functions a consumer may call.

Token management

One token per consumer, bound to a service user, with IP restriction and expiry where suitable, and a rotation procedure your administrators can follow.

Custom external functions

New API functions written in a plugin with declared parameters and return structures, so Moodle validates input and output on each call.

Capability and context checks

Every function validates the context and requires the right capability, so a token can read or change only what its user is allowed to.

Bulk and paged endpoints

Functions designed for sync jobs: changes since a timestamp, paged results and batch writes, so consumers stop looping over single-record calls.

Documentation and test collection

A reference for each function with sample requests, responses and error cases, plus a request collection your developers can run against staging.

Typical projects

Moodle API projects we deliver

01

HR system sync

Functions to create and update users, assign cohorts and return completions changed since the last run, called on a schedule by your HR platform or middleware.

02

Learner data in a portal

A customer or staff portal shows enrolled courses, progress and certificates by calling Moodle with a scoped token, and deep-links the learner into the right course.

03

Back end for a custom app

Endpoints shaped for mobile screens, returning a dashboard or a course outline in one call, used by a Flutter or web app in place of dozens of core calls.

04

Reporting extract

Paged functions that expose enrolment, grade and completion records for a data warehouse, with filters by date and category and a stable field list.

In depth

How Moodle web services really behave

Functions, not resources

Moodle exposes a single REST endpoint. Each request names a function, such as creating users or listing one user's courses, passes a token, and asks for JSON. Parameters travel as form fields, including nested arrays, instead of a JSON body. There are no resource URLs and no meaningful HTTP verbs. Developers used to conventional REST find this odd for a day and then get on with it, provided someone has written down which functions to call and in what order.

Services, users and tokens

A function can only be called if it belongs to a service, the service is enabled, and the token's user has been allowed to use it. That user also needs the capability to use the web service protocol, plus whatever capabilities the function itself checks. We create one service per consumer containing the minimum set of functions, a dedicated user with a purpose-made role, and a token tied to both. If the HR token leaks, it cannot grade assignments, and revoking it does not break the portal.

Writing an external function

Custom functions live in a plugin, usually a local one. Each is a class with three parts: a description of the parameters it accepts, the method that does the work, and a description of what it returns. It is registered in the plugin's services file. Moodle uses those descriptions to validate every call and to generate API documentation in the admin area. Inside the method we validate the context, check capabilities, then use Moodle's own APIs to enroll, grade or read, so events fire and logs are written as if a person had done it. The plugin structure itself is covered under Moodle plugin development.

Errors, load and payload size

Two behaviors catch integrators out. First, a failed call normally still returns HTTP 200 with an exception object in the body, so clients must inspect the response instead of trusting the status code. Second, throttling of API traffic is normally left to the infrastructure in front of Moodle. A consumer that fires thousands of requests competes with learners for the same PHP workers and database. We design for that with batch functions, paging, "changed since" filters and, where needed, limits at the web server or gateway. Large responses are trimmed to the fields the consumer uses, which matters most on mobile connections.

Testing and versioning

External functions are covered by PHPUnit tests that call them as different users and assert both results and refusals. When a function must change shape, we add a new one and keep the old one working until consumers have moved, because a mobile app already in the stores cannot be updated overnight.

Process

From request to working Moodle endpoint

  1. 1

    Consumer mapping

    We list each system that will call Moodle, the data it needs to read or write, how often, and under whose authority.

  2. 2

    Function design

    Core functions are matched to needs, gaps are specified as custom functions with parameters, return fields and error cases, and you approve the contract.

  3. 3

    Build and secure

    Services, roles, users and tokens are configured on staging, custom functions are written in a plugin, and automated tests cover permissions.

  4. 4

    Consumer testing

    Your developers or vendor build against staging using our documentation and request collection, and we adjust payloads based on what they find.

  5. 5

    Production rollout

    Tokens are issued for production, monitoring of web service logs is set up, and the rotation and revocation steps are handed to your admins.

Deliverables

Handed to the developers calling Moodle

  • A dedicated service, role and token for each consumer
  • Custom functions packaged in a plugin you own
  • Reference documentation with sample calls
  • Permission tests that run automatically
  • A token rotation and revocation procedure
FAQ

Moodle web service questions developers ask

Does Moodle have a REST API out of the box?
Yes. Moodle ships with web services that can be called over REST and return JSON, covering users, courses, enrolments, grades, completion and much more. They are off by default. An administrator has to enable the protocol, define a service and issue tokens before anything can connect.
What if the core functions do not return what we need?
Then we write a custom external function in a plugin. It can combine data from several areas, expose your own plugin tables or accept a bulk update, and it is validated and permission-checked like any core function. Nothing in Moodle core is modified to add it.
How are Moodle API calls authenticated?
With a token sent on each request. The token belongs to a specific user and service, so it can call only the functions in that service and act only with that user's capabilities. We issue separate tokens per consuming system and can restrict them by IP address and expiry date.
Can Moodle push data out when something happens, like a webhook?
Yes, with a small plugin. We write an event observer that listens for events such as course completion or a new enrolment and queues an adhoc task to post the data to your endpoint, with retries if the receiver is down. The learner's page stays fast because the call happens in the background.
Will heavy API use slow the site down for learners?
It can if the integration is chatty. API calls use the same web servers and database as people do. We reduce the load with batch and paged functions, incremental sync, schedules outside peak hours and limits at the web server, and we test with realistic volumes on staging first.
Can you build the system on the other side too?
Yes. We build portals and middleware that consume Moodle, most often in Laravel, and mobile apps in Flutter. If your Moodle needs a companion back end of its own, our Laravel API development team works alongside the Moodle developers on the same project.
Start a project

Tell us what needs to talk to Moodle

Name the system, the data and the direction. We will reply within one business day with the core functions that fit, the gaps we see and what a free quote would cover.

  • Free consultation and quote
  • NDA on request
  • You own the source code
  • Reply within one business day
Add budget and timeline optional, helps us quote faster

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.