Moodle Web Service APIs
Tags: moodle, lms
Published: 2020-10-31 13:22:00

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](https://github.com/dmanolescu/moodle-local_gdpr_deleteuserdata)
> 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