Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-70588

WS core_course_update_courses returning "requireloginerror"



    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.9.3, 3.10
    • Fix Version/s: None
    • Component/s: Course, Web Services
    • Labels:
    • Affected Branches:


      Hi! I'm trying to use Moodle (3.10+ build  2020110900.02) webservices from another program, but when I tried to make the ws function "core_course_update_courses" works, it fails with this error:
      "warnings": [
      "item": "course",
      "itemid": 2,
      "warningcode": "requireloginerror",
      "message": "Course or activity not accessible. (Not enrolled)"

      Debugging the Moodle code, this error raises on line 3011 from the file "moodlelib.php", and it's conditions to arrive there is "the user cannot access the course, because it not enrolled".

      The question is: to run this function properly, the webservice user must enrolled on the course(s) who want to update?

      In my humble opinion, I believe it's a problem that the algorithm is not prepared to allow a webservice user for making course updates.


      Steps to reproduce:

      1) Enable webservices

      2) Enable REST protocol

      3) Create a user who will work on webservices

      4) Create a role specific for work on webservices  with this permissions:

      • Context types where this role may be assigned: System
      • moodle/course:update
      • moodle/course:changecategory
      • moodle/course:changefullname
      • moodle/course:changeshortname
      • moodle/course:changeidnumber
      • moodle/course:changesummary
      • moodle/course:visibility
      • webservice/rest:use

      5) On the system roles assignment, put the webservice user on the webservice role

      7) Create a custom service, check "authorized users only" to allow the webservice user only and add the function "core_course_update_courses"

      8) Add the webservice user to this custom service

      9) Create a token for the webservice user

      10) Run on curl or on your preferred client the call to make a update on a course, like this example on curl format:
      curl --location --request POST 'http://localhost/moodle310/webservice/rest/server.php?wsfunction=core_course_update_courses&moodlewsrestformat=json&wstoken=<webservice user token>'
      'courses[0][fullname]="new course fullname"'
      (If I've not forget any step, this is sufficient to reproduce)
      You will get the error.
      Thanks for the help!






            Unassigned Unassigned
            jeferod83 Jeferson Rodrigues
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona), Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            0 Vote for this issue
            3 Start watching this issue