Tips & Tricks

Please do NOT use this section of the forum to request help if Joomdle does not work for you in some particular way. Your post will be deleted.

How to call joomdle web service functions in my own service

More
12 years 3 months ago - 12 years 3 months ago #1 by Alex
Hi, i'm trying to call joomdle_get_moodle_users from my service in this way... but there is something wrong, could anyone help me? :) thanks

function getAllMoodleUser($limitstart) {
$this->error = null;

// Create XML for the request. XML must be set properly for this to work.
$request = xmlrpc_encode_request('joomdle_get_moodle_users', (int)$limitstart);

$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $request
)));

$path = $this->server.$this->dir."/webservice/xmlrpc/server.php?wstoken=".$this->token;


// Send XML to server and get a reply from it.
$file = file_get_contents($path, false, $context); // $file is the reply from server.
// Decode the reply.
$response = xmlrpc_decode($file);
return $response;

}


my goal is get the list of all moodle users
Last edit: 12 years 3 months ago by Alex.

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #2 by Antonio Durán
Are you calling this inside Joomla, or in a external script? If in Joomla, you could just use the Joomdle wrapper functions to make web service calls.

If not, what problem are you having?

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #3 by Alex
hi, i'm trying to call from an external scritp

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #4 by Alex
first of all, is that the right way to call this function?

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago - 12 years 3 months ago #5 by Alex
I've also tryied with
$request = xmlrpc_encode_request('joomdle_get_moodle_users', array('limitstart' =>0, 'limit' => 5, 'order' => 'desc', 'order_dir' => '', 'search' => ''),array('encoding'=>'UTF-8'));


but this doesn't work.... moreover i don't know the correct values for 'order', 'order_dir' and 'search' text fields

The problem is that the response is
array (size=2)
'faultCode' => int 404
'faultString' => string 'Unknown error' (length=13)
null
Last edit: 12 years 3 months ago by Alex.

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #6 by Antonio Durán
Your values seem correct,

Enabled debugging in Moodle to get more info about the 404.

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #7 by Alex
i took a look to the implementation of get_moodle_users() in auth.php script.
it take these parameters and build an sql query... my request is

$request = xmlrpc_encode_request('joomdle_get_moodle_users',array('limitstart' =>0, 'limit' => 5, 'order' => 'name', 'order_dir' => 'desc', 'search' => ''),array('encoding'=>'utf8'));

and the error is: "parameters do not match signature | ERRORCODE: 1"

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #8 by Antonio Durán
You may need to force types, with something like: (int) 0

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #9 by Alex
thanks but it still doesn't work

$request = xmlrpc_encode_request('joomdle_get_moodle_users',array('limitstart' => (int)0, 'limit' => (int)5, 'order' => (string)'name', 'order_dir' => (string)'', 'search' => (string)''),array('encoding'=>'utf8'));

Please Log in or Create an account to join the conversation.

More
12 years 3 months ago #10 by Antonio Durán
There is no "name" field in moodle user table. Try "lastname".

Please Log in or Create an account to join the conversation.