core_user_get_users not returning users created with core_user_create_users

Re: core_user_get_users not returning users created with core_user_create_users

by alejandro alves -
Number of replies: 0

sorry just noticed the format problem


If I try to search for a user I just created with a WS it does not return it. Also I noticed that if I search by unexisting fields, for example, asdasdad, it returns the user associated with the token. Why? shouldn't it return an error?

$token = 'XXXXX'; $domainname = 'XXXX';

$functionname = 'core_user_create_users'; // REST RETURNED VALUES FORMAT

$restformat = 'json'; //Also possible in Moodle 2.2 and later: 'json'

//Setting it to 'json' will fail all calls on earlier Moodle version

//////// moodle_user_create_users ////////

/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION

$user1 = new stdClass();

$user1->username = 'testusername4';

$user1->password = 'testpassworD*1';

$user1->firstname = 'testfirstname1';

$user1->lastname = 'testlastname1';

$user1->email = 'testemail1@moodlsde.com';

$user2 = new stdClass();

$user2->username = 'testusername5';

$user2->password = 'testpassworD*2';

$user2->firstname = 'testfirstname2';

$user2->lastname = 'testlastname2';

$user2->email = 'testemail2@moodleas.com';

$user2->timezone = 'Pacific/Port_Moresby';

$users = array($user1, $user2);

$params = array('users' => $users);

/// REST CALL

header('Content-Type: text/plain');

$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname; require_once('./curl.php'); $curl = new curl;

//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2

$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';

$resp = $curl->post($serverurl . $restformat, $params);

$criteria = array( 'key' => 'username','value' => 'testusername4' );

$params = array( 'criteria' => array($criteria));

$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction=core_user_get_users';

$ret = $resp = $curl->post($serverurl . $restformat, $params);

print_r($ret);