How can I enrol cohort to course using webservice API.
I have downloaded this plugin from git https://github.com/learningworks/moodle-local_ws_enrolcohort but not working for me. It throws HTTP500 error. My moodle version is 3.9
Anybody please help
Enrol cohort to course using webservice API
Number of replies: 4Re: Enrol cohort to course using webservice API
What's in the server error logs for that 500 error (500 error tells you nothing useful).
Re: Enrol cohort to course using webservice API
Thank you Howard. I have managed the HTTP error issue. but it shows another error
<?xml version="1.0" encoding="UTF-8" ?> <EXCEPTION class="invalid_parameter_exception"> <ERRORCODE>invalidparameter</ERRORCODE> <MESSAGE>Invalid parameter value detected</MESSAGE> <DEBUGINFO>Missing function name</DEBUGINFO> </EXCEPTION>Here is my code
$token = '0a090e0ef5f5d883a532171525606b94';
$domainname = 'http://localhost';
/// FUNCTION NAME
$functionname = 'local_ws_enrolcohort_add_instance';
/// PARAMETERS
$instance = array("courseid"=>11,"cohortid"=>1,"roleid"=>5,"name"=>"Test 3 to cohort");
$params = array("instance"=>$instance);
/// REST CALL
header('Content-Type: text/plain');
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&ws_function='.$functionname;
require_once('./curl.php');
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);
print_r($resp);
Re: Enrol cohort to course using webservice API
The error states 'missing function name', so the problem is clearly with the '&ws_function='.$functionname part of the code.
A quick look at the documentation ( https://docs.moodle.org/dev/Creating_a_web_service_client ) will show that the param should be "wsfunction", not "ws_function".
So, a quick change of the code to: '&wsfunction='.$functionname should be all you need to fix this error.
A quick look at the documentation ( https://docs.moodle.org/dev/Creating_a_web_service_client ) will show that the param should be "wsfunction", not "ws_function".
So, a quick change of the code to: '&wsfunction='.$functionname should be all you need to fix this error.
Re: Enrol cohort to course using webservice API
Thank you Davo!! It's working