Patrick Pollet Pointed me to this forum, and I'd like to know how can I do it using xmlrpc.
I'm using Moodle 1.9.4+, and I don't know if this feature is implemented in this version.
I haven't found any example of how to do a rpc.
Could someone help me?
You have a few options, from what I can see:
- you can use Moodle Networks. If your external app is written in PHP, you should be able to largely use Moodle's (or Mahara's) Moodle Networks implementation. Otherwise, you may need to write your own implementation, which can be a lot of work.
- you can use Moodle Networks in "dangerous" mode. This should allow you to bypass the additional security layer and use straight XML-RPC, but you need to be aware of the security risks, and it is generally recommended that you do not do this (but it may be the easiest).
- you can use the OKTech Web Services plugin, which will give you a SOAP interface rather than an XML-RPC interface. http://moodle.org/mod/data/view.php?d=13&rid=573 It does not provide a method for listing courses, but you can modify it to do so.
- you could set your external application to access the Moodle database directly, and get the list of courses from there.
Could I do this with Moodle 2.0 using web services?
"The external APP is not written in PHP, so I think that the last option is the best one."
You will find in clients diretory samples code in java or python.
And don't forget, soapUi will be your friend to test the operations...
@patrick: where are find sample code by python? I need working webservice XML-RPC and python (not Soap). Can you detail?
you can use the OKTech Web Services plugin, which will give you a SOAP interface rather than an XML-RPC interface. http://moodle.org/mod/data/view.php?d=13&rid=573 It does not provide a method for listing courses, but you can modify it to do so.
euh, it does it among 43 other operations...
Go to wspp/clients directory and run
php ../wsdl2php.php http://yourmoodle/wspp/wsdl_pp.php
it will create a class MoodleWS.php and a directory tests with 43 samples scripts :
rename auth.php.dist to auth.php and edit to match an admin user (with manual authentication)
and give them a go :
you will find among them this sample script :
/**test code for MoodleWS: Get Courses Information
* @param integer $client
* @param string $sesskey
* @param (getCoursesInput) array of string $courseids
* @param string $idfield
* @return getCoursesReturn
$courseids=array(); //all courses that LOGIN user can see
// $courseids=array("chem101","phys101"); //o nly these 2
when done, transfert the tests directory and MoodleWS.php , auth.php to a real (remote) client and try them out again ...
Don't forget to remove the tests directory from server (!!!!) or protected wspp directory with a suitable .htaccess file ! (you have been warned)
I'll try it, but it seems a bit complicated. I'm just starting to learn Moodle
Are the Web Services working this way in 2.0?
The external app is written in Python, I'll check the clients.
I am also in need of an easy way to print a course directory. I need to have a list of all our courses available so that I can create a list for our superintendent.
From the Moodle version 2.5.1 onwards, you can use these following function to get course(s):
- Get a specific course with ID:
$course = get_course($course_id);
- Get all courses:
$courses = get_courses();
Read the Moodle's Data Manipulation API for more information: