Creating a web service client: Difference between revisions
From MoodleDocs
Line 14: | Line 14: | ||
= How to get a user token = | = How to get a user token = | ||
{ | {{Moodle_2.2}} Your client can call the script located in /login/token.php with a simple HTTP request. We highly recommend to do it securely with HTTPS. | ||
The required parameters are: | The required parameters are: | ||
* username | * username |
Revision as of 06:47, 17 November 2011
Moodle 2.0
You need to know how to setup a web service first.
To see the API Documentation, connect as Admin and go to Administration > Plugins > Web services > API Documentation
Officially supported protocols
- REST: the Moodle REST server accepts GET/POST parameters and return XML/JSON values. This server is not RESTfull.
- SOAP: the Moodle SOAP server is based on the Zend SOAP server (itself based on the PHP SOAP server). Zend publishes a Zend SOAP client. The current server implementation doesn't fully 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 issues MDL-28988 / MDL-28989
- XML-RPC: the Moodle XML-RPC server is based on Zend XML-RPC server. Zend also publishes a Zend XML-RPC client.
- AMF: the Moodle AMF server is based on the Zend AMF server. The test client can be found in Settings blocks > Site Administration > Development > Web service test client > AMF Test client.
Demo client examples
Demo client sample codes can be downloaded on Github.
How to get a user token
Moodle 2.2
Your client can call the script located in /login/token.php with a simple HTTP request. We highly recommend to do it securely with HTTPS.
The required parameters are:
- username
- password
- service shortname - The service shortname is usually hardcoded in the pre-build service (db/service.php files). Moodle administrator will be able to edit shortnames for service created on the fly: MDL-29807. If you want to use the Mobile service, its shortname is moodle_mobile_app. Also useful to know, the database shortname field can be found in the table named external_services.
Call:
https://www.yourmoodle.com/login/token.php?username=USERNAME&password=PASSWORD&service=SERVICESHORTNAME //Moodle mobile service shortname => moodle_mobile_app
Get in return:
{token:4ed876sd87g6d8f7g89fsg6987dfh78d}