6

Following various guides, I have managed to accomplish the following:

  • Set up an external service using the REST API which includes the "core_user_create_users" function,
  • Set up a user account and assigned it to be allowed to use the REST API service I set up,
  • Defined a role for web service users, archetype 'authenticated user', context of 'system',
  • Set role to allow "moodle/user:create", and
  • Manually generated a token for the web service user with no expiration.

Now, when I go to the built-in web service test client, select to use token-based authentication on the REST API, select the "moodle_user_create_users" function and put in the token and details, I get this:

REST protocol: moodle_user_create_users
URL: [...]
'<?xml version="1.0" encoding="UTF-8" ?>
<EXCEPTION class="webservice_access_exception">
<ERRORCODE>accessexception</ERRORCODE>
<MESSAGE>Access control exception</MESSAGE>
<DEBUGINFO>Access to the function moodle_user_create_users() is not allowed.
There could be multiple reasons for this:
1. The service linked to the user token does not contain the function.
2. The service is user-restricted and the user is not listed.
3. The service is IP-restricted and the user IP is not listed.
4. The service is time-restricted and the time has expired.
5. The token is time-restricted and the time has expired.
6. The service requires a specific capability which the user does not have.
7. The function is called with username/password (no user token is sent)
and none of the services has the function to allow the user.
These settings can be found in Administration &gt; Site administration
&gt; Plugins &gt; Web services &gt; External services and Manage tokens.</DEBUGINFO>
</EXCEPTION>

What am I missing?

Luke G.
  • 587
  • 1
  • 4
  • 13
  • I've got plenty more defined roles and permissions, but this one is critical to what I need to accomplish, so I figured if I can get it working the rest is likely to follow suit. None of the functions work--they all respond with the same error message listed above. – Luke G. Jul 17 '15 at 18:21
  • 2
    UPDATE: This may be related to a number of depreciated functions being listed in the built-in Web Service Test Client. I found [this](https://tracker.moodle.org/browse/MDL-31609?jql=text%20~%20%22web%20service%22) article in their bug tracker, but if so that's been a bug for quite some time. – Luke G. Jul 21 '15 at 02:23
  • 2
    You're absolutely right Luke, the test client's methods are not the same methods we execute via the real service. What an absolute circus, they should just pull the test client, it's certainly wasted hours of my time. You should create an answer and mark yourself as accepted. This is one of the first hits for "Access to the function xxxxxx is not allowed". – Moby's Stunt Double Jan 21 '17 at 18:56
  • I'm still getting the error, and I guess this is still not resolved, please update the answer if it is fixed by now please. Cheers! – Pasan Eeriyagama Dec 06 '18 at 01:33

5 Answers5

3

I had the same exception. then I have made this change in the admin dashboard.

Site administration -> Mobile app -> Mobile settings -> Enable web services for mobile devices.

turn this on.

that's who I solved my issue.

MH Fuad
  • 746
  • 6
  • 16
2

My answer seems to be the same as others have experienced: the Web Service Test Client is hopelessly broken.

This was a known issue at the time I was working on this project, and unfortunately Moodle decided to continue to ship this feature anyway.

For the foreseeable future I'd suggest not wasting your time even trying to use this 'tool'.

Luke G.
  • 587
  • 1
  • 4
  • 13
0

With all elements configured in Moodle administration dashboard (funcions, user, role, action-role, token)...

When I used the web service test client selecting the "core_user_create_users" function, instead of "moodle_user_create_users" (I ignore why the latter was used), the exception didn't appear to me and the response was OK.

-1

Try enabling web service authentication from: Site Administration > Plugin > Manage authentication

Md.
  • 496
  • 4
  • 11
  • I tried that, but with no effect. Do I need to do anything else after doing that? – Yvonne Aburrow Sep 05 '16 at 09:27
  • It's not a permissions issue. I've enabled everything needed and have the same issues. It appears to be that the functions exposed in the test client don't match the actual functions in the back-end and so they just don't work. I do know for sure that permissions are not *the* issue. – Luke G. Feb 20 '17 at 18:08
-2

Try to get token throw https://yourmoodle/login/token.php?username=username&password=pass&service=webserviceshortname. My token from /admin/settings.php?section=webservicetokens dosnt work also and enable functions for service in /admin/settings.php?section=externalservices

yurij
  • 1
  • Welcome to Stack Overflow, yurij! I don't understand what you mean to say with this answer. Could you try and explain it more clearly and extensively? – anothernode Aug 08 '18 at 09:25
  • Delete my comment please. Token from script token.php and in '/admin/settings.php?section=webservicetokens' are same. Check if your service have enabled functions in '/admin/settings.php?section=externalservices' – yurij Aug 08 '18 at 11:40
  • @yurij, the webservice test client was acknowledged as broken by others involved in the Moodle community (over on their message board). You'll likely have to write your own test cases, unless they've fixed it since then. – Luke G. Aug 08 '18 at 12:33
  • @yurij Which comment do you mean should be deleted? You can also delete your own posts and comments if you think they are not relevant anymore. – anothernode Aug 08 '18 at 14:05