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
- core_user_create_users
- core_user_update_users
- local_gdpr_deleteuserdata_single
- core_course_create_courses
- core_course_create_categories
- enrol_manual_enrol_users
- enrol_manual_unenrol_users
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
- users[0][username]
- users[0][email]
- users[0][lastname]
- users[0][firstname]
- 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
- users[0][username]
- users[0][email]
- users[0][lastname]
- users[0][firstname]
- 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
- 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
- categories[0][name]
- categories[0][parent]
- 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
- courses[0][fullname]
- courses[0][categoryid]
- courses[0][shortname]
- 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
- enrolments[0][roleid]
- enrolments[0][userid]
- 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
- enrolments[0][roleid]
- enrolments[0][userid]
- 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)
What is the limit of bulk user creation for core_user_create_users? how many users can be created in a single API call?
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
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?
Hi, I've some doubts in moodle will you clarify. Thank you
Sure, what you want to know about?