REST Service core_course_create_courses

Re: REST Service core_course_create_courses

by Gilberto Mangones -
Number of replies: 1

Hello every posters,

This worked:


$token = 'You token'

$domainname = 'http://localhost/moodle';

$functionname = 'core_course_create_courses';

$restformat = 'json';

//crear objeto de acuerdo a la estructura para crear Categoría en Moodle

$curso = new stdClass();        

$curso->fullname = 'Gilberto Mangones'; 

$curso->shortname ='Gm'; // This data no repeat in other side is inique

$curso->idnumber = 27; // Remember is a consecutive, you problem was for that, you sould write a number

$curso->visible = 1; 

$curso->categoryid = 6; // write number of category (1: Misellaneus)

$modulos = array($curso);

$params = array('courses' => $modulos);

header('Content-Type: text/plain');

$serverurl = $domainname . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $functionname;

require_once(APPPATH . 'libraries/curl.php');

$curl = new curl;

$restformat = ($restformat == 'json') ? '&moodlewsrestformat=' . $restformat : '';

$resp = $curl->post($serverurl . $restformat, $params);

return $resp;

In reply to Gilberto Mangones

Re: REST Service core_course_create_courses

by Raúl Chamorro -

Hello,

I have the same problem. I did the same but Im getting the error.

What I am doing wrong? Could you help me?


Thank you!

$functionname = 'core_course_create_courses';

$curs = new stdClass();
$curs->fullname = 'Curs de prova WS';
$curs->shortname = 'PWS';
$curs->category = 17;

$cursos = array($curs);

$params = array('courses'=> $cursos);

/// SOAP CALL
$serverurl = $domainname . '/webservice/soap/server.php'. '?wsdl=1&wstoken=' . $token;

$client = new SoapClient($serverurl);
try {
$resp = $client->__soapCall($functionname, $params);
} catch (Exception $e) {
print_r($e);
}
if (isset($resp)) {
print_r($resp);
}


error:

 [function] => __soapCall

                    [class] => SoapClient

                    [type] => ->

                    [args] => Array

                        (

                            [0] => core_course_create_courses

                            [1] => Array

                                (

                                    [courses] => Array

                                        (

                                            [0] => stdClass Object

                                                (

                                                    [fullname] => Curs de prova WS

                                                    [shortname] => PWS

                                                    [category] => 17

                                                )

                                        )