API Guides

Moodle has a number of core APIs that provide tools for Moodle scripts. They are essential when writing Moodle plugins.

Most-used General API

These APIs are critical and will be used by nearly every Moodle plugin.

  • Access API (access) - Determines what the current user can do and allows modules to extend Moodle with new capabilities.
  • Data manipulation API (dml) - Read/write to databases in a consistent and safe way.
  • File API (files) - Controls storage of files for various plugins.
  • Form API (form) - Defines and handles user data via web forms.
  • Logging API (log) - Logs events and manages log storage/retrieval.
  • Navigation API (navigation) - Manipulates the navigation tree.
  • Page API (page) - Sets up the current page, adds JavaScript, and configures display.
  • Output API (output) - Renders HTML for all page components.
  • String API (string) - Retrieves language text strings and handles translations.
  • Upgrade API (upgrade) - Manages module installation and upgrades.
  • Moodlelib API (core) - General-purpose Moodle functions and constants.

Other General API

  • Admin settings API (admin) - Provides configuration options for plugins and core.
  • Admin presets API (adminpresets) - Manages Site admin presets.
  • Analytics API (analytics) - Creates prediction models and generates insights.
  • Availability API (availability) - Controls access to activities and sections.
  • Backup API (backup) - Handles course data backup and restore processes.
  • Cache API (cache) - Manages cache data storage using Moodle Universal Cache.
  • Calendar API (calendar) - Adds and modifies calendar events.
  • Check API (check) - Adds security, performance, or health checks.
  • Comment API (comment) - Saves and retrieves user comments.
  • Communication API (communication) - Manages messaging and other communication providers.
  • Competency API (competency) - Manages competencies and evidence.
  • Data definition API (ddl) - Creates, changes, and deletes database tables and fields.
  • Editor API - Controls HTML text editors.
  • Enrolment API (enrol) - Manages course participants.
  • Events API (event) - Defines and handles events for inter-plugin communication.
  • Hooks API - Enables indirect communication between core and plugins.
  • Experience API (xAPI) - Supports the xAPI e-learning standard.
  • External functions API (external) - Creates methods accessible by external programs.
  • Favourites API - Manages user favourites (starred items).
  • H5P API (h5p) - Integrates H5P content features.
  • Lock API (lock) - Synchronises processing between multiple requests.
  • Message API (message) - Posts messages to users.
  • Media API (media) - Embeds audio, video, and media content.
  • My profile API - Adds content to the user profile page.
  • OAuth 2 API (oauth2) - Manages OAuth 2 external system integrations.
  • Payment API (payment) - Handles payment processing.
  • Preference API (preference) - Stores and retrieves user preferences.
  • Portfolio API (portfolio) - Adds portfolio interfaces and export functionality.
  • Privacy API (privacy) - Manages user personal data compliance (e.g., GDPR).
  • Rating API (rating) - Creates rating interfaces for plugins.
  • Report builder API (reportbuilder) - Creates custom reports.
  • RSS API (rss) - Creates secure RSS feeds.
  • Search API (search) - Indexes and queries searchable content.
  • Tag API (tag) - Manages tags and tag clouds.
  • Task API (task) - Runs background jobs and scheduled tasks.
  • Time API (time) - Translates and displays times across users.
  • Testing API (test) - Contains Unit and Acceptance test APIs.
  • User-related APIs (user) - Handles user sorting and searching.
  • Web services API (webservice) - Exposes functions as web services.
  • Badges API (badges) - Manages badges and OpenBadges integration.
  • Custom fields API (customfield) - Configures and adds custom fields for entities.

Activity Module APIs

Activity modules are the most important plugin type in Moodle. These APIs serve activity modules specifically.

  • Activity completion API (completion) - Indicates how activities are completed.
  • Advanced grading API (grading) - Adds advanced grading interfaces (e.g., rubrics).
  • Conditional activities API (condition) - Deprecated in 2.7, replaced by Availability API.
  • Groups API (group) - Checks and sets activity group modes.
  • Gradebook API (grade) - Reads and writes gradebook data.
  • Plagiarism API (plagiarism) - Sends files/data for plagiarism checking.
  • Question API (question) - Uses and manages questions from the question bank.