DEV Community

Cover image for Moodle Web Service APIs
Udara Jayawardena
Udara Jayawardena

Posted on • Updated on

Moodle Web Service APIs

Moodle is a free open source learning management system written in PHP. Moodle is modular base Object Oriented dynamic learning platform that is designed to help educators, administrators, teachers and students to interact with each other through the platform share personalized resources.

Moodle has web services API allows you to expose your plugin's functions such as internal core functionalities like user creation, update, delete, enroll, unenroll, create events and many more..

To do that first of all system administrator has to enable the web services that can be used by rest API endpoints/ once you have done this, your system core functionalities will be accessible to other systems through Web services using one of a number of protocols, like XML-RPC, REST(Most used) or SOAP.

Each of the web service can be accessible with a token that created by system administrator.

These are some of the main core functions

  1. core_user_create_users
  2. core_user_update_users
  3. local_gdpr_deleteuserdata_single
  4. core_course_create_courses
  5. core_course_create_categories
  6. enrol_manual_enrol_users
  7. enrol_manual_unenrol_users

http://DOMAIN_OR_IP/webservice/rest/server.php?wstoken=TOKEN&moodlewsrestformat=JSON&wsfunction=FUNCTION

This Rest API enable you to create, update, delete internal resources form the database.

1. Create User

Function Name : - core_user_create_users (Internal Plugin)
Token : - Generated by Site administrator.

In this function you can create a user in the moodle database.

Parameters

  1. users[0][username]
  2. users[0][email]
  3. users[0][lastname]
  4. users[0][firstname]
  5. users[0][password]

2. Update User

Function Name : - core_user_update_users (Internal Plugin)
Token : - Generated by Site administrator.

In this function you can change existing user model details in the database.

Parameters

  1. users[0][username]
  2. users[0][email]
  3. users[0][lastname]
  4. users[0][firstname]
  5. users[0][password]

3. Delete User

Function Name: - local_gdpr_deleteuserdata_single (External plugin) can learn more about the plugin in here
Token : - Generated by Site administrator.

In this function you can delete an existing user from the database.

Parameters

  1. parameters[userid]

4. Create Category

Function Name: - core_course_create_categories (Internal plugin)
Token : - Generated by Site administrator.

In this function you can create a category in the database.

Parameters

  1. categories[0][name]
  2. categories[0][parent]
  3. categories[0][description]

5. Create Courses

Function Name: - core_course_create_courses (Internal plugin)
Token : - Generated by Site administrator.

In this function you can create a course and a relation with an existing category to the course(Mentioned above in example 4).

Parameters

  1. courses[0][fullname]
  2. courses[0][categoryid]
  3. courses[0][shortname]
  4. courses[0][summary]

6. Enrol Users

Function Name : - enrol_manual_enrol_users (Internal plugin)
Token : - Generated by Site administrator.

In this function you can assign a role to an existing user in the database such as Student role, Teacher role, Sys admin role.

Parameters

  1. enrolments[0][roleid]
  2. enrolments[0][userid]
  3. enrolments[0][courseid]

7. UnEnrol Users

Function Name: -enrol_manual_unenrol_users (Internal plugin)
Token : - Generated by Site administrator.

In this function you can un enroll a user from the database.

Parameters

  1. enrolments[0][roleid]
  2. enrolments[0][userid]
  3. enrolments[0][courseid]

Read more about Moodle web services
πŸ‘‰ https://docs.moodle.org/dev/Web_service_API_functions
πŸ‘‰ https://docs.moodle.org/dev/Core_APIs
πŸ‘‰ https://docs.moodle.org/39/en/Using_web_services

if you guys have any issue, send me a mail udarajayawardena5@gmail.com
Hope you guys like the blog and learn something new!
A ❀️ would be Awesome... 😊 #UJ

Top comments (5)

Collapse
 
ashahrior profile image
Ashef Shahrior

What is the limit of bulk user creation for core_user_create_users? how many users can be created in a single API call?

Collapse
 
udarajayawardena profile image
Udara Jayawardena • Edited

Hi Ashef, you can create only one user in a single API call from this function (core_user_create_users). if you want to create many, you have to use a loop

Collapse
 
ashahrior profile image
Ashef Shahrior • Edited

How come? From what I have experienced from the api call with the webservice and according to the documentation a bulk user list can be sent with the API call. Let me rephrase my question. What is the max number of users that can be sent through the post api for creation? the limit of the json object request body?

Collapse
 
subashshanmugam profile image
subashboss

Hi, I've some doubts in moodle will you clarify. Thank you

Collapse
 
udarajayawardena profile image
Udara Jayawardena

Sure, what you want to know about?