ArgumentCountError when testing webservice API

ArgumentCountError when testing webservice API

by Marco Cigna -
Number of replies: 0

{

  "exception": "ArgumentCountError",

  "message": "Too few arguments to function, 1 passed in /public_html/webservice/lib.php on line 1516 and exactly 2 expected"

}

Line 1516 of the webservice/lib.php looks as below:

        $this->returns = call_user_func_array(array($this->function->classname, $this->function->methodname), $params);
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
externallib.php
class local_web_service_external extends external_api {

    public static function expiration_date_parameters() {
        return new external_function_parameters(
            array(
                'enrol'    => new external_single_structure(
                    array(
                        'courseid' => new external_value(PARAM_INT, 'Course Ids'),
                        'userid'   => new external_value(PARAM_INT, 'Users Ids')      
                    )
               )
           )
        );
    }
    public static function expiration_date($courseid, $userid) {
        global $DB, $CFG;
        $requestinfo =[];

        $params = self::validate_parameters(self::expiration_date_parameters(), array('courseid' => $courseid, "userid" => $userid));

        if ($DB->record_exists('enrol', ['courseid' => $courseid, 'enrol' => 'manual'])){
           
            $instance = $DB->get_record('enrol', ['courseid' => $courseid, 'enrol' => 'manual']);
            $enrolid = $instance->id;

            if ($DB->record_exists('user_enrolments', ['enrolid' => $enrolid, 'userid' => $userid])){
                //------------Finding course expiration--------------------------------------------------------------
                $search = $DB->get_record('user_enrolments', ['enrolid' => $enrolid, 'userid' => $userid]);
                $expiration = $search->timeend;

                $reason = 'NULL';
                $feedback = 'Success!';

            }
            else{
                $expiration = 0;
                $reason = 'record in user_enrolments does not exist, check userid';
                $feedback = 'Failed';
            }
        }
        else{
            $expiration = 0;
            $reason = 'record in enrol does not exist, check courseid';
            $feedback = 'Failed';
        }


        $requestinfo = [
            'courseid'=>$courseid,
            'userid'=>$userid,
            'expiration'=>$expiration,
            'reason'=>$reason,
            'message'=>$feedback
            ];
        return $requestinfo;

    }
    public static function expiration_date_returns() {
        return new external_multiple_structure(
            new external_single_structure(
                array(
                    'courseid' => new external_value(PARAM_INT, 'course ids'),
                    'userid'=> new external_value(PARAM_INT, 'user ids'),
                    'expiration'=>new external_value(PARAM_INT,'expiration date'),
                    'reason'=>new external_value(PARAM_TEXT,'reason for failure'),
                    'message'=>new external_value(PARAM_TEXT,'Success or Failure')

                )
            )
        );
    }
}




Not too sure how to resolve this error, since I have two parameters already defined in my function. Any help is appreciated!

Average of ratings: -