Web service Access control exception

If you are creating or using a web service in Moodle and see the following message:

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

It can be a bit hard to troubleshoot. Generally there is a 4th item with debugging info, but this will only appear if you have the correct Moodle debugging level set in Site administration > Development > Debugging.

At minimum you’ll need to set Debug messages to NORMAL: Show errors, warnings and notices. That is, it won’t apear if you have it set to NONE or MINIMAL.

Once you do that you should get that 4th parameter:

{
    "exception": "webservice_access_exception",
    "errorcode": "accessexception",
    "message": "Access control exception",
    "debuginfo": "You are not allowed to use the {$a} protocol (missing capability: webservice/rest:use)"
}

In this instance, user that is associated with the web service token didn’t have the capability webservice/rest:use in their system role. Adding the capability to the role fixed the issue.

 

Access the WSDL for a Moodle SOAP service

When you enable SOAP based web services through Moodle:

Site administration > Plugins > Web Services > Overview (follow the steps)

You can access the WSDL for the SOAP based service by passing the flag &wsdl=1 in your URL e.g.

http://yourmoodle.com/webservice/soap/server.php?wsdl=1&wstoken=tokenifrequired

 

Undefined Property $webserviceprotocols

When this occurs, there is no result from a web service call and undefined property $webserviceprotocols.

In the PHP error log the following appears:

Undefined property: stdClass::$webserviceprotocols

Check your web service protocols and ensure that the appropriate protocol is enabled.

Site administration > Plugins > Web services > Manage protocols.