core_users_get_user_by_field parameter issue

core_users_get_user_by_field parameter issue

by Rezka Aufar Leonandya -
Number of replies: 2

Hello everyone, im having these parameter issue with moodle API that i implemented and used for mobile apps that i'm currently working on. here's my code :

code

and this is what i got from google chrome's network developer tools :

error

error

can anyone please help me? fast response are really appreciated. may god bless you!

Average of ratings: -
In reply to Rezka Aufar Leonandya

Re: core_users_get_user_by_field parameter issue

by Mike Eaton -

Hi Rezka,

I've started working with these API calls myself and came across the same issue as you.  in your userToGet variable, the 'values' value needs to be an array.  So for your example, the line 

var userToGet = { field: 'username', values: 'mobile' };

should be

var userToGet = { field: 'username', values: ['mobile'] };

With the idea being that if you wanted to look up more than one username, you'd have them as elements of the values array. 

Hope that helps!

Mike