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

Re: Wasted over a day and still can't get enrol_manual_enrol_users to work!!!!

$
0
0

by A W.  

Still not working sad does anyone have anymore suggestions?

I even tried it with REST as well, initially did test of create user which worked, then tried enrol using:

<?php
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);
$token = '9f85338ddaa47ad3151dd444983e15df';
$domainname = 'http://localhost/moodle';
$functionname = 'enrol_manual_enrol_users';
$restformat = 'xml'; 
$enrolobj = new stdClass();           
                $enrolobj->userid = 101;                
                $enrolobj->courseid = 3;                
                $enrolobj->roleid = 5; 
print_r ($enrolobj);
$params[] = $enrolobj;
echo "Now making enrol REST call\n";
header('Content-Type: text/plain');
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$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);
?>

which gave me:

stdClass Object
(
    [userid] => 101
    [courseid] => 3
    [roleid] => 5
)
Now making enrol REST call<?xml version="1.0" encoding="UTF-8" ?><EXCEPTION class="invalid_parameter_exception"><ERRORCODE>invalidparameter</ERRORCODE><MESSAGE>Invalid parameter value detected</MESSAGE><DEBUGINFO>Missing required key in single structure: enrolments</DEBUGINFO></EXCEPTION>
verified the parameters in API documentation for this call:

General structure
list of (
object {
roleid int //Role to assign to the user
userid int //The user that is going to be enrolled
courseid int //The course to enrol the user role in
timestart int Optional//Timestamp when the enrolment start
timeend int Optional//Timestamp when the enrolment end
suspend int Optional//set to 1 to suspend the enrolment
}
)
And as before changing line it to 'cat' to see if its even parsing it for a valid roleID made no difference i.e. gives the same error if I use:

 

 [roleid] => cat


Any help much appreciated,

Thanks,

Alex


Viewing all articles
Browse latest Browse all 2361

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>