MR
Mayur Rathi
@mayurrathi
⭐ 5 GitHub stars

Moodle External Api Development

Create custom external web service APIs for Moodle LMS. Use when implementing web services for course management, user tracking, quiz operations, or custom plugin functionality. Covers parameter va...

mkdir -p ./skills/moodle-external-api-development && curl -sfL https://raw.githubusercontent.com/mayurrathi/awesome-agent-skills/main/skills/moodle-external-api-development/SKILL.md -o ./skills/moodle-external-api-development/SKILL.md

Run in terminal / PowerShell. Requires curl (Unix) or PowerShell 5+ (Windows).

Skill Content

# Moodle External API Development


This skill guides you through creating custom external web service APIs for Moodle LMS, following Moodle's external API framework and coding standards.


When to Use This Skill


- Creating custom web services for Moodle plugins

- Implementing REST/AJAX endpoints for course management

- Building APIs for quiz operations, user tracking, or reporting

- Exposing Moodle functionality to external applications

- Developing mobile app backends using Moodle


Core Architecture Pattern


Moodle external APIs follow a strict three-method pattern:


1. **`execute_parameters()`** - Defines input parameter structure

2. **`execute()`** - Contains business logic

3. **`execute_returns()`** - Defines return structure


Step-by-Step Implementation


Step 1: Create the External API Class File


**Location**: `/local/yourplugin/classes/external/your_api_name.php`


```php

<?php

namespace local_yourplugin\external;


defined('MOODLE_INTERNAL') || die();

require_once("$CFG->libdir/externallib.php");


use external_api;

use external_function_parameters;

use external_single_structure;

use external_value;


class your_api_name extends external_api {


// Three required methods will go here


}

```


**Key Points**:

- Class must extend `external_api`

- Namespace follows: `local_pluginname\external` or `mod_modname\external`

- Include the security check: `defined('MOODLE_INTERNAL') || die();`

- Require externallib.php for base classes


Step 2: Define Input Parameters


```php

public static function execute_parameters() {

return new external_function_parameters([

'userid' => new external_value(PARAM_INT, 'User ID', VALUE_REQUIRED),

'courseid' => new external_value(PARAM_INT, 'Course ID', VALUE_REQUIRED),

'options' => new external_single_structure([

'includedetails' => new external_value(PARAM_BOOL, 'Include details', VALUE_DEFAULT, false),

'limit' => new external_value(PARAM_INT, 'Result limit', VALUE_DEFAULT, 10)

], 'Options', VALUE_OPTIONAL)

]);

}

```


**Common Parameter Types**:

- `PARAM_INT` - Integers

- `PARAM_TEXT` - Plain text (HTML stripped)

- `PARAM_RAW` - Raw text (no cleaning)

- `PARAM_BOOL` - Boolean values

- `PARAM_FLOAT` - Floating point numbers

- `PARAM_ALPHANUMEXT` - Alphanumeric with extended chars


**Structures**:

- `external_value` - Single value

- `external_single_structure` - Object with named fields

- `external_multiple_structure` - Array of items


**Value Flags**:

- `VALUE_REQUIRED` - Parameter must be provided

- `VALUE_OPTIONAL` - Parameter is optional

- `VALUE_DEFAULT, defaultvalue` - Optional with default


Step 3: Implement Business Logic


```php

public static function execute($userid, $courseid, $options = []) {

global $DB, $USER;


// 1. Validate parameters

$params = self::validate_parameters(self::execute_parameters(), [

'userid' => $userid,

'courseid' => $courseid,

'options' => $options

]);


// 2. Check permissions/capabilities

$context = \context_course::instance($params['courseid']);

self::validate_context($context);

require_capability('moodle/course:view', $context);


// 3. Verify user access

if ($params['userid'] != $USER->id) {

require_capability('moodle/course:viewhiddenactivities', $context);

}


// 4. Database operations

$sql = "SELECT id, name, timecreated

FROM {your_table}

WHERE userid = :userid

AND courseid = :courseid

LIMIT :limit";


$records = $DB->get_records_sql($sql, [

'userid' => $params['userid'],

'courseid' => $params['courseid'],

'limit' => $params['options']['limit']

]);


// 5. Process and return data

$results = [];

foreach ($records as $record) {

$results[] = [

'id' => $record->id,

'name' => $record->name,

'timestamp' => $record->timecreated

];

}


return

🎯 Best For

  • UI designers
  • Product designers
  • Claude users
  • Software engineers
  • Development teams

💡 Use Cases

  • Generating component mockups
  • Creating design system tokens
  • Code quality improvement
  • Best practice enforcement

📖 How to Use This Skill

  1. 1

    Install the Skill

    Copy the install command from the Terminal tab and run it. The SKILL.md file downloads to your local skills directory.

  2. 2

    Load into Your AI Assistant

    Open Claude and reference the skill. Paste the SKILL.md content or use the system prompt tab.

  3. 3

    Apply Moodle External Api Development to Your Work

    Open your project in the AI assistant and ask it to apply the skill. Start with a small module to verify the output quality.

  4. 4

    Review and Refine

    Review AI suggestions before committing. Run tests, check for regressions, and iterate on the skill output.

❓ Frequently Asked Questions

Does this work with Figma?

Some design skills integrate with Figma plugins. Check the Works With section for supported tools.

Is Moodle External Api Development compatible with Cursor and VS Code?

Yes — this skill works with any AI coding assistant including Cursor, VS Code with Copilot, and JetBrains IDEs.

Do I need specific dependencies for Moodle External Api Development?

Check the install command and Works With section. Most code skills only require the AI assistant and your codebase.

How do I install Moodle External Api Development?

Copy the install command from the Terminal tab and run it. The skill downloads to ./skills/moodle-external-api-development/SKILL.md, ready to use.

Can I customize this skill for my team?

Absolutely. Edit the SKILL.md file to add team-specific instructions, examples, or workflows.

⚠️ Common Mistakes to Avoid

Skipping usability testing

AI-generated designs should be validated with real users before development.

Skipping validation

Always test AI-generated code changes, even for simple refactors.

Missing dependency updates

Check if the skill requires updated dependencies or new packages.

🔗 Related Skills