Problem with core_user_get_users_by_field

Problem with core_user_get_users_by_field

by Владимир Филиппов -
Number of replies: 1

Good afternoon! I really need help. I just can’t figure out why, when calling the core_user_get_users_by_field function, it gives an error:

array

(

     [exception] => invalid_parameter_exception

     [errorcode] => invalidparameter

     [message] => Invalid parameter value detected.

     [debuginfo] => Missing required key in single structure: values

)

MoodleRest.php returns this url:

https://mysite.com/webservice/rest/server.php?wstoken=xxx1&moodlewsrestformat=json&wsfunction=core_user_get_users_by_field&field=email&values[0]=email@email.com

This error also occurs when searching by id or username.

If you insert this link into the address bar of the browser, then the data is normally issued, without errors. But here one point, if I insert the email (id, username) of the user who has the right to manage the web service, then the data is normally displayed, if another user, then an empty array is returned.

Average of ratings: -
In reply to Владимир Филиппов

Re: Problem with core_user_get_users_by_field

by Владимир Филиппов -
Understood with the help of examples in the file /user/tests/externallib_test.php

User data is obtained through:
$searchparams = array(
array('key' => 'email', 'value' => 'myemail@mypochta.ru')
);
$result = core_user_external::get_users($searchparams);

Create:
$user = array(
'username' => loginmy,
'password' => 'pswd123',
'firstname' => 'Vvladimir',
'lastname' => 'Filippovv',
'middlename' => 'Vladimirovich',
'email' => 'loginmy@email.fake'
);
$result_insert = core_user_external::create_users(array($user));
Average of ratings: Useful (1)