How to Create Web Services in Moodle
HTML-код
- Опубликовано: 12 июн 2021
- In this video you are going to learn How Web Services Infrastructure Works in Moodle.
Web services enable other systems to login to Moodle Sites and perform certain operations.
To run the web service and make it works, you can visit the end point from the browser or via curl.
For example to call a function via REST protocol, we can use below endpoints:
1) Generating a Token for Web Service
yoursite/login/token.php?username=USERNAME&password=PASSWORD&service=SERVICESHORTNAME
URL : yoursite/login/token.php
username : xyz
password : abc
service : service123
2) Making an API Call
yoursite/webservice/rest/server.php?wstoken=7c335a5bd39a46cb2db589735d97774e&wsfunction=local_custom_service_update_courses_sections&moodlewsrestformat=json&courseids=14
URL : yoursite/webservice/rest/server.php
wstoken : 04e3a50c7c60b0ffdb175c45bdecd850
wsfunction : local_custom_service_update_courses_sections
moodlewsrestformat : json
PARAM1 : 123
PARAM2 : 557
PARAM3 : 777
Read more about moodle web services here :
docs.moodle.org/dev/Web_services
Read more about moodle by visiting :
docs.moodle.org/311/en/Main_page
Explore this sample plugin for making custom services :
github.com/arjunsingh0037/Cus...
I hope you gain something out of this video. Incase you got any queries, do comment the same in the comment box. Also please make sure to like this video and subscribe to my channel.
{ Moodle Arjun }: { / @moodlerarjun }
Just FYI to those using a later version than in the video, you may find that the 'web services' subcategory shown at 3:40 has moved from the plugins tab to the Server tab.
This is the case for 3.11.6 but may be the case for earlier versions too.
Muchas gracias estaba viendo el video y no encontraba esta opción
Just came to comment this. Thank you!
thanks a lot!
part from 11:00-14:00 is crucial to understanding the whole!
give this part more attention, folks =)
New subscriber here.Thanks for the content.please do more videos on moodle especially in development.Thanks again
Thank you very much!
thank you so much, you've saved my life
Great!!! You help me, so much thank you!!!😀
Thank you Sir. Please make more videos on moodle especially in development.
Hi Arjun, very userful. Thank you!
Glad it was helpful!
Please upload videos on a regular basis. It's really necessary.
You are on a Linux desktop, right? What is the distribution and the window manager?
Please make a video on How to setup Global search in moodle in webserver?
Hello . very useful video. Kindly make tutorial for moodle mobile app plugin. or moodle mobile support for plugin.
Thanks. Surely i'll be making videos on Moodle Mobile App and its customization.
Hi sir, please make a video series on how to create a mod plugin in Moodle?
Hi , Could u pls share the custom files ie.Service.php and version.php etc
Can web service post to login moodle session without using SSO?
I want to give discount to students if they are member on another website and also i have created api to handle request by user member id but i ma stuck on how to achive this in moodle to change the original price of course and give them discounts if they are a member please suggest me any lead
What theme are you using tho it looks good
Exactly what them is that?
@@clementmuhirwa Its 'Space' theme
Its 'Space' theme.
Hi guys,
I need to allow students to subscribe to courses depending on the response from a third party web service. I mean the user will be allowed or not first depending on this external service.
I am new developing moodle, I know the best way is to create a plugin to handle it, but can you put me in the right direction on how would be the best way to do it? Some documentation or something similar built before.
Thanks in advance!
there are many authentication plugins given by moodle on default, however a little customisation is required in order to achieve your workflow. You can go with the userkey authentication plugin and as soon as the users gets in the system(created or logging in), you can add your condition or login. On passing that, you can redirect them to relevant pages/courses etc. This is the function 'user_login_userkey() ' which handles this, you can extend it or customise there itself
Gracias amigo, me has salvado el culo.
Glad! it was helpful.
Thank you, your video so useful, could you please share your demo code?
And, could you plesa show me how can i call this function via javascript (ajax)?
You can find it in the video description.
If you know how to use Moodle AMD structure, below could help you.
define(['jquery','core/ajax'], function($, ajax) {
return {
init: function() {
var crs = $('[data-region="data-sample"]').data('displaycourse');
var promises = ajax.call([
{
methodname: 'local_custom_service_get_course_modules',
args: {courseid: crs}
}
]);
promises[0].done(function(result) {
//do something
}).fail(function() {
//do something
});
}
};
});
Sure. You can check this sample plugin for the same : github.com/moodlerarjun/Custom-service
@@moodlerarjun Hi great jo goahead. This repo is not available. Can you please share it again.
Bhai plzzzzz🙏🙏🙏 make a video in hindi plzzz broo form integration api including checkbox, drop-down,, etc plzzz
Sure, why not. I'll share the link once it is ready and up.
Arjun I am not able to get web service link in the Plugin section, Can you please help me out same
Sure, you can send your files to moodlerarjun@gmail.com . I'll look into it.
Hi, thanks for this video. But mine is not showing web service under plugins
It is under server in 3.11 version.
Hi, can we edit the existing functions on moodle ?
Yes we can, what are you trying to changes. Better extend the class to your native plugin(s), and make the required changes
What is that specific Moodle theme?
Basically this is Moodle Space Theme.
Check here : demo.rosea.io/space/1/
Sure. Thank you 🙂
Plzzz bro
How can I get the course quiz and its password via request ?
Good question. However in similar approach, we can do this. Pass a quiz id and get all related data like quiz details, response, correct answer,etc. Please check this plugin as a reference : github.com/moodlerarjun/Custom-service
Me aparece el plugin en overview pero no en external services ayuda
can you please ellaborate a little more
Arjuna please share me core user creation web services api very urgent
Bro how to customise login page with code pls let me know
You should not touch the core login pages. However you can do full customisation via theme layouts and any auth type plugin.
Wbservice on karne ke liye kahan type karna hai yo jo aap type kar rahe hain wo to bataya nahi aapne?
So there is an option in site administration where you can check all the enabled protocols and related settings. Make sure those are enabled.