<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="sv">
	<id>https://docs.moodle.org/4x/sv/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Donalm</id>
	<title>MoodleDocs - Användarbidrag [sv]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/4x/sv/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Donalm"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/Special:Bidrag/Donalm"/>
	<updated>2026-04-21T03:09:51Z</updated>
	<subtitle>Användarbidrag</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=33196</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=33196"/>
		<updated>2008-03-05T03:31:06Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* Tell us! */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page describes internals of how to add a new web service to Moodle.  If you are just trying to connect to Moodle to do some stuff then come to the [[Development:Web_services]] page and help us build up a standard set of functions.&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket science. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;dangerous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system/listMethods&lt;br /&gt;
* system/methodSignature&lt;br /&gt;
* system/methodHelp&lt;br /&gt;
* system/listServices&lt;br /&gt;
Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system/keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php. Note that the _name and _description suffixes are required:&lt;br /&gt;
&lt;br /&gt;
 $string[&#039;yummy_beer_name&#039;]                = &#039;Yummy Beer&#039;;&lt;br /&gt;
 $string[&#039;yummy_beer_description&#039;]         = &#039;A service to bribe your sysadmin with promises of gourmet beer.&#039;;&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection recognise your edits.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll almost always need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function, but it must be named with a prefix of the module name, e.g. forum_mnet_publishes. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_sp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Remember that if you&#039;re writing such a function for a module, the function name must be prefixed with your module name, e.g. modulename_mnet_publishes.&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is entirely up to you, but you need to create a language file in (for example) lang/en_utf8/mod_forum.php to store your service name and description, for example:&lt;br /&gt;
&lt;br /&gt;
  $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
  $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
Note that your service name (in this example &#039;sso_idp&#039;) is suffixed with _name and _description.&lt;br /&gt;
&lt;br /&gt;
Turning back to the mnet_publishes function, your associative array has an &#039;apiversion&#039; key, that allows you to provide more than one version of your API. This is really provided for future use, and isn&#039;t implemented in the code yet. We anticipate that eventually APIs will have to change, and this should allow newer Moodles to still be able to communicate with older Moodles. While this is unavoidable, it&#039;s something that we want to put of for as long as possible.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of method or function names that constitute the service. When an admin enables this service for a host, he&#039;s really permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
Calling a function remotely will require your XML-RPC client to pass something like this to the Moodle XML-RPC server as the function name:&lt;br /&gt;
 &amp;quot;mod/forum/rpclib.php/somefunction&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Other Implementations==&lt;br /&gt;
XML-RPC won&#039;t work for everyone. If you&#039;re planning a REST or SOAP service, please consider putting your work into mnet/soap or mnet/rest, so that it&#039;s alongside mnet/xmlrpc. The work we&#039;ve done in the mnet directory might be useful to you as well, so rather than re-invent the wheel, have a look at our code to see if it meets any of your needs.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Mahoodle&amp;diff=32186</id>
		<title>Mahoodle</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Mahoodle&amp;diff=32186"/>
		<updated>2008-02-14T13:22:07Z</updated>

		<summary type="html">&lt;p&gt;Donalm: Configure SSO for Moodle and Mahara&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A PDF has been created to help users in configuring Moodle and Mahara to network together, supporting Single-Sign-On (SSO). The 3MB document titled &amp;quot;Mahoodle&amp;quot; has been uploaded to the page here:&lt;br /&gt;
https://eduforge.org/docman/?group_id=176&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25544</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25544"/>
		<updated>2007-08-02T06:40:19Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system/listMethods&lt;br /&gt;
* system/methodSignature&lt;br /&gt;
* system/methodHelp&lt;br /&gt;
* system/listServices&lt;br /&gt;
Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system/keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php. Note that the _name and _description suffixes are required:&lt;br /&gt;
&lt;br /&gt;
 $string[&#039;yummy_beer_name&#039;]                = &#039;Yummy Beer&#039;;&lt;br /&gt;
 $string[&#039;yummy_beer_description&#039;]         = &#039;A service to bribe your sysadmin with promises of gourmet beer.&#039;;&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection recognise your edits.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll almost always need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function, but it must be named with a prefix of the module name, e.g. forum_mnet_publishes. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_sp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
Remember that if you&#039;re writing such a function for a module, the function name must be prefixed with your module name, e.g. modulename_mnet_publishes.&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is entirely up to you, but you need to create a language file in (for example) lang/en_utf8/mod_forum.php to store your service name and description, for example:&lt;br /&gt;
&lt;br /&gt;
  $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
  $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
Note that your service name (in this example &#039;sso_idp&#039;) is suffixed with _name and _description.&lt;br /&gt;
&lt;br /&gt;
Turning back to the mnet_publishes function, your associative array has an &#039;apiversion&#039; key, that allows you to provide more than one version of your API. This is really provided for future use, and isn&#039;t implemented in the code yet. We anticipate that eventually APIs will have to change, and this should allow newer Moodles to still be able to communicate with older Moodles. While this is unavoidable, it&#039;s something that we want to put of for as long as possible.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of method or function names that constitute the service. When an admin enables this service for a host, he&#039;s really permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
Calling a function remotely will require your XML-RPC client to pass something like this to the Moodle XML-RPC server as the function name:&lt;br /&gt;
 &amp;quot;mod/forum/rpclib.php/somefunction&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Other Implementations==&lt;br /&gt;
XML-RPC won&#039;t work for everyone. If you&#039;re planning a REST or SOAP service, please consider putting your work into mnet/soap or mnet/rest, so that it&#039;s alongside mnet/xmlrpc. The work we&#039;ve done in the mnet directory might be useful to you as well, so rather than re-invent the wheel, have a look at our code to see if it meets any of your needs.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25542</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25542"/>
		<updated>2007-08-02T02:10:03Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system/listMethods&lt;br /&gt;
* system/methodSignature&lt;br /&gt;
* system/methodHelp&lt;br /&gt;
* system/listServices&lt;br /&gt;
Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system/keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php. Note that the _name and _description suffixes are required:&lt;br /&gt;
&lt;br /&gt;
 $string[&#039;yummy_beer_name&#039;]                = &#039;Yummy Beer&#039;;&lt;br /&gt;
 $string[&#039;yummy_beer_description&#039;]         = &#039;A service to bribe your sysadmin with promises of gourmet beer.&#039;;&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection recognise your edits.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll almost always need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_sp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is entirely up to you, but you need to create a language file in (for example) lang/en_utf8/mod_forum.php to store your service name and description, for example:&lt;br /&gt;
&lt;br /&gt;
  $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
  $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
Note that your service name (in this example &#039;sso_idp&#039;) is suffixed with _name and _description.&lt;br /&gt;
&lt;br /&gt;
Turning back to the mnet_publishes function, your associative array has an &#039;apiversion&#039; key, that allows you to provide more than one version of your API. This is really provided for future use, and isn&#039;t implemented in the code yet. We anticipate that eventually APIs will have to change, and this should allow newer Moodles to still be able to communicate with older Moodles. While this is unavoidable, it&#039;s something that we want to put of for as long as possible.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of method or function names that constitute the service. When an admin enables this service for a host, he&#039;s really permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
Calling a function remotely will require your XML-RPC client to pass something like this to the Moodle XML-RPC server as the function name:&lt;br /&gt;
 &amp;quot;mod/forum/rpclib.php/somefunction&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Other Implementations==&lt;br /&gt;
XML-RPC won&#039;t work for everyone. If you&#039;re planning a REST or SOAP service, please consider putting your work into mnet/soap or mnet/rest, so that it&#039;s alongside mnet/xmlrpc. The work we&#039;ve done in the mnet directory might be useful to you as well, so rather than re-invent the wheel, have a look at our code to see if it meets any of your needs.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25541</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25541"/>
		<updated>2007-08-02T02:08:49Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system/listMethods&lt;br /&gt;
* system/methodSignature&lt;br /&gt;
* system/methodHelp&lt;br /&gt;
* system/listServices&lt;br /&gt;
Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system/keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php. Note that the _name and _description suffixes are required:&lt;br /&gt;
&lt;br /&gt;
 $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
 $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection recognise your edits.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll almost always need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_sp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is entirely up to you, but you need to create a language file in (for example) lang/en_utf8/mod_forum.php to store your service name and description, for example:&lt;br /&gt;
&lt;br /&gt;
  $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
  $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
Note that your service name (in this example &#039;sso_idp&#039;) is suffixed with _name and _description.&lt;br /&gt;
&lt;br /&gt;
Turning back to the mnet_publishes function, your associative array has an &#039;apiversion&#039; key, that allows you to provide more than one version of your API. This is really provided for future use, and isn&#039;t implemented in the code yet. We anticipate that eventually APIs will have to change, and this should allow newer Moodles to still be able to communicate with older Moodles. While this is unavoidable, it&#039;s something that we want to put of for as long as possible.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of method or function names that constitute the service. When an admin enables this service for a host, he&#039;s really permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
Calling a function remotely will require your XML-RPC client to pass something like this to the Moodle XML-RPC server as the function name:&lt;br /&gt;
 &amp;quot;mod/forum/rpclib.php/somefunction&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Other Implementations==&lt;br /&gt;
XML-RPC won&#039;t work for everyone. If you&#039;re planning a REST or SOAP service, please consider putting your work into mnet/soap or mnet/rest, so that it&#039;s alongside mnet/xmlrpc. The work we&#039;ve done in the mnet directory might be useful to you as well, so rather than re-invent the wheel, have a look at our code to see if it meets any of your needs.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25540</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25540"/>
		<updated>2007-08-02T01:11:29Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system/listMethods&lt;br /&gt;
* system/methodSignature&lt;br /&gt;
* system/methodHelp&lt;br /&gt;
* system/listServices&lt;br /&gt;
Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system/keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection recognise your edits.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll almost always need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_sp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is entirely up to you, but you need to create a language file in (for example) lang/en_utf8/mod_forum.php to store your service name and description, for example:&lt;br /&gt;
&lt;br /&gt;
  $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
  $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
Note that your service name (in this example &#039;sso_idp&#039;) is suffixed with _name and _description.&lt;br /&gt;
&lt;br /&gt;
Turning back to the mnet_publishes function, your associative array has an &#039;apiversion&#039; key, that allows you to provide more than one version of your API. This is really provided for future use, and isn&#039;t implemented in the code yet. We anticipate that eventually APIs will have to change, and this should allow newer Moodles to still be able to communicate with older Moodles. While this is unavoidable, it&#039;s something that we want to put of for as long as possible.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of method or function names that constitute the service. When an admin enables this service for a host, he&#039;s really permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
Calling a function remotely will require your XML-RPC client to pass something like this to the Moodle XML-RPC server as the function name:&lt;br /&gt;
 &amp;quot;mod/forum/rpclib.php/somefunction&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Other Implementations==&lt;br /&gt;
XML-RPC won&#039;t work for everyone. If you&#039;re planning a REST or SOAP service, please consider putting your work into mnet/soap or mnet/rest, so that it&#039;s alongside mnet/xmlrpc. The work we&#039;ve done in the mnet directory might be useful to you as well, so rather than re-invent the wheel, have a look at our code to see if it meets any of your needs.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25539</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25539"/>
		<updated>2007-08-02T00:07:04Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system/listMethods&lt;br /&gt;
* system/methodSignature&lt;br /&gt;
* system/methodHelp&lt;br /&gt;
* system/listServices&lt;br /&gt;
Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system/keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection recognise your edits.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll almost always need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_sp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is entirely up to you, but you need to create a language file in (for example) lang/en_utf8/mod_forum.php to store your service name and description, for example:&lt;br /&gt;
&lt;br /&gt;
  $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
  $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
Note that your service name (in this example &#039;sso_idp&#039;) is suffixed with _name and _description.&lt;br /&gt;
&lt;br /&gt;
Turning back to the mnet_publishes function, your associative array has an &#039;apiversion&#039; key, that allows you to provide more than one version of your API. This is really provided for future use, and isn&#039;t implemented in the code yet. We anticipate that eventually APIs will have to change, and this should allow newer Moodles to still be able to communicate with older Moodles. While this is unavoidable, it&#039;s something that we want to put of for as long as possible.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of method or function names that constitute the service. When an admin enables this service for a host, he&#039;s really permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
Calling a function remotely will require your XML-RPC client to pass something like this to the Moodle XML-RPC server as the function name:&lt;br /&gt;
 &amp;quot;mod/forum/rpclib.php/somefunction&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25538</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25538"/>
		<updated>2007-08-01T23:49:03Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection recognise your edits.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll almost always need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_sp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is entirely up to you, but you need to create a language file in (for example) lang/en_utf8/mod_forum.php to store your service name and description, for example:&lt;br /&gt;
&lt;br /&gt;
  $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
  $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
Note that your service name (in this example &#039;sso_idp&#039;) is suffixed with _name and _description.&lt;br /&gt;
&lt;br /&gt;
Turning back to the mnet_publishes function, your associative array has an &#039;apiversion&#039; key, that allows you to provide more than one version of your API. This is really provided for future use, and isn&#039;t implemented in the code yet. We anticipate that eventually APIs will have to change, and this should allow newer Moodles to still be able to communicate with older Moodles. While this is unavoidable, it&#039;s something that we want to put of for as long as possible.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of method or function names that constitute the service. When an admin enables this service for a host, he&#039;s really permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
Calling a function remotely will require your XML-RPC client to pass something like this to the Moodle XML-RPC server as the function name:&lt;br /&gt;
 &amp;quot;mod/forum/rpclib.php/somefunction&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25537</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25537"/>
		<updated>2007-08-01T23:44:33Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll almost always need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_sp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is entirely up to you, but you need to create a language file in (for example) lang/en_utf8/mod_forum.php to store your service name and description, for example:&lt;br /&gt;
&lt;br /&gt;
  $string[&#039;sso_idp_name&#039;]                = &#039;SSO  (Identity Provider)&#039;;&lt;br /&gt;
  $string[&#039;sso_idp_description&#039;]         = &#039;A description of the SSO IDP service that allows an admin to know if he needs it or not.&#039;;&lt;br /&gt;
&lt;br /&gt;
Note that your service name (in this example &#039;sso_idp&#039;) is suffixed with _name and _description.&lt;br /&gt;
&lt;br /&gt;
Turning back to the mnet_publishes function, your associative array has an &#039;apiversion&#039; key, that allows you to provide more than one version of your API. This is really provided for future use, and isn&#039;t implemented in the code yet. We anticipate that eventually APIs will have to change, and this should allow newer Moodles to still be able to communicate with older Moodles. While this is unavoidable, it&#039;s something that we want to put of for as long as possible.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of method or function names that constitute the service. When an admin enables this service for a host, he&#039;s really permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25536</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25536"/>
		<updated>2007-08-01T23:27:55Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll normally need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request or what have you. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_idp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
        &lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is fairly arbitrary, but it will be presented to the system administrator to allow him to enable or disable your service for each host that he peers with, so it should be adequately descriptive to allow him to do this with confidence.&lt;br /&gt;
&lt;br /&gt;
Generally, you want to get your API right first time and then never change it, but if you find that you need to revise it in future, you can enable more than one version of the same service for XML-RPC.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of methods that constitute the service. When an admin enables this service for a host, he&#039;s permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25535</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25535"/>
		<updated>2007-08-01T23:27:25Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an array of associative arrays with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
  return array($yummy_beer);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll normally need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request or what have you. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_idp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
&lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
        &lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
        &lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is fairly arbitrary, but it will be presented to the system administrator to allow him to enable or disable your service for each host that he peers with, so it should be adequately descriptive to allow him to do this with confidence.&lt;br /&gt;
&lt;br /&gt;
Generally, you want to get your API right first time and then never change it, but if you find that you need to revise it in future, you can enable more than one version of the same service for XML-RPC.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of methods that constitute the service. When an admin enables this service for a host, he&#039;s permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25534</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25534"/>
		<updated>2007-08-01T23:26:03Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an associative array with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==Functions in Modules==&lt;br /&gt;
The mechanics of XML-RPC are such that there are few functions that it would be useful to call directly from a remote server; you&#039;ll normally need some kind of wrapper function to establish a security context or identify the server that&#039;s making the request or what have you. Partly for this reason, and partly so that it would be really obvious which functions are available to remote servers (i.e. really difficult for someone to call some arbitrary function in Moodle), we mandated that all XML-RPC-callable functions should be implemented in a special file called rpclib.php, so if you want to call a function in mod/forum/lib.php, you&#039;ll need to create a file called mod/forum/rpclib.php, and implement a wrapper function in that file that calls the function in mod/forum/lib.php.&lt;br /&gt;
&lt;br /&gt;
For rpclib.php files, it is still also necessary to create an mnet_publishes function. This function must return an array in the same format as the one detailed above for auth and enrol plugins. Let&#039;s look at that in a little more detail by reviewing the method from the auth_plugin_mnet class.&lt;br /&gt;
&lt;br /&gt;
For the benefit of administrators, your functions must be grouped into &amp;quot;Services&amp;quot;. Some of the services that we&#039;ve already implemented include sso_idp; the &#039;Single-Sign-On Identity Provider&#039; service, and sso_idp; the &#039;Single-Sign-On Service Provider&#039; service. You can see that the mnet_publishes method for that plugin returns an array with two elements. These elements provide information on the sso_idp and sso_sp services.&lt;br /&gt;
&lt;br /&gt;
    /**&lt;br /&gt;
     * Provides the allowed RPC services from this class as an array.&lt;br /&gt;
     * @return array  Allowed RPC services.&lt;br /&gt;
     */&lt;br /&gt;
    function mnet_publishes() {&lt;br /&gt;
&lt;br /&gt;
        $sso_idp = array();&lt;br /&gt;
        $sso_idp[&#039;name&#039;]        = &#039;sso_idp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_idp[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
        $sso_idp[&#039;methods&#039;]     = array(&#039;user_authorise&#039;,&#039;keepalive_server&#039;, &#039;kill_children&#039;,&lt;br /&gt;
                                        &#039;refresh_log&#039;, &#039;fetch_user_image&#039;, &#039;fetch_theme_info&#039;,&lt;br /&gt;
                                        &#039;update_enrolments&#039;);&lt;br /&gt;
&lt;br /&gt;
        $sso_sp = array();&lt;br /&gt;
        $sso_sp[&#039;name&#039;]         = &#039;sso_sp&#039;; // Name &amp;amp; Description go in lang file&lt;br /&gt;
        $sso_sp[&#039;apiversion&#039;]   = 1;&lt;br /&gt;
        $sso_sp[&#039;methods&#039;]      = array(&#039;keepalive_client&#039;,&#039;kill_child&#039;);&lt;br /&gt;
&lt;br /&gt;
        return array($sso_idp, $sso_sp);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The name that you give your service is fairly arbitrary, but it will be presented to the system administrator to allow him to enable or disable your service for each host that he peers with, so it should be adequately descriptive to allow him to do this with confidence.&lt;br /&gt;
&lt;br /&gt;
Generally, you want to get your API right first time and then never change it, but if you find that you need to revise it in future, you can enable more than one version of the same service for XML-RPC.&lt;br /&gt;
&lt;br /&gt;
Finally, you provide a list of methods that constitute the service. When an admin enables this service for a host, he&#039;s permitting the host to remotely call the methods or functions that you list here.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25533</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25533"/>
		<updated>2007-08-01T22:25:36Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an associative array with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
When you&#039;re writing your method, it&#039;s good practice to add a docblock with @param and @return values, because Moodle will read that information and provide it on to remote servers who call the introspection methods (e.g. system.methodSignature). This information is updated every time you hit /admin/index.php, so if you update the docblock for your function, you need to visit that page to have Moodle&#039;s introspection.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25532</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25532"/>
		<updated>2007-08-01T22:21:47Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an associative array with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25531</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25531"/>
		<updated>2007-08-01T22:18:13Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an associative array with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
So - once you&#039;ve implemented your method, you&#039;re ready to call it from your application. Your XML-RPC client needs to pass a function name to Moodle&#039;s XML-RPC server, that allows the server to identify the file and function to execute. The name you pass is a concatenation of the path to the file, and the name of your function, e.g.&lt;br /&gt;
&lt;br /&gt;
 &amp;quot;/auth/bribeme/auth.php/buymebeer&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25485</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25485"/>
		<updated>2007-07-31T07:47:00Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
I recommend that you enter something like this (assuming your application&#039;s IP address is 192.168.0.7):&lt;br /&gt;
192.168.0.7/32&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need. Moodle knows your server is friendly, and will XML-RPC with it, without requiring it to encrypt or sign anything.&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==Methods of auth and enrol objects==&lt;br /&gt;
Let&#039;s say you have an enrolment class called &#039;enrol_plugin_bribeme&#039; with the method &amp;quot;buy_me_beer&amp;quot; and you want to be able to call it via XML-RPC. First, your class&#039; constructor must not require arguments. The despatcher should be able to just ask for your enrolment object and get it... end of story.&lt;br /&gt;
&lt;br /&gt;
Second - enrol_plugin_bribeme must have a method called mnet_publishes which returns information about the &amp;quot;buy_me_beer&amp;quot; method. The method should return an associative array with the following structure:&lt;br /&gt;
  $yummy_beer = array();&lt;br /&gt;
  $yummy_beer[&#039;name&#039;]        = &#039;yummy_beer&#039;; // Name (&#039;Yummy Beer!&#039;) goes in lang file&lt;br /&gt;
  $yummy_beer[&#039;apiversion&#039;]  = 1;&lt;br /&gt;
  $yummy_beer[&#039;methods&#039;]     = array(&#039;buy_me_beer&#039;);&lt;br /&gt;
&lt;br /&gt;
The $yummy_beer[&#039;methods&#039;] array can contain any number of method names. The $yummy_beer[&#039;name&#039;] element is the name of this service, and this will appear in the admin interface to allow the service to be enabled and disabled for different hosts. You enter an identifier here, and the actual name goes in the appropriate lang file - in this case lang/en_utf8/enrol_bribeme.php.&lt;br /&gt;
&lt;br /&gt;
Just implement your method, and you&#039;re done.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25484</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25484"/>
		<updated>2007-07-31T07:29:43Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code, so I&#039;m not telling you where it is.&lt;br /&gt;
&lt;br /&gt;
==Tell us!==&lt;br /&gt;
Oh alright then. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;. Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first, however, if you do enable this and your site does got pwned please tell me so I can laugh and high five my co-workers.&lt;br /&gt;
&lt;br /&gt;
==So - back to those four categories of function we were talking about==&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be friendly to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25483</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25483"/>
		<updated>2007-07-31T07:21:59Z</updated>

		<summary type="html">&lt;p&gt;Donalm: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
Plaintext networking is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==A word on Encryption==&lt;br /&gt;
There&#039;s really no voodoo going on in the Moodle encryption and signing process. We&#039;ve tried to stick to the W3C&#039;s XML-ENC and XML-DSIG standards, and because our implementation of them is fairly simple and naive, getting your application to mimic that behaviour&#039;s is not (as we say) rocket surgery. The Mahara implementation of XML-ENC/XML-DSIG uses some PHP5 features that make things even easier, so that might be a useful starting point for adventurous hackers.&lt;br /&gt;
&lt;br /&gt;
==But if I&#039;m not using Encryption?==&lt;br /&gt;
Then you need to tell Moodle to privilege the machine on which your application is running, and allow it to use the XML-RPC service without having to sign or encrypt its messages. You can do this at /admin/mnet/trustedhosts.php, which you can browse to in the admin panel at&lt;br /&gt;
Networking:XML-RPC hosts&lt;br /&gt;
&lt;br /&gt;
==What can Moodle&#039;s XML-RPC do?==&lt;br /&gt;
By default, we&#039;ve strictly limited the functions that can be remotely called. These fall into four categories:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
==But what if I have a death wish or something?==&lt;br /&gt;
Don&#039;t worry - we&#039;ve thought of you too. If you want to do something that&#039;s not in that list, there is a special &#039;shoot-yourself-in-the-foot&#039; switch that you can enable by tweaking a field in your database. This switch - if enabled - would allow the remote application to do ANYTHING to your Moodle that has a corresponding function anywhere in the code. In your config table, the row with the &#039;name&#039; mnet_dispatcher_mode, should have a &#039;value&#039; of &#039;promiscuous&#039;.&lt;br /&gt;
&lt;br /&gt;
Please don&#039;t do that. There are other ways to enable whatever it is you want to enable, so please exhaust those first.&lt;br /&gt;
&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be useful to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25482</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25482"/>
		<updated>2007-07-31T07:01:50Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* XML-RPC background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
This is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
By default, there are four kinds of function that might be called remotely:&lt;br /&gt;
* special &#039;system&#039; functions&lt;br /&gt;
* methods of an authorisation object&lt;br /&gt;
* methods of an enrolment object&lt;br /&gt;
* functions in a module&lt;br /&gt;
&lt;br /&gt;
The system functions return information about the services and methods that your API is making available to remote servers. These functions are:&lt;br /&gt;
* system.listMethods&lt;br /&gt;
* system.methodSignature&lt;br /&gt;
* system.methodHelp&lt;br /&gt;
* system.listServices&lt;br /&gt;
The dot-notation is not an XML-RPC standard, but it does seem to be widely deployed, so we figured it would be useful to implement that. You can call all of these methods with a slash (like system/listMethods) if that&#039;s important to you. Missing from this list is a non-standard method, that we implemented to help with key-exchange and key-rotation:&lt;br /&gt;
* system.keyswap&lt;br /&gt;
This method returns the public key that your Moodle and Mahara peers will use for message encryption and signing. It is always possible to call this method from any host without signing or encryption, otherwise Moodles would never be able to exchange keys, and for that reason, it might be really useful to use as a test function. If you get a result back from this function, you have a foot in the door to setting up plaintext XML-RPC between your application and Moodle.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25481</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=25481"/>
		<updated>2007-07-31T06:24:03Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* XML-RPC background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, bypassing Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
This is only likely to be useful if you have another application which:&lt;br /&gt;
* is not a Moodle&lt;br /&gt;
* is completely under your control (for security reasons)&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
* allow trusted sites to access web services by configuring &#039;&#039;&#039;admin/mnet/trustedhosts.php&#039;&#039;&#039;&lt;br /&gt;
* start by pointing your browser to &#039;&#039;&#039;mnet/xmlrpc/server.php&#039;&#039;&#039; - this should show an XML error message&lt;br /&gt;
* use POST data in this format:&lt;br /&gt;
 // $method is something like: &amp;quot;mod/forum/lib/forum_add_instance&amp;quot;&lt;br /&gt;
 // $params is an array of parameters. A parameter might itself be an array.&lt;br /&gt;
 // use only Whitelist characters that are permitted in a method name&lt;br /&gt;
 // The method name must not begin with a / - avoid absolute paths&lt;br /&gt;
 // A dot character . is only allowed in the filename, i.e. something.php&lt;br /&gt;
* use &#039;&#039;&#039;mnet/xmlrpc/client.php&#039;&#039;&#039; to make remote xmlrpc calls&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=24820</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=24820"/>
		<updated>2007-07-05T06:06:01Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* XML-RPC background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network [https://docs.moodle.org/en/Moodle_Network] features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, with Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=24819</id>
		<title>Web services API</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=Web_services_API&amp;diff=24819"/>
		<updated>2007-07-05T06:01:15Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* XML-RPC background */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Overview ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The Web Services API provides Moodle with a web service interface to allow exchange of data and information with other systems.&lt;br /&gt;
&lt;br /&gt;
For example,&lt;br /&gt;
# Manage user data - send and retrieve the information,&lt;br /&gt;
# Manage course enrolments - add/remove teachers and students,&lt;br /&gt;
# Course management - create new courses based on templates,&lt;br /&gt;
# Gradebook info - extract grades information from Moodle.&lt;br /&gt;
&lt;br /&gt;
==XML-RPC background==&lt;br /&gt;
The XML-RPC service allows other servers to contact your Moodle server and request that it call a function. The Moodle server might do something, like create a user, or it might fetch some data and serve it back to your host.&lt;br /&gt;
&lt;br /&gt;
To communicate like this with another Moodle host, you&#039;d normally use the Moodle Network features, but it&#039;s also possible for other kinds of program to contact your Moodle, using plain-old-XML-RPC, with Moodle Network&#039;s encryption or signed-message features.&lt;br /&gt;
&lt;br /&gt;
==The server script==&lt;br /&gt;
&lt;br /&gt;
==Things you can do==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/view.php?f=965 Web Services forum]  &lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Web services API]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19267</id>
		<title>MNet</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19267"/>
		<updated>2007-01-10T20:59:46Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* Security */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.8}}&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;Draft -- for 1.8 functionality&#039;&#039; --[[User:Martin Langhoff|Martin Langhoff]] 22:44, 26 December 2006 (CST) &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
Moodle Network is a new feature that is set to be a part of the 1.8 release of Moodle. The network feature allows a Moodle administrator to establish a link with another Moodle, and to share some resources with the users of that Moodle.&lt;br /&gt;
&lt;br /&gt;
The initial release of Moodle Network is bundled with a new Authentication Plugin, which makes single-sign-on between Moodles possible. A user with the username &amp;lt;em&amp;gt;jody&amp;lt;/em&amp;gt; logs in to her Moodle server as normal, and clicks on a link that takes her to a page on another Moodle server. Normally, she would have only the privileges of a guest on the remote Moodle, but behind the scenes, single-sign-on has established a fully authenticated session for Jody on the remote site.&lt;br /&gt;
&lt;br /&gt;
=Security=&lt;br /&gt;
The Moodle network feature requires that your server has the Curl and OpenSSL extensions installed. When you install or upgrade to Moodle 1.8, your system will generate a new OpenSSL certificate for encrypted communication with other Moodles, and will thereafter rotate encryption keys on a monthly basis (approx).&lt;br /&gt;
&lt;br /&gt;
Communication takes place over an XML-RPC transport, and the XML-RPC documents are wrapped first in an XMLDSIG (XML digital signature) envelope, and then in an XMLENC (XML encryption) envelope. The encryption all happens within PHP, and does not require an https (Apache SSL) server.&lt;br /&gt;
&lt;br /&gt;
Refs:&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.w3.org/TR/xmldsig-core/ XML Digital Signatures]&amp;lt;br /&amp;gt;&lt;br /&gt;
[http://www.w3.org/TR/xmlenc-core/ XML Encryption]&lt;br /&gt;
&lt;br /&gt;
A special mode can be enabled which would allow a machine with a specified IP address to make calls to the XML-RPC layer without using either encryption or signature envelopes. This mode is provided to enable Moodle to communicate with other software systems in which the integration of signatures and encryption might be prohibitively difficult. It is not envisioned that unencrypted inter-Moodle networking will ever be enabled.&lt;br /&gt;
&lt;br /&gt;
=Peer to Peer Network=&lt;br /&gt;
&lt;br /&gt;
This is the basic layout of the system. It can be very useful to run one Moodle per faculty or departments, each with its own user management, and yet permit users to roam across the Moodle installs... subject to permissions of course. &lt;br /&gt;
&lt;br /&gt;
==Setup==&lt;br /&gt;
&lt;br /&gt;
The instructions will cover 2 Moodle installations: MoodleA and MoodleB. Both are installed correctly and have never had a Moodle Network configuration.&lt;br /&gt;
&lt;br /&gt;
# Get them to talk to eachother&lt;br /&gt;
## Ensure Admin / Server / Environment indicates you have curl installed&lt;br /&gt;
## If MoodleA and MoodleB are hosted in the same domain, ensure they have a different cookie prefix. Note that changing the cookie prefix will log you out! &lt;br /&gt;
## On both, go to Admin / Network / Settings and turn Networking ON.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers - put the URL of MoodleB under &amp;quot;Add New Host&amp;quot; and click Add.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
# Get user roaming going&lt;br /&gt;
## On both, go to Admin / Users / Authentication and enable Moodle Network authentication plugin. Click on &#039;Settings&#039; and enable auto_add_remote_users.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable SSO-IDP publish and subscribe, and SSO-SP publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## On both, got to Admin / Users / Permissions / Define Roles, only roles that have &amp;quot;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;quot; will be allowed to roam. Grant the privilege as appropriate.&lt;br /&gt;
## On both, go to the homepage, and add the &#039;Network Servers&#039; block.&lt;br /&gt;
## To test, it is recommended to use a different browser (even on a different machine) that is logged in to neither. Login to MoodleA with a non-administrator account that has the permissions to roam. You should see the Network Servers block, and clicking on it you should go to MoodleB with a newly autocreated account. &lt;br /&gt;
# Get remote enrolments going -- this is optional. It allows administrator of MoodleB can enrol users that are &amp;quot;native&amp;quot; to MoodleB in courses in MoodleA, and viceversa.&lt;br /&gt;
## On both, go to Admin / Courses / Enrolment and enable Moodle Network enrolment plugin (click Save). Click on &#039;Edit&#039; and enable &#039;allow_allcourses&#039; or select some courses or categories to be remotely enrolled.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable Enrolment publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## To use, in MoodleA go to Admin / Courses / Enrolment / Moodle Network -&amp;gt; Edit / Manage Network Enrolments and you will see MoodleB listed. Click on MoodleB and you will see a list of your users, and the courses that MoodleB offers for remote enrolment.&lt;br /&gt;
&lt;br /&gt;
==Using it==&lt;br /&gt;
&lt;br /&gt;
=Connecting to a Community Hub=&lt;br /&gt;
A Community Hub is a Moodle server that is configured to accept connections from other Moodle servers, and to provide a set of services to users of these other servers. This guideline will direct you to connect to a Community Hub, assess the services it has to offer, and enable those services for your users.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Get talking to the Hub&lt;br /&gt;
## Ensure that  the Admin / Server / Environment  page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on&lt;br /&gt;
## Go to Admin / Network / Peers and enter the URL of Community Hub under &amp;quot;Add New Host&amp;quot;. Click &amp;lt;em&amp;gt;Add&amp;lt;/em&amp;gt;&lt;br /&gt;
## The host details for the Community Hub should appear with the Site Name field already populated. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## The details will be written to your database and two new tabs will appear in this window: &#039;Services&#039; and &#039;Logs&#039;. Click &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt;&lt;br /&gt;
##A list of services will appear, each with a checkbox for &#039;publish&#039; and &#039;subscribe&#039;. Check the checkboxes for any services you want to publish or subscribe to&lt;br /&gt;
==Using it==&lt;br /&gt;
If the Community Hub has already enabled a service for you, there will be a tick alongside the appropriate checkbox, for example: if the Hub is &amp;lt;em&amp;gt;publishing&amp;lt;/em&amp;gt; Moodle Networked Enrolment, then a tick will appear alongside the &amp;lt;em&amp;gt;subscribe&amp;lt;/em&amp;gt; checkbox for this service. Note that in order to enable some functionality, prominently &amp;lt;em&amp;gt;single-sign-on&amp;lt;/em&amp;gt;, you may have to &amp;lt;em&amp;gt;publish&amp;lt;/em&amp;gt; a service, e.g. the &amp;lt;em&amp;gt;Identity Provider&amp;lt;/em&amp;gt; service. The Community Hub will access this service on your Moodle, asking it to authenticate your users.&lt;br /&gt;
# Enable Roaming&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;SSO (Service Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Publish &amp;lt;em&amp;gt;SSO (Identity Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Users / Permissions / Define Roles, and grant the capability &amp;lt;em&amp;gt;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;lt;/em&amp;gt; to an appropriate role&lt;br /&gt;
## Go to Admin / Users / Authentication and enable the &amp;lt;em&amp;gt;Moodle Network authentication&amp;lt;/em&amp;gt; plugin&lt;br /&gt;
## Go to your homepage, turn on editing, and add the &#039;Network Servers&#039; block&lt;br /&gt;
## Using a different web-browser, log on as a non-admin user who inhabits the role you granted the roaming capability to&lt;br /&gt;
## Note that the Community Hub is listed in the Network Servers block on the homepage. Click on the link to that server&lt;br /&gt;
## Some of your user details will be transferred to the Community Hub server, and a browsing session will be started for you as if you had logged on there directly&lt;br /&gt;
# Enable Networked Enrolment&lt;br /&gt;
## Return to the web browser you&#039;ve been using as the site administrator&lt;br /&gt;
## Go to Admin / Network / Peers and click on the entry for the Community Hub.&lt;br /&gt;
## Click on the Services tab&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;Moodle Networked Enrolment&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Courses / Enrolment and enable the &amp;lt;em&amp;gt;Moodle Network enrolment&amp;lt;/em&amp;gt; plugin. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;edit&amp;lt;/em&amp;gt; to view the details for networked enrolments.&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Manage Moodle Network Enrolments&amp;lt;/em&amp;gt; to see a list of Moodle servers that offer this service to you&lt;br /&gt;
## Click on a server name to view a list of courses that the server offers to your users&lt;br /&gt;
## Click on a course name, to view a list users that you can enrol in this course&lt;br /&gt;
## Enrol users&lt;br /&gt;
## Profit!&lt;br /&gt;
&lt;br /&gt;
=Running a community Hub=&lt;br /&gt;
A Community Hub is a regular Moodle site that runs in a special mode. As a Moodle Administrator, when you add another Moodle site to your list of network peers, your Moodle will contact that site to find out what it is called, and to request its public key for encrypted communication. Normally, the remote server will simply provide this information without making any record of the transaction.&lt;br /&gt;
&lt;br /&gt;
A Community Hub is different. As soon as you add an entry for a Community Hub to your system, the Community Hub will create an entry for your server in its list of hosts, and may immediately begin to offer services to the users of your site.&lt;br /&gt;
This section will guide you to set up a community hub, and select services to offer to all comers.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Enable Networking&lt;br /&gt;
## Ensure that the Admin / Server / Environment page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on &lt;br /&gt;
## Go to Admin / Network / Peers and tick the checkbox for &amp;lt;em&amp;gt;Register all hosts&amp;lt;/em&amp;gt;. Click on &amp;lt;em&amp;gt;Save Changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## On the same page, the first entry in your list of hosts should be &amp;lt;em&amp;gt;All hosts&amp;lt;/em&amp;gt;. Click this link&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt; and enable any services you want to offer to all comers&lt;br /&gt;
&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19265</id>
		<title>MNet</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19265"/>
		<updated>2007-01-10T20:44:28Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.8}}&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;Draft -- for 1.8 functionality&#039;&#039; --[[User:Martin Langhoff|Martin Langhoff]] 22:44, 26 December 2006 (CST) &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
Moodle Network is a new feature that is set to be a part of the 1.8 release of Moodle. The network feature allows a Moodle administrator to establish a link with another Moodle, and to share some resources with the users of that Moodle.&lt;br /&gt;
&lt;br /&gt;
The initial release of Moodle Network is bundled with a new Authentication Plugin, which makes single-sign-on between Moodles possible. A user with the username &amp;lt;em&amp;gt;jody&amp;lt;/em&amp;gt; logs in to her Moodle server as normal, and clicks on a link that takes her to a page on another Moodle server. Normally, she would have only the privileges of a guest on the remote Moodle, but behind the scenes, single-sign-on has established a fully authenticated session for Jody on the remote site.&lt;br /&gt;
&lt;br /&gt;
=Security=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Peer to Peer Network=&lt;br /&gt;
&lt;br /&gt;
This is the basic layout of the system. It can be very useful to run one Moodle per faculty or departments, each with its own user management, and yet permit users to roam across the Moodle installs... subject to permissions of course. &lt;br /&gt;
&lt;br /&gt;
==Setup==&lt;br /&gt;
&lt;br /&gt;
The instructions will cover 2 Moodle installations: MoodleA and MoodleB. Both are installed correctly and have never had a Moodle Network configuration.&lt;br /&gt;
&lt;br /&gt;
# Get them to talk to eachother&lt;br /&gt;
## Ensure Admin / Server / Environment indicates you have curl installed&lt;br /&gt;
## If MoodleA and MoodleB are hosted in the same domain, ensure they have a different cookie prefix. Note that changing the cookie prefix will log you out! &lt;br /&gt;
## On both, go to Admin / Network / Settings and turn Networking ON.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers - put the URL of MoodleB under &amp;quot;Add New Host&amp;quot; and click Add.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
# Get user roaming going&lt;br /&gt;
## On both, go to Admin / Users / Authentication and enable Moodle Network authentication plugin. Click on &#039;Settings&#039; and enable auto_add_remote_users.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable SSO-IDP publish and subscribe, and SSO-SP publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## On both, got to Admin / Users / Permissions / Define Roles, only roles that have &amp;quot;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;quot; will be allowed to roam. Grant the privilege as appropriate.&lt;br /&gt;
## On both, go to the homepage, and add the &#039;Network Servers&#039; block.&lt;br /&gt;
## To test, it is recommended to use a different browser (even on a different machine) that is logged in to neither. Login to MoodleA with a non-administrator account that has the permissions to roam. You should see the Network Servers block, and clicking on it you should go to MoodleB with a newly autocreated account. &lt;br /&gt;
# Get remote enrolments going -- this is optional. It allows administrator of MoodleB can enrol users that are &amp;quot;native&amp;quot; to MoodleB in courses in MoodleA, and viceversa.&lt;br /&gt;
## On both, go to Admin / Courses / Enrolment and enable Moodle Network enrolment plugin (click Save). Click on &#039;Edit&#039; and enable &#039;allow_allcourses&#039; or select some courses or categories to be remotely enrolled.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable Enrolment publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## To use, in MoodleA go to Admin / Courses / Enrolment / Moodle Network -&amp;gt; Edit / Manage Network Enrolments and you will see MoodleB listed. Click on MoodleB and you will see a list of your users, and the courses that MoodleB offers for remote enrolment.&lt;br /&gt;
&lt;br /&gt;
==Using it==&lt;br /&gt;
&lt;br /&gt;
=Connecting to a Community Hub=&lt;br /&gt;
A Community Hub is a Moodle server that is configured to accept connections from other Moodle servers, and to provide a set of services to users of these other servers. This guideline will direct you to connect to a Community Hub, assess the services it has to offer, and enable those services for your users.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Get talking to the Hub&lt;br /&gt;
## Ensure that  the Admin / Server / Environment  page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on&lt;br /&gt;
## Go to Admin / Network / Peers and enter the URL of Community Hub under &amp;quot;Add New Host&amp;quot;. Click &amp;lt;em&amp;gt;Add&amp;lt;/em&amp;gt;&lt;br /&gt;
## The host details for the Community Hub should appear with the Site Name field already populated. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## The details will be written to your database and two new tabs will appear in this window: &#039;Services&#039; and &#039;Logs&#039;. Click &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt;&lt;br /&gt;
##A list of services will appear, each with a checkbox for &#039;publish&#039; and &#039;subscribe&#039;. Check the checkboxes for any services you want to publish or subscribe to&lt;br /&gt;
==Using it==&lt;br /&gt;
If the Community Hub has already enabled a service for you, there will be a tick alongside the appropriate checkbox, for example: if the Hub is &amp;lt;em&amp;gt;publishing&amp;lt;/em&amp;gt; Moodle Networked Enrolment, then a tick will appear alongside the &amp;lt;em&amp;gt;subscribe&amp;lt;/em&amp;gt; checkbox for this service. Note that in order to enable some functionality, prominently &amp;lt;em&amp;gt;single-sign-on&amp;lt;/em&amp;gt;, you may have to &amp;lt;em&amp;gt;publish&amp;lt;/em&amp;gt; a service, e.g. the &amp;lt;em&amp;gt;Identity Provider&amp;lt;/em&amp;gt; service. The Community Hub will access this service on your Moodle, asking it to authenticate your users.&lt;br /&gt;
# Enable Roaming&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;SSO (Service Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Publish &amp;lt;em&amp;gt;SSO (Identity Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Users / Permissions / Define Roles, and grant the capability &amp;lt;em&amp;gt;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;lt;/em&amp;gt; to an appropriate role&lt;br /&gt;
## Go to Admin / Users / Authentication and enable the &amp;lt;em&amp;gt;Moodle Network authentication&amp;lt;/em&amp;gt; plugin&lt;br /&gt;
## Go to your homepage, turn on editing, and add the &#039;Network Servers&#039; block&lt;br /&gt;
## Using a different web-browser, log on as a non-admin user who inhabits the role you granted the roaming capability to&lt;br /&gt;
## Note that the Community Hub is listed in the Network Servers block on the homepage. Click on the link to that server&lt;br /&gt;
## Some of your user details will be transferred to the Community Hub server, and a browsing session will be started for you as if you had logged on there directly&lt;br /&gt;
# Enable Networked Enrolment&lt;br /&gt;
## Return to the web browser you&#039;ve been using as the site administrator&lt;br /&gt;
## Go to Admin / Network / Peers and click on the entry for the Community Hub.&lt;br /&gt;
## Click on the Services tab&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;Moodle Networked Enrolment&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Courses / Enrolment and enable the &amp;lt;em&amp;gt;Moodle Network enrolment&amp;lt;/em&amp;gt; plugin. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;edit&amp;lt;/em&amp;gt; to view the details for networked enrolments.&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Manage Moodle Network Enrolments&amp;lt;/em&amp;gt; to see a list of Moodle servers that offer this service to you&lt;br /&gt;
## Click on a server name to view a list of courses that the server offers to your users&lt;br /&gt;
## Click on a course name, to view a list users that you can enrol in this course&lt;br /&gt;
## Enrol users&lt;br /&gt;
## Profit!&lt;br /&gt;
&lt;br /&gt;
=Running a community Hub=&lt;br /&gt;
A Community Hub is a regular Moodle site that runs in a special mode. As a Moodle Administrator, when you add another Moodle site to your list of network peers, your Moodle will contact that site to find out what it is called, and to request its public key for encrypted communication. Normally, the remote server will simply provide this information without making any record of the transaction.&lt;br /&gt;
&lt;br /&gt;
A Community Hub is different. As soon as you add an entry for a Community Hub to your system, the Community Hub will create an entry for your server in its list of hosts, and may immediately begin to offer services to the users of your site.&lt;br /&gt;
This section will guide you to set up a community hub, and select services to offer to all comers.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Enable Networking&lt;br /&gt;
## Ensure that the Admin / Server / Environment page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on &lt;br /&gt;
## Go to Admin / Network / Peers and tick the checkbox for &amp;lt;em&amp;gt;Register all hosts&amp;lt;/em&amp;gt;. Click on &amp;lt;em&amp;gt;Save Changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## On the same page, the first entry in your list of hosts should be &amp;lt;em&amp;gt;All hosts&amp;lt;/em&amp;gt;. Click this link&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt; and enable any services you want to offer to all comers&lt;br /&gt;
&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19242</id>
		<title>MNet</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19242"/>
		<updated>2007-01-10T06:22:49Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.8}}&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;Draft -- for 1.8 functionality&#039;&#039; --[[User:Martin Langhoff|Martin Langhoff]] 22:44, 26 December 2006 (CST) &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
Moodle Network is a new feature that is set to be a part of the 1.8 release of Moodle. The network feature allows a Moodle administrator to establish a link with another Moodle, and to share some resources with the users of that Moodle.&lt;br /&gt;
&lt;br /&gt;
The initial release of Moodle Network is bundled with a new Authentication Plugin, which makes single-sign-on between Moodles possible. A user with the username &amp;lt;em&amp;gt;jody&amp;lt;/em&amp;gt; logs in to her Moodle server as normal, and clicks on a link that takes her to a page on another Moodle server. Normally, she would have only the privileges of a guest on the remote Moodle, but behind the scenes, single-sign-on has established a fully authenticated session for Jody on the remote site.&lt;br /&gt;
&lt;br /&gt;
In earlier releases of Moodle, no two users could have the same username. From Moodle 1.8 onwards, a username will be unique &amp;lt;em&amp;gt;per server&amp;lt;/em&amp;gt; so a user who authenticates elsewhere, and then roams to your site via single-sign-on, could have the same username as a user on your site.&lt;br /&gt;
&lt;br /&gt;
=Security=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Peer to Peer Network=&lt;br /&gt;
&lt;br /&gt;
This is the basic layout of the system. It can be very useful to run one Moodle per faculty or departments, each with its own user management, and yet permit users to roam across the Moodle installs... subject to permissions of course. &lt;br /&gt;
&lt;br /&gt;
==Setup==&lt;br /&gt;
&lt;br /&gt;
The instructions will cover 2 Moodle installations: MoodleA and MoodleB. Both are installed correctly and have never had a Moodle Network configuration.&lt;br /&gt;
&lt;br /&gt;
# Get them to talk to eachother&lt;br /&gt;
## Ensure Admin / Server / Environment indicates you have curl installed&lt;br /&gt;
## If MoodleA and MoodleB are hosted in the same domain, ensure they have a different cookie prefix. Note that changing the cookie prefix will log you out! &lt;br /&gt;
## On both, go to Admin / Network / Settings and turn Networking ON.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers - put the URL of MoodleB under &amp;quot;Add New Host&amp;quot; and click Add.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
# Get user roaming going&lt;br /&gt;
## On both, go to Admin / Users / Authentication and enable Moodle Network authentication plugin. Click on &#039;Settings&#039; and enable auto_add_remote_users.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable SSO-IDP publish and subscribe, and SSO-SP publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## On both, got to Admin / Users / Permissions / Define Roles, only roles that have &amp;quot;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;quot; will be allowed to roam. Grant the privilege as appropriate.&lt;br /&gt;
## On both, go to the homepage, and add the &#039;Network Servers&#039; block.&lt;br /&gt;
## To test, it is recommended to use a different browser (even on a different machine) that is logged in to neither. Login to MoodleA with a non-administrator account that has the permissions to roam. You should see the Network Servers block, and clicking on it you should go to MoodleB with a newly autocreated account. &lt;br /&gt;
# Get remote enrolments going -- this is optional. It allows administrator of MoodleB can enrol users that are &amp;quot;native&amp;quot; to MoodleB in courses in MoodleA, and viceversa.&lt;br /&gt;
## On both, go to Admin / Courses / Enrolment and enable Moodle Network enrolment plugin (click Save). Click on &#039;Edit&#039; and enable &#039;allow_allcourses&#039; or select some courses or categories to be remotely enrolled.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable Enrolment publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## To use, in MoodleA go to Admin / Courses / Enrolment / Moodle Network -&amp;gt; Edit / Manage Network Enrolments and you will see MoodleB listed. Click on MoodleB and you will see a list of your users, and the courses that MoodleB offers for remote enrolment.&lt;br /&gt;
&lt;br /&gt;
==Using it==&lt;br /&gt;
&lt;br /&gt;
=Connecting to a Community Hub=&lt;br /&gt;
A Community Hub is a Moodle server that is configured to accept connections from other Moodle servers, and to provide a set of services to users of these other servers. This guideline will direct you to connect to a Community Hub, assess the services it has to offer, and enable those services for your users.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Get talking to the Hub&lt;br /&gt;
## Ensure that  the Admin / Server / Environment  page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on&lt;br /&gt;
## Go to Admin / Network / Peers and enter the URL of Community Hub under &amp;quot;Add New Host&amp;quot;. Click &amp;lt;em&amp;gt;Add&amp;lt;/em&amp;gt;&lt;br /&gt;
## The host details for the Community Hub should appear with the Site Name field already populated. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## The details will be written to your database and two new tabs will appear in this window: &#039;Services&#039; and &#039;Logs&#039;. Click &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt;&lt;br /&gt;
##A list of services will appear, each with a checkbox for &#039;publish&#039; and &#039;subscribe&#039;. Check the checkboxes for any services you want to publish or subscribe to&lt;br /&gt;
==Using it==&lt;br /&gt;
If the Community Hub has already enabled a service for you, there will be a tick alongside the appropriate checkbox, for example: if the Hub is &amp;lt;em&amp;gt;publishing&amp;lt;/em&amp;gt; Moodle Networked Enrolment, then a tick will appear alongside the &amp;lt;em&amp;gt;subscribe&amp;lt;/em&amp;gt; checkbox for this service. Note that in order to enable some functionality, prominently &amp;lt;em&amp;gt;single-sign-on&amp;lt;/em&amp;gt;, you may have to &amp;lt;em&amp;gt;publish&amp;lt;/em&amp;gt; a service, e.g. the &amp;lt;em&amp;gt;Identity Provider&amp;lt;/em&amp;gt; service. The Community Hub will access this service on your Moodle, asking it to authenticate your users.&lt;br /&gt;
# Enable Roaming&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;SSO (Service Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Publish &amp;lt;em&amp;gt;SSO (Identity Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Users / Permissions / Define Roles, and grant the capability &amp;lt;em&amp;gt;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;lt;/em&amp;gt; to an appropriate role&lt;br /&gt;
## Go to Admin / Users / Authentication and enable the &amp;lt;em&amp;gt;Moodle Network authentication&amp;lt;/em&amp;gt; plugin&lt;br /&gt;
## Go to your homepage, turn on editing, and add the &#039;Network Servers&#039; block&lt;br /&gt;
## Using a different web-browser, log on as a non-admin user who inhabits the role you granted the roaming capability to&lt;br /&gt;
## Note that the Community Hub is listed in the Network Servers block on the homepage. Click on the link to that server&lt;br /&gt;
## Some of your user details will be transferred to the Community Hub server, and a browsing session will be started for you as if you had logged on there directly&lt;br /&gt;
# Enable Networked Enrolment&lt;br /&gt;
## Return to the web browser you&#039;ve been using as the site administrator&lt;br /&gt;
## Go to Admin / Network / Peers and click on the entry for the Community Hub.&lt;br /&gt;
## Click on the Services tab&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;Moodle Networked Enrolment&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Courses / Enrolment and enable the &amp;lt;em&amp;gt;Moodle Network enrolment&amp;lt;/em&amp;gt; plugin. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;edit&amp;lt;/em&amp;gt; to view the details for networked enrolments.&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Manage Moodle Network Enrolments&amp;lt;/em&amp;gt; to see a list of Moodle servers that offer this service to you&lt;br /&gt;
## Click on a server name to view a list of courses that the server offers to your users&lt;br /&gt;
## Click on a course name, to view a list users that you can enrol in this course&lt;br /&gt;
## Enrol users&lt;br /&gt;
## Profit!&lt;br /&gt;
&lt;br /&gt;
=Running a community Hub=&lt;br /&gt;
A Community Hub is a regular Moodle site that runs in a special mode. As a Moodle Administrator, when you add another Moodle site to your list of network peers, your Moodle will contact that site to find out what it is called, and to request its public key for encrypted communication. Normally, the remote server will simply provide this information without making any record of the transaction.&lt;br /&gt;
&lt;br /&gt;
A Community Hub is different. As soon as you add an entry for a Community Hub to your system, the Community Hub will create an entry for your server in its list of hosts, and may immediately begin to offer services to the users of your site.&lt;br /&gt;
This section will guide you to set up a community hub, and select services to offer to all comers.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Enable Networking&lt;br /&gt;
## Ensure that the Admin / Server / Environment page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on &lt;br /&gt;
## Go to Admin / Network / Peers and tick the checkbox for &amp;lt;em&amp;gt;Register all hosts&amp;lt;/em&amp;gt;. Click on &amp;lt;em&amp;gt;Save Changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## On the same page, the first entry in your list of hosts should be &amp;lt;em&amp;gt;All hosts&amp;lt;/em&amp;gt;. Click this link&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt; and enable any services you want to offer to all comers&lt;br /&gt;
&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19241</id>
		<title>MNet</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19241"/>
		<updated>2007-01-10T05:59:40Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* Running a community Hub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.8}}&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;Draft -- for 1.8 functionality&#039;&#039; --[[User:Martin Langhoff|Martin Langhoff]] 22:44, 26 December 2006 (CST) &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
=Security=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Peer to Peer Network=&lt;br /&gt;
&lt;br /&gt;
This is the basic layout of the system. It can be very useful to run one Moodle per faculty or departments, each with its own user management, and yet permit users to roam across the Moodle installs... subject to permissions of course. &lt;br /&gt;
&lt;br /&gt;
==Setup==&lt;br /&gt;
&lt;br /&gt;
The instructions will cover 2 Moodle installations: MoodleA and MoodleB. Both are installed correctly and have never had a Moodle Network configuration.&lt;br /&gt;
&lt;br /&gt;
# Get them to talk to eachother&lt;br /&gt;
## Ensure Admin / Server / Environment indicates you have curl installed&lt;br /&gt;
## If MoodleA and MoodleB are hosted in the same domain, ensure they have a different cookie prefix. Note that changing the cookie prefix will log you out! &lt;br /&gt;
## On both, go to Admin / Network / Settings and turn Networking ON.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers - put the URL of MoodleB under &amp;quot;Add New Host&amp;quot; and click Add.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
# Get user roaming going&lt;br /&gt;
## On both, go to Admin / Users / Authentication and enable Moodle Network authentication plugin. Click on &#039;Settings&#039; and enable auto_add_remote_users.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable SSO-IDP publish and subscribe, and SSO-SP publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## On both, got to Admin / Users / Permissions / Define Roles, only roles that have &amp;quot;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;quot; will be allowed to roam. Grant the privilege as appropriate.&lt;br /&gt;
## On both, go to the homepage, and add the &#039;Network Servers&#039; block.&lt;br /&gt;
## To test, it is recommended to use a different browser (even on a different machine) that is logged in to neither. Login to MoodleA with a non-administrator account that has the permissions to roam. You should see the Network Servers block, and clicking on it you should go to MoodleB with a newly autocreated account. &lt;br /&gt;
# Get remote enrolments going -- this is optional. It allows administrator of MoodleB can enrol users that are &amp;quot;native&amp;quot; to MoodleB in courses in MoodleA, and viceversa.&lt;br /&gt;
## On both, go to Admin / Courses / Enrolment and enable Moodle Network enrolment plugin (click Save). Click on &#039;Edit&#039; and enable &#039;allow_allcourses&#039; or select some courses or categories to be remotely enrolled.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable Enrolment publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## To use, in MoodleA go to Admin / Courses / Enrolment / Moodle Network -&amp;gt; Edit / Manage Network Enrolments and you will see MoodleB listed. Click on MoodleB and you will see a list of your users, and the courses that MoodleB offers for remote enrolment.&lt;br /&gt;
&lt;br /&gt;
==Using it==&lt;br /&gt;
&lt;br /&gt;
=Connecting to a Community Hub=&lt;br /&gt;
A Community Hub is a Moodle server that is configured to accept connections from other Moodle servers, and to provide a set of services to users of these other servers. This guideline will direct you to connect to a Community Hub, assess the services it has to offer, and enable those services for your users.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Get talking to the Hub&lt;br /&gt;
## Ensure that  the Admin / Server / Environment  page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on&lt;br /&gt;
## Go to Admin / Network / Peers and enter the URL of Community Hub under &amp;quot;Add New Host&amp;quot;. Click &amp;lt;em&amp;gt;Add&amp;lt;/em&amp;gt;&lt;br /&gt;
## The host details for the Community Hub should appear with the Site Name field already populated. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## The details will be written to your database and two new tabs will appear in this window: &#039;Services&#039; and &#039;Logs&#039;. Click &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt;&lt;br /&gt;
##A list of services will appear, each with a checkbox for &#039;publish&#039; and &#039;subscribe&#039;. Check the checkboxes for any services you want to publish or subscribe to&lt;br /&gt;
==Using it==&lt;br /&gt;
If the Community Hub has already enabled a service for you, there will be a tick alongside the appropriate checkbox, for example: if the Hub is &amp;lt;em&amp;gt;publishing&amp;lt;/em&amp;gt; Moodle Networked Enrolment, then a tick will appear alongside the &amp;lt;em&amp;gt;subscribe&amp;lt;/em&amp;gt; checkbox for this service. Note that in order to enable some functionality, prominently &amp;lt;em&amp;gt;single-sign-on&amp;lt;/em&amp;gt;, you may have to &amp;lt;em&amp;gt;publish&amp;lt;/em&amp;gt; a service, e.g. the &amp;lt;em&amp;gt;Identity Provider&amp;lt;/em&amp;gt; service. The Community Hub will access this service on your Moodle, asking it to authenticate your users.&lt;br /&gt;
# Enable Roaming&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;SSO (Service Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Publish &amp;lt;em&amp;gt;SSO (Identity Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Users / Permissions / Define Roles, and grant the capability &amp;lt;em&amp;gt;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;lt;/em&amp;gt; to an appropriate role&lt;br /&gt;
## Go to Admin / Users / Authentication and enable the &amp;lt;em&amp;gt;Moodle Network authentication&amp;lt;/em&amp;gt; plugin&lt;br /&gt;
## Go to your homepage, turn on editing, and add the &#039;Network Servers&#039; block&lt;br /&gt;
## Using a different web-browser, log on as a non-admin user who inhabits the role you granted the roaming capability to&lt;br /&gt;
## Note that the Community Hub is listed in the Network Servers block on the homepage. Click on the link to that server&lt;br /&gt;
## Some of your user details will be transferred to the Community Hub server, and a browsing session will be started for you as if you had logged on there directly&lt;br /&gt;
# Enable Networked Enrolment&lt;br /&gt;
## Return to the web browser you&#039;ve been using as the site administrator&lt;br /&gt;
## Go to Admin / Network / Peers and click on the entry for the Community Hub.&lt;br /&gt;
## Click on the Services tab&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;Moodle Networked Enrolment&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Courses / Enrolment and enable the &amp;lt;em&amp;gt;Moodle Network enrolment&amp;lt;/em&amp;gt; plugin. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;edit&amp;lt;/em&amp;gt; to view the details for networked enrolments.&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Manage Moodle Network Enrolments&amp;lt;/em&amp;gt; to see a list of Moodle servers that offer this service to you&lt;br /&gt;
## Click on a server name to view a list of courses that the server offers to your users&lt;br /&gt;
## Click on a course name, to view a list users that you can enrol in this course&lt;br /&gt;
## Enrol users&lt;br /&gt;
## Profit!&lt;br /&gt;
&lt;br /&gt;
=Running a community Hub=&lt;br /&gt;
A Community Hub is a regular Moodle site that runs in a special mode. As a Moodle Administrator, when you add another Moodle site to your list of network peers, your Moodle will contact that site to find out what it is called, and to request its public key for encrypted communication. Normally, the remote server will simply provide this information without making any record of the transaction.&lt;br /&gt;
&lt;br /&gt;
A Community Hub is different. As soon as you add an entry for a Community Hub to your system, the Community Hub will create an entry for your server in its list of hosts, and may immediately begin to offer services to the users of your site.&lt;br /&gt;
This section will guide you to set up a community hub, and select services to offer to all comers.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Enable Networking&lt;br /&gt;
## Ensure that the Admin / Server / Environment page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on &lt;br /&gt;
## Go to Admin / Network / Peers and tick the checkbox for &amp;lt;em&amp;gt;Register all hosts&amp;lt;/em&amp;gt;. Click on &amp;lt;em&amp;gt;Save Changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## On the same page, the first entry in your list of hosts should be &amp;lt;em&amp;gt;All hosts&amp;lt;/em&amp;gt;. Click this link&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt; and enable any services you want to offer to all comers&lt;br /&gt;
&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19240</id>
		<title>MNet</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/4x/sv/index.php?title=MNet&amp;diff=19240"/>
		<updated>2007-01-10T05:44:05Z</updated>

		<summary type="html">&lt;p&gt;Donalm: /* Connecting to a Community Hub */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 1.8}}&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;Draft -- for 1.8 functionality&#039;&#039; --[[User:Martin Langhoff|Martin Langhoff]] 22:44, 26 December 2006 (CST) &amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Overview=&lt;br /&gt;
&lt;br /&gt;
=Security=&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Peer to Peer Network=&lt;br /&gt;
&lt;br /&gt;
This is the basic layout of the system. It can be very useful to run one Moodle per faculty or departments, each with its own user management, and yet permit users to roam across the Moodle installs... subject to permissions of course. &lt;br /&gt;
&lt;br /&gt;
==Setup==&lt;br /&gt;
&lt;br /&gt;
The instructions will cover 2 Moodle installations: MoodleA and MoodleB. Both are installed correctly and have never had a Moodle Network configuration.&lt;br /&gt;
&lt;br /&gt;
# Get them to talk to eachother&lt;br /&gt;
## Ensure Admin / Server / Environment indicates you have curl installed&lt;br /&gt;
## If MoodleA and MoodleB are hosted in the same domain, ensure they have a different cookie prefix. Note that changing the cookie prefix will log you out! &lt;br /&gt;
## On both, go to Admin / Network / Settings and turn Networking ON.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers - put the URL of MoodleB under &amp;quot;Add New Host&amp;quot; and click Add.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
# Get user roaming going&lt;br /&gt;
## On both, go to Admin / Users / Authentication and enable Moodle Network authentication plugin. Click on &#039;Settings&#039; and enable auto_add_remote_users.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable SSO-IDP publish and subscribe, and SSO-SP publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## On both, got to Admin / Users / Permissions / Define Roles, only roles that have &amp;quot;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;quot; will be allowed to roam. Grant the privilege as appropriate.&lt;br /&gt;
## On both, go to the homepage, and add the &#039;Network Servers&#039; block.&lt;br /&gt;
## To test, it is recommended to use a different browser (even on a different machine) that is logged in to neither. Login to MoodleA with a non-administrator account that has the permissions to roam. You should see the Network Servers block, and clicking on it you should go to MoodleB with a newly autocreated account. &lt;br /&gt;
# Get remote enrolments going -- this is optional. It allows administrator of MoodleB can enrol users that are &amp;quot;native&amp;quot; to MoodleB in courses in MoodleA, and viceversa.&lt;br /&gt;
## On both, go to Admin / Courses / Enrolment and enable Moodle Network enrolment plugin (click Save). Click on &#039;Edit&#039; and enable &#039;allow_allcourses&#039; or select some courses or categories to be remotely enrolled.&lt;br /&gt;
## On MoodleA go to Admin / Network / Peers, click on &#039;MoodleB&#039;, and click on &#039;Services&#039;. Enable Enrolment publish and subscribe.&lt;br /&gt;
## Do the equivalent on MoodleB.&lt;br /&gt;
## To use, in MoodleA go to Admin / Courses / Enrolment / Moodle Network -&amp;gt; Edit / Manage Network Enrolments and you will see MoodleB listed. Click on MoodleB and you will see a list of your users, and the courses that MoodleB offers for remote enrolment.&lt;br /&gt;
&lt;br /&gt;
==Using it==&lt;br /&gt;
&lt;br /&gt;
=Connecting to a Community Hub=&lt;br /&gt;
A Community Hub is a Moodle server that is configured to accept connections from other Moodle servers, and to provide a set of services to users of these other servers. This guideline will direct you to connect to a Community Hub, assess the services it has to offer, and enable those services for your users.&lt;br /&gt;
==Setup==&lt;br /&gt;
# Get talking to the Hub&lt;br /&gt;
## Ensure that  the Admin / Server / Environment  page indicates you have curl and openssl installed&lt;br /&gt;
## Go to Admin / Network / Settings and turn Networking on&lt;br /&gt;
## Go to Admin / Network / Peers and enter the URL of Community Hub under &amp;quot;Add New Host&amp;quot;. Click &amp;lt;em&amp;gt;Add&amp;lt;/em&amp;gt;&lt;br /&gt;
## The host details for the Community Hub should appear with the Site Name field already populated. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## The details will be written to your database and two new tabs will appear in this window: &#039;Services&#039; and &#039;Logs&#039;. Click &amp;lt;em&amp;gt;Services&amp;lt;/em&amp;gt;&lt;br /&gt;
##A list of services will appear, each with a checkbox for &#039;publish&#039; and &#039;subscribe&#039;. Check the checkboxes for any services you want to publish or subscribe to&lt;br /&gt;
==Using it==&lt;br /&gt;
If the Community Hub has already enabled a service for you, there will be a tick alongside the appropriate checkbox, for example: if the Hub is &amp;lt;em&amp;gt;publishing&amp;lt;/em&amp;gt; Moodle Networked Enrolment, then a tick will appear alongside the &amp;lt;em&amp;gt;subscribe&amp;lt;/em&amp;gt; checkbox for this service. Note that in order to enable some functionality, prominently &amp;lt;em&amp;gt;single-sign-on&amp;lt;/em&amp;gt;, you may have to &amp;lt;em&amp;gt;publish&amp;lt;/em&amp;gt; a service, e.g. the &amp;lt;em&amp;gt;Identity Provider&amp;lt;/em&amp;gt; service. The Community Hub will access this service on your Moodle, asking it to authenticate your users.&lt;br /&gt;
# Enable Roaming&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;SSO (Service Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Publish &amp;lt;em&amp;gt;SSO (Identity Provider)&amp;lt;/em&amp;gt; by checking the box&lt;br /&gt;
## Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Users / Permissions / Define Roles, and grant the capability &amp;lt;em&amp;gt;Roam to a remote Moodle moodle/site:mnetlogintoremote&amp;lt;/em&amp;gt; to an appropriate role&lt;br /&gt;
## Go to Admin / Users / Authentication and enable the &amp;lt;em&amp;gt;Moodle Network authentication&amp;lt;/em&amp;gt; plugin&lt;br /&gt;
## Go to your homepage, turn on editing, and add the &#039;Network Servers&#039; block&lt;br /&gt;
## Using a different web-browser, log on as a non-admin user who inhabits the role you granted the roaming capability to&lt;br /&gt;
## Note that the Community Hub is listed in the Network Servers block on the homepage. Click on the link to that server&lt;br /&gt;
## Some of your user details will be transferred to the Community Hub server, and a browsing session will be started for you as if you had logged on there directly&lt;br /&gt;
# Enable Networked Enrolment&lt;br /&gt;
## Return to the web browser you&#039;ve been using as the site administrator&lt;br /&gt;
## Go to Admin / Network / Peers and click on the entry for the Community Hub.&lt;br /&gt;
## Click on the Services tab&lt;br /&gt;
## Subscribe to &amp;lt;em&amp;gt;Moodle Networked Enrolment&amp;lt;/em&amp;gt;&lt;br /&gt;
## Go to Admin / Courses / Enrolment and enable the &amp;lt;em&amp;gt;Moodle Network enrolment&amp;lt;/em&amp;gt; plugin. Click &amp;lt;em&amp;gt;Save changes&amp;lt;/em&amp;gt;&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;edit&amp;lt;/em&amp;gt; to view the details for networked enrolments.&lt;br /&gt;
## Click on &amp;lt;em&amp;gt;Manage Moodle Network Enrolments&amp;lt;/em&amp;gt; to see a list of Moodle servers that offer this service to you&lt;br /&gt;
## Click on a server name to view a list of courses that the server offers to your users&lt;br /&gt;
## Click on a course name, to view a list users that you can enrol in this course&lt;br /&gt;
## Enrol users&lt;br /&gt;
## Profit!&lt;br /&gt;
&lt;br /&gt;
=Running a community Hub=&lt;br /&gt;
&lt;br /&gt;
==Setup==&lt;br /&gt;
&lt;br /&gt;
==Helping others use it==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Donalm</name></author>
	</entry>
</feed>