core_enrol_get_enrolled_users options and json

core_enrol_get_enrolled_users options and json

by Tim Titley -
Number of replies: 3

Hi All,

I'm trying to retrieve a list of enrolled users for a particular course using python, but am having problems defining the options.

I can post the following:

{'courseid': 96, 'options': [{'name': 'userfields', 'value': 'role'}, {'name': 'userfields', 'value': 'username'}], 'wstoken': 'MY_TOKEN', 'wsfunction': 'core_enrol_get_enrolled_users', 'moodlewsrestformat': 'json'}

but get the response:

{'exception': 'invalid_parameter_exception', 'errorcode': 'invalidparameter', 'message': 'Invalid parameter value detected', 'debuginfo': "options => Invalid parameter value detected: Only arrays accepted. The bad value is: 'value'"}

I've tried a number of different ways of presenting the options, but from my understanding, the above *should* work.

On the other hand, this works as expected:

curl -X POST 'https://mymoodlesite/webservice/rest/server.php' -d 'courseid=207&options[0][name]=userfields&options[0][value]=username&options[1][name]=userfields&options[1][value]=roles&wstoken=MY_TOKEN&wsfunction=core_enrol_get_enrolled_users&moodlewsrestformat=json'

Am I missing something obvious?

Average of ratings: -
In reply to Tim Titley

Re: core_enrol_get_enrolled_users options and json

by Young Bo KIM -
please don't use -X POST

try as shown below command.

curl -v -H "Content-Type: application/x-www-form-urlencoded Accept: application/json" -d "moodlewsrestformat=json&wstoken=xxxxxxxxxxxxxxxxxxxxx&wsfunction=xxxxxxxxxxxxxxx&'put options with &'" "https://mymoodlesite/webservice/rest/server.php"
In reply to Young Bo KIM

Re: core_enrol_get_enrolled_users options and json

by Tim Titley -
Thanks for your reply.

I don't have a problem with urlencoded query. I can get this working. The problem is with posting json to the service endpoint.

JSON seems to work fine if I use simple key/value pairs, but when I use nested lists/collections (or in this case, a collection within a list within a collection), it throws the error.

Do you think my understanding is correct, and is the the json is valid or do you think this might be a bug in the parameter checking code?

I'm happy to submit a bug report, but I just wanted a second opinion..
In reply to Tim Titley

Re: core_enrol_get_enrolled_users options and json

by Young Bo KIM -
in API Docs, it should be "option[0][optionname]: option", then "option[0][name]=name&optioin[0][groupid]=xxxx&so on.
so option[0] is fixed.