Hi Yuri,
The error states that SoapClient can not be found, you need to enable the php extension:Â http://php.net/manual/en/soap.installation.php
Hi Yuri,
The error states that SoapClient can not be found, you need to enable the php extension:Â http://php.net/manual/en/soap.installation.php
Hi Tomasz,
core_user_get_users is internally using user_get_user_details, which only returns the current user preferences (https://github.com/moodle/moodle/blob/master/user/lib.php#L540)
Oh, I indeed noticed I could get the preferences for the client's user. Thanks for clarification.
Hi Pratim,
I understand that if you need to get the grades using  gradereport_user_get_grades_table web service is because you are processing these grades in an external application; if that is the case you will need a library for converting these grades to an excel, it would depend on your client's language. If you could do it within Moodle you could use lib/phpexcel or lib/csvlib.class.php.
Hi ,
I working on external application from which i want to post grades in to gradebook without change php code in moodle. I post grades using web services or Core API only change in to php code in external application . Is it possible.
Example:- I add External tools in moodle (Using external tools plugins),that page are redirect to another page and that page, I have given any test show i want that this grade automatic show in to gradebook without change in moodle php code,only change in external page.
Any one know about that so Please help me.
Hello Carlos sir ,
it will work perfectly .Â
use this link - https://github.com/moodlehq/sample-ws-clients/tree/master/PHP-XMLRPCÂ
try this code .Â
<?php
// file_name : client.php
$token = 'f29f8b6b8e04bf2a883d28f2bad8f5a4';
$domainname = 'http://localhost/moodle';
$functionname = 'core_user_get_users';
//////// core_enrol_get_users_courses ////////
//$user = new stdClass();
$user['key'] = 'userid';
$user['value'] = '2';
/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION
$params = array(array($user));
/// XML-RPC CALLÂ
print_r($params);
header('Content-Type: text/plain');
$serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token;
require_once('./curl.php');
$curl = new curl;
$post = xmlrpc_encode_request($functionname, $params);
$resp = xmlrpc_decode($curl->post($serverurl, $post));
print_r($resp);
?>
Moodle has some core external functions, but not all of them were web service enabled. How to enable other functions?Â
I tried the following, but didn't work:
Edit lib/db/services.php file, add function from $functions array to $services array. Am I missing something?
Thanks for answering
The form is really within Moodle. But I do not know how to modify the assigments core.
I've seen that you can get the student token using:
But I do not know the password
Hi,
I'm using core_course_create_categories to create categories. I'd like to set also visibility but there isn't  a suitable parameter.
Does exist a different method I can use?
Thanks!
Sara
Hi,
please help, bacause I have some problem with function:Â core_user_get_users_by_field.
This code works for me:
header('Content-Type: text/plain');
$params = array('field' => 'email','values[0]'=>'....@....');
$restformat = 'xml';
$functionname = 'core_user_get_users_by_field';
$serverurl = $domainname . '/webservice/rest/server.php'. '?wstoken=' . $token . '&wsfunction='.$functionname;
require_once('./curl.php');
$curl = new curl;
$restformat = ($restformat == 'json')?'&moodlewsrestformat=' . $restformat:'';
$resp = $curl->post($serverurl . $restformat, $params);//, $params
print_r($resp);
but this not works:
header('Content-Type: text/plain');
$functionname = 'core_user_get_users_by_field';
$params = array('field' => 'email','values'=>array('...@....'));
$serverurl = $domainname . '/webservice/xmlrpc/server.php'. '?wstoken=' . $token;
require_once('./curl.php');
$curl = new curl;
$post = xmlrpc_encode_request($functionname, $params );
$resp = xmlrpc_decode($curl->post($serverurl, $post));
print_r($resp);
Why? I have enabled all protocols.
I also tried: array($params), array(array($params)), but same problem.
I found detailed error:
field => Scalar type expected, array or object received.
Please help. My moodle 3.0 always return error when I want assign course to user.
I did steps by this wizard:Â http://www.rumours.co.nz/manuals/using_moodle_web_services.htm
I can list courses, list user, add user, but I can not assign course.
Always I got error:
Array ( [exception] => moodle_exception [errorcode] => wsusercannotassign [message] => You don't have the permission to assign this role (5) to this user (6) in this course(2). )What is the problem?
Hi All,
We've got a new implementation of the xmlrpc server landing in Integration today:
https://tracker.moodle.org/browse/MDL-52209
All going well, that will make it moodle.git (and download packages) by the end of this week. It would be extremely helpful to have third-party clients tested against this new implementation so we can iron out potential any issues before this implementation is eventually be released as part of Moodle 3.1 in May.
So if you've got a xmlrpc client, if you are able to test against this weeks integration or in the coming weeks - it would be appreciated. Thanks!
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
                        )
                    )
               Â
can any body tell me how to create new assignment using web services api. i have got api for updating the grades of already created assignment, but i am not getting how to create new one.
Please help.
Please reply. can anybody help me in this.Â
Hi,
I'm trying to develop a web service that create new resource module page in moodle from a webservice.
Doing some tests and tracking the database via pgadmin3, i make some insertions into the db, but i am doing something wrong, because moodle can't show these insertions.
If someone can help me, please, i'll be greated.
PS. This is my webservice code if anybody can test and make it works.
<?php
require_once("$CFG->libdir/externallib.php");
Â
class local_mypage_external extends external_api {
Â
  /**
   * Returns description of method parameters
   * @return external_function_parameters
   */
  public static function create_page_parameters() {
    return new external_function_parameters(
      array(
        'page' => new external_multiple_structure(
          new external_single_structure(
            array(
              'course' => new external_value(PARAM_INT, 'page record id'),
          'coursemodule' => new external_value(PARAM_INT, 'id of course'),
          'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
          'content'=> new external_value(PARAM_RAW, 'page description text'),
            )
          )
        )
      )
    );
  }
public static function create_page_returns() {
    return new external_single_structure(
      array(
         'id'    => new external_value(PARAM_INT, 'course id'),
                )
     );
    Â
  }
 public static function create_page($page) { //Don't forget to set it as static
    global $CFG, $DB;
    require_once("$CFG->dirroot/course/modlib.php");
 require_once("$CFG->dirroot/mod/page/lib.php");
    // Attempt to include module library before we make any changes to DB.
  $course=2;
  $moduleinfo = set_moduleinfo_defaults($moduleinfo);
  $moduleinfo= new stdClass();
  $moduleinfo->course = 2;
  $moduleinfo->modulename ='page';
  $moduleinfo->coursemodule='15';
  $moduleinfo->name='Pagina de prueba';
  $moduleinfo->content='pagina';
  $moduleinfo->section=1;
  Â
  // First add course_module record because we need the context.
  $newcm = new stdClass();
  $newcm->course      = 2;
  $newcm->module      = 15;
  $newcm->instance     = 0; // Not known yet, will be updated later (this is similar to restore code).
  $newcm->visible      = 1;
  $newcm->visibleold    = 1;
 Â
  $newcm->groupmode     = 0;
  $newcm->groupingid    = 0;
  $transaction = $DB->start_delegated_transaction();
  if (!$moduleinfo->coursemodule = add_course_module($newcm)) {
    print_error('cannotaddcoursemodule');
  }
  $addinstancefunction   = $moduleinfo->modulename."_add_instance";
  try {
    $returnfromfunc = page_add_instance($moduleinfo, $mform);
  } catch (moodle_exception $e) {
    $returnfromfunc = 'FAIL';
  }
  if (!$returnfromfunc or !is_number($returnfromfunc)) {
    // Undo everything we can. This is not necessary for databases which
    // support transactions, but improves consistency for other databases.
    $modcontext = context_module::instance($moduleinfo->coursemodule);
    context_helper::delete_instance(CONTEXT_MODULE, $moduleinfo->coursemodule);
    $DB->delete_records('course_modules', array('id'=>$moduleinfo->coursemodule));
    if ($e instanceof moodle_exception) {
      throw $e;
    } else if (!is_number($returnfromfunc)) {
      print_error('invalidfunction', '', course_get_url($course, $moduleinfo->section));
    } else {
      print_error('cannotaddnewmodule', '', course_get_url($course, $moduleinfo->section), $moduleinfo->modulename);
    }
  }
  $moduleinfo->instance = $returnfromfunc;
  $DB->set_field('course_modules', 'instance', $returnfromfunc, array('id'=>$moduleinfo->coursemodule));
// Update embedded links and save files.
   $modcontext = context_module::instance($moduleinfo->coursemodule);
    if (!empty($introeditor)) {
      $moduleinfo->intro = file_save_draft_area_files($introeditor['itemid'], $modcontext->id,
                             'mod_'.$moduleinfo->modulename, 'intro', 0,
                            array('subdirs'=>true), $introeditor['text']);
$DB->set_field($moduleinfo->modulename, 'intro', $moduleinfo->intro, array('id'=>$moduleinfo->instance));
   }
$cm = $DB->get_record('page', array('id' => $returnfromfunc), '*', MUST_EXIST);
Â
       // Check if we have not yet confirmed they have permission in this course.
         $context = context_course::instance($cm->course);
         self::validate_context($context);
 $modcontext = context_module::instance($cm->id);       Â
  require_capability('mod/page:addinstance', $modcontext);
  $eventdata = clone $moduleinfo;
  $eventdata->modname = $eventdata->modulename;
   $eventdata->id = $eventdata->coursemodule;
   $event = \core\event\course_module_created::create_from_cm($eventdata, $modcontext);
  $event->trigger();
   $moduleinfo = edit_module_post_actions($moduleinfo, $course);
   $transaction->allow_commit();
 return array('id'=>$returnfromfunc);
 }
}
can any body tell me how to create new assignment using web services api. i have got api for updating the grades of already created assignment, but i am not getting how to create new one using web services api.
Please help
I'm using Moodle 2.8.9 (20151204).Â
As the instructor, I can go to:
Home >Â My courses >Â Miscellaneous > Course101 > Participants
Looking at the "Last access to course" column gives me the information I want.
I'm trying to find this same information via the api, but I'm coming up short.Â
I expected to see this via the "core_enrol_get_enrolled_users" web service function. However, I only see the site (LMS) last access date, and not the course last access date.
It seems strange to be allowed to add a first and last name 'phonetic' but not be allowed to add an instution or department when calling 'core_user_create_users'.
Can anyone help?
Hi,
We are looking to do the same thing. Have you any news on this subject?
Thanks
Jean-Kristof