Webservice function for course list platform
The local_ws_courselist
plugin is a Moodle plugin that provides a web service to list all available courses on the platform, including each course’s unique ID (id
), full name (fullname
), short name (shortname
), and the category ID (categoryid
) it belongs to.
- Course List: Retrieves available courses on Moodle with the following details:
id
: the unique identifier for the course.fullname
: the full name of the course.shortname
: the short name of the course.categoryid
: the unique identifier of the category the course belongs to.
- Moodle: Minimum version required: 3.11.
- Permissions: Users must have the
moodle/course:view
capability to access this service.
- Download the
local_ws_courselist
folder into thelocal
directory of your Moodle installation. - Access the site administration to complete the plugin installation.
- Enable web services in Moodle administration if needed and assign permissions to authorized users.
Function: local_ws_courselist_get_courses
Description: Retrieves the list of available courses on Moodle.
Example Response:
[
{
"id": 1,
"fullname": "Sample Course",
"shortname": "Sample",
"categoryid": 3
},
{
"id": 2,
"fullname": "Another Course",
"shortname": "Another",
"categoryid": 3
}
]
To test this web service, use a tool like curl
or Postman with a valid API token for a user with the required permissions.
Example cURL Request:
curl -X POST "https://your-moodle-site.com/webservice/rest/server.php" \
-d "wstoken=YOUR_TOKEN" \
-d "wsfunction=local_ws_courselist_get_courses" \
-d "moodlewsrestformat=json"
This plugin can be modified to further restrict accessible courses or include additional information as needed.
Maxime Cruzel
This project is licensed under the MIT License.