"get_users_by_id" web service

"get_users_by_id" web service

by Brian Ruedi -
Number of replies: 7

I have just recently installed version 2.1 and I have been working with the get_users_by_id web service.  Since I have installed version 2.1 I have issues with the web service now, for some reason I am unable to get usernames, and emails in the web service response.  I was able to get them fine in the previous version but now they aren't there.  If anyone has any suggestions I would really appreciate them.

Average of ratings: -
In reply to Brian Ruedi

Re: "get_users_by_id" web service

by RICHARD gillette -

Tell us more about the errors and your setup. Things like are you using REST or SOAP as your client, what do the parameters that you are sending look like ie arrays, XML, what is the error message you are getting back from moodle, and what is your method of sending the parameters, like LWP or CURL?

In reply to RICHARD gillette

Re: "get_users_by_id" web service

by Brian Ruedi -

I am using the test client to test the web service using token authentication, REST protocol and I am simply using the id number as my parameters.  I am not sure what format the test client sends the information as but in my thrid party application the parameters are sent in XML format.  When I run the test client I am able to get the username if I give the web service user administrative permissions, but I don't think tht should be necessary as it wasn't in version 2.0.3 which I upgraded from.  I have also been able to get the email to show up only on users that have their email set to display email address to everyone, but I am working with student emails and do not want everyone to be able to view email addresses.

There is no error message with this issue, I am actually getting all of the information that is expected in the response except for the username and email value so there is no actual error message associated.

I am running Moodle version 2.1 on Windows Server 2008 R2 with a mySql database

In reply to Brian Ruedi

Re: "get_users_by_id" web service

by RICHARD gillette -

Try going into the moodle directory to moodle/users/externallib.php and look at their get_users_by_id function. There should be three parts - a get_users_by_id_parameters - a get_users_by_id (the function def) - and a get_users_by_id_returns.   Look at the returns and see if the email and the username are returned in that block of code. If they are, then I will try and think of something else. If they are not, the the bottom of the get_by_id function needs to be modified to return those values.

Here is what my code looks like for the get users by ID returns and I am running moodle 2.0.3
public static function get_users_by_id_returns() {
        return new external_multiple_structure(
                new external_single_structure(
                        array(
                    'id'    => new external_value(PARAM_NUMBER, 'ID of the user'),
                    'username'    => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config'),
                    'firstname'   => new external_value(PARAM_NOTAGS, 'The first name(s) of the user'),
                    'lastname'    => new external_value(PARAM_NOTAGS, 'The family name of the user'),
                    'email'       => new external_value(PARAM_TEXT, 'An email address - allow email as root@localhost'),
                    'auth'        => new external_value(PARAM_SAFEDIR, 'Auth plugins include manual, ldap, imap, etc'),
                    'confirmed'   => new external_value(PARAM_NUMBER, 'Active user: 1 if confirmed, 0 otherwise'),
                    'idnumber'    => new external_value(PARAM_RAW, 'An arbitrary ID code number perhaps from the institution'),
                    'lang'        => new external_value(PARAM_SAFEDIR, 'Language code such as "en", must exist on server'),
                    'theme'       => new external_value(PARAM_SAFEDIR, 'Theme name such as "standard", must exist on server'),
                    'timezone'    => new external_value(PARAM_ALPHANUMEXT, 'Timezone code such as Australia/Perth, or 99 for default'),
                    'mailformat'  => new external_value(PARAM_INTEGER, 'Mail format code is 0 for plain text, 1 for HTML etc'),
                    'description' => new external_value(PARAM_RAW, 'User profile description'),
                    'descriptionformat' => new external_value(PARAM_INT, 'User profile description format'),
                    'city'        => new external_value(PARAM_NOTAGS, 'Home city of the user'),
                    'country'     => new external_value(PARAM_ALPHA, 'Home country code of the user, such as AU or CZ'),
                    'customfields' => new external_multiple_structure(
                                    new external_single_structure(
                                            array(
                                                'type'  => new external_value(PARAM_ALPHANUMEXT, 'The name of the custom field'),
                                                'value' => new external_value(PARAM_RAW, 'The value of the custom field')
                                            )
                                    ), 'User custom fields (also known as user profil fields)', VALUE_OPTIONAL)
                        )
                )
        );
    }

See if yours looks similar or not and let me know, Right above that function should be the get_user_id definition that has a giant user array at the bottom that should be returning all of the values you need.

In reply to RICHARD gillette

Re: "get_users_by_id" web service

by Matt R -

I have the same problem. I cannot see email address and username in web service API responses. I have checked this file and username and email parameters are there.

 

any help appreciated.

 

regards,

matt.

In reply to Matt R

Re: "get_users_by_id" web service

by Malte K -

It seems to be an rights-issue. I have also been wondering why username and email won't be returned by the webservice, but by taking a look at the code i discovered that the webservice user needs to be a site admin (using version 2.2.1).

Go to Site administration/ Users/ Permissions/ Site administrators

and add your webservice user to the list of site administrators. I hope that helps ;)

But i have further been wondering if there could come up any security issues if my webservice user becomes a site administrator?

regards,

Malte

In reply to Malte K

Re: "get_users_by_id" web service

by Jérôme Mouneyrac -

Hi,

to explain a bit more. In the web interface a user can see another user information when he goes on the:

- user profile page (http://mymoodle/user/profile.php?id=USERID) => core_user_get_users_by_id().

- course user profile page (http://mymoodle/user/view.php?id=USERID&course=COURSEID) => core_user_get_course_user_profiles().

These two pages do not display the same information in Moodle, so it does not with the web service functions. If ever the web service function does not display the same things as the web version it's an issue. Otherwise it works like excepted. I hope it clarify.

Note that except if you are admin, you are most likely never going to see someone else username in both pages.

In reply to Brian Ruedi

Re: "get_users_by_id" web service

by oneil clacken -

Hi! I am trying to get my test client to work using xmlrpc and token authentication, but I keep getting a faultcode630 error. I am running 2.03 on Windows Server 2008 R2 with a mySql database. any help would be GREATLY appreciated!