0

I configured REST webservice on Moodle 3.0.5 to use function core_course_get_courses which is supposed to return a response containing basic info about all available courses.

This is the URL I've been using:

https://example.com/webservice/rest/server.php?wstoken=713898e3fcaf9ead2218eb7565993230&wsfunction=core_course_get_courses&moodlewsrestformat=json

And, this is what I get:

{
  "exception": "required_capability_exception",
  "errorcode": "nopermissions",
  "message": "Sorry, but you do not currently have permissions to do that (View courses without participation)"
}

The permission in question has been set from the start, that is:

moodle/course:view

Role permissions setting page

It does not have any effect. I even allowed everything, some few hundred permissions just to see if it would work, but still no effect.

I used another function with the same service, it does work!:

core_enrol_get_enrolled_users

Another important fact is that the core_course_get_courses function works on a local, development machine with fresh installation of Moodle. The production environment has 50 additional plugins installed. The debugging, "extra Moodle debug messages for developers" has been enabled but there are no errors shown.

What could be the cause for this?

P.S. Dev. machine is Ubuntu 14.04

Đuro Mandinić
  • 693
  • 1
  • 8
  • 26

3 Answers3

0

Does the user with the token have access to the capability?

Find the user with the token via site admin -> plugins -> web services -> manage tokens

or direct to /admin/settings.php?section=webservicetokens

Then check the users capability via site admin -> users -> permissions -> check system permissions

or direct to /admin/roles/check.php?contextid=1

If that looks okay, then check if the user is in the list of other users for the course - https://docs.moodle.org/31/en/Other_users

Go to a course, then course admin -> users -> other users

or direct to /enrol/otherusers.php?id=# (#=courseid)

Is the user in that list?

Russell England
  • 9,436
  • 1
  • 27
  • 41
  • The user has all possible permissions currently set according to "check system permissions" .. There is several hundred of courses. Setting properties for the user per each course is not an option. What when someone tomorrow adds a number of new courses. – Đuro Mandinić Aug 30 '16 at 12:57
  • I got a tip to use Admin user for the rest webservice. I created a token for him and added the user to the particular role. It did not return "nopermissions" error but "500 internal server error" :-D – Đuro Mandinić Aug 30 '16 at 13:01
  • Is there a way to paginate REST response result? There is not, according to docs. – Đuro Mandinić Aug 30 '16 at 13:03
0

I recently had this issue and found that even though the user had system level access that was needed the user was also enrolled in a course as a student who did not have the needed access for that specific course. As a result the error was thrown when the process got to that course while building the full course list.

We removed the student enrollment and were then able to pull the full course list without error.

I hope this helps for anyone else having this issue!

-1

Please check the required capabilities for this function and then go to site Adminitration->users->permission->define

moodle/admin/roles/manage.php a role then show the listing of roles

moodle/admin/roles/define.php?action=edit&roleid=9

enter image description here

allow the capabilities

Divya Rai
  • 1
  • 1