Note: You are currently viewing documentation for Moodle 2.0. Up-to-date documentation for the latest stable version is available here: Creating a web service client.

Development:Creating a web service client

From MoodleDocs

Template:Moodle 2.0

Officially supported protocols

  • REST: the current REST Moodle server use POST paramters and XML. The server is not RESTfull. A client would be really easy to implement once you know how the XML is structured. Have a look to the Moodle default test client, the XML is displayed.
  • SOAP: the current SOAP server is based on the Zend SOAP sever (itself based on the PHP SOAP sever). Zend publishes a Zend SAOP client. The current server implementation doesn't work with Java/.Net because we didn't generated a fully describe WSDL yet. If you are working on a Java/.Net client, follow or participate to the tracker issue MDL-20804
  • XML-RPC: the current XML-RPC server is based on Zend XML-RPC server. Zend also publishes a Zend XML-RPC client.
  • AMF: the server is based on the Zend AMF server. The server has been tested with simple web service function and primary type. The test client is currently work in progress, see the issue tracker MDL-20808.

You will also look for functions documentation. A documentation generator will be available. Please follow the tracker issue MDL-20803

What protocol to use

  • PHP: have a look at SOAP/XMLRPC zend clients. SOAP/XMLRPC Moodle server use Zend server, it should be easy to use.
  • Java/.Net: use the REST protocol. The SOAP server doesn't generate a Java compliant WSDL yet.
  • AS3: use the AMF protocol. Moodle use Zend AMF server. This server is supported by Zend and Adobe.

Authentication

There is two methods to be authenticated by the web service. Each time you call a web service function:

  1. you pass your username/password.
  2. you pass a token. This token has been generated for you by an administrator into the Moodle administration.

username/password authentication

if you look to the Moodle test client PHP code, you will notice that username/password are sent as GET parameters. //wwwroot/webservice/$protocol/simpleserver.php?wsusername=your_username&wspassword=your_password $serverurl = "$CFG->wwwroot/webservice/$protocol/simpleserver.php"; $serverurl .= '?wsusername='.urlencode($data->wsusername); $serverurl .= '&wspassword='.urlencode($data->wspassword);

token authentication

if you look to the Moodle test client PHP code, you will notice that username/password are sent as GET parameters. //wwwroot/webservice/$protocol/simpleserver.php?wstoken=your_token $serverurl = "$CFG->wwwroot/webservice/$protocol/server.php"; $serverurl .= '?wstoken='.urlencode($data->token);