Quantcast
Channel: Web services
Viewing all articles
Browse latest Browse all 2364

Call webservices without wstoken parameter

$
0
0
by Kia Kaviani.  

Hello Moodle team,

I am programming for many years but I started to work on Moodle recently.

I have created a web service for Moodle and everything works great while I am sending wstoken parameter in Postman, but when I set the 'loginrequired' => false in db/server.php file of my web service, I expect that there is NO NEED to send wstoken parameter when calling the service. Is it right? If not, how can I write a service that everyone can call it before login or getting wstoken?

I am using this URL to call services:

http://localhost:8083/webservice/rest/server.php?wsfunction=local_my_services_get_courses&moodlewsrestformat=json

I am getting the following error when I remove wstoken parameter:

{
    "exception": "moodle_exception",
    "errorcode": "invalidtoken",
    "message": "Invalid token - token not found"
}
 
 

My 'server.php' file is like this :

$functions = array(
    'local_my_services_get_courses' => array(
        'classname'   => 'local_my_services_external',
        'classpath'   => 'local/my_services/externallib.php',
        'methodname'  => 'get_courses',
        'description' => 'Get courses list.',
        'type'        => 'read',
        'ajax'          => true,
        'loginrequired' => false,
    ),

$services = array(
    'My web service'  => array(
         'functions' => array(
            'local_my_services_get_courses',
         ),
         'enabled' => 1,
         'restrictedusers' => 0,
         'shortname' => 'my_web_services',
         'downloadfiles' => 1,
         'uploadfiles' => 1
     ),
 );
 
Thank you

Viewing all articles
Browse latest Browse all 2364

Trending Articles