If you have experimented with the Moodle Web Services then you will find there are pockets of information that can be pieced together to help understand how the API’s work.

Below is a list of links to pages and sites that I have found extremely useful when it comes to putting together an external web service.

Moodle web service links

The first most important page is on your Moodle server.


This will list all the web service functions that you have available and describe the schema for each service in different protocols.

Current web service functions from the Moodle documentation.


Using web services – setting up the service on Moodle


Creating a web service client


Getting started list of steps to setup web services in Moodle


Step by step setup


Quick web service setup and test


Example: Save grades using PHP.


Download CURL if you are using PHP as your server side code from here.

Some code to get you started

If you just want some code to get you started, the below code is the core of what you will need.

Make sure you setup your Moodle service as recommended in the above links to allow web services and setup a user account with a token.

Enrol the user with the web service token into the course you are going to test with.

Remember that your account must have permission to use a web service.

I am assuming you are using PHP as the external application server to call the Moodle web services?

On a PHP server, download the CURL PHP file from above and add it to your web server to be included by the code below.

Create a PHP testwebservice.php page and add the following code.

Replace courseid_as_integer with your test course ID.  

$config = array(

    'moodletoken' =>  'xxxxxx',
    'moodledomainname' => 'https://yourmoodleserver'
$courserefmoodle =  courseid_as_integer;
$restformat = 'json';
$functionname = 'core_course_get_courses';
$mdl_params = array('options' => array('ids' => array($courserefmoodle)));
$serverurl = $config['moodledomainname'] . '/webservice/rest/server.php'. '?wstoken=' . $config['moodletoken'] . '&wsfunction='.$functionname;
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = json_decode($curl->post($serverurl . $restformat, $mdl_params));
if (!isset($resp) || is_object($resp) || !isset($resp[0])) {
    echo "<div class='warning'>MOODLE Course not found or web service user is not enroled in this course.</div>";
$coursedata = $resp[0];

This will return the details about the course ID that you set as JSON data.

Need more information….. Join the NEW Moodle Administrators and Developers group


Would you like a FREE copy of the Top 10 Admin Tasks​ that you ​must know​ for Moodle Administrators?
You will discover some simple things that you can do in Moodle that will make your life easier.