Create new User via Webservice

Create new User via Webservice

by Zadok Lindt -
Number of replies: 6

We have installed the latest Moodle. I am able to search moodle course information using the API, but I am having trouble testing out user account creation.

It seems like "core_user_create_users" is the appropriate command. However, when using a valid token, fetching the following URL

https://moodle.example.com/moodle/webservice/rest/server.php?wstoken=mytoken&wsfunction=core_user_create_users&moodlewsrestformat=json&firstname=a&lastname=b&email=c@example.com&username=d

The following is returned:

{"exception":"webservice_access_exception","errorcode":"accessexception","message":"Access control exception"}

Am I doing it correctly, or am I missing something?

Thanks!

Average of ratings: -
In reply to Zadok Lindt

Re: Create new User via Webservice

by Zadok Lindt -

My research suggests I am not the only person with this problem:

https://stackoverflow.com/questions/31482243/moodle-2-9-1-any-web-service-function-gives-access-control-exception

However it seems others may have success with this, i.e.:

https://moodle.org/mod/forum/discuss.php?d=323422

Thanks!

In reply to Zadok Lindt

Re: Create new User via Webservice

by Zadok Lindt -

Enabling debug mode on the server displays a more detailed error:

{"exception":"webservice_access_exception","errorcode":"accessexception","message":"Access control exception","debuginfo":"Access to the function core_user_create_users() is not allowed.\n                     There could be multiple reasons for this:\n                     1. The service linked to the user token does not contain the function.\n                     2. The service is user-restricted and the user is not listed.\n                     3. The service is IP-restricted and the user IP is not listed.\n                     4. The service is time-restricted and the time has expired.\n                     5. The token is time-restricted and the time has expired.\n                     6. The service requires a specific capability which the user does not have.\n                     7. The function is called with username\/password (no user token is sent)\n                     and none of the services has the function to allow the user.\n                     These settings can be found in Administration > Site administration\n                     > Plugins > Web services > External services and Manage tokens."}

In reply to Zadok Lindt

Re: Create new User via Webservice

by Zadok Lindt -

Never mind, after a few hours of digging around the website, I eventually worked it out.