Get assignments for all students for all courses with webservice

Get assignments for all students for all courses with webservice

by William Bustos -
Number of replies: 1

Hi,

I need get information for assignments with grades for all students for all courses through a webservice with REST, Is there any some plugin or API of this module or i have to develop this action?.

Many thanks.

Average of ratings: -
In reply to William Bustos

Re: Get assignments for all students for all courses with webservice

by Adam Landow -

Hi William.

You can adapt the example at https://github.com/moodlehq/sample-ws-clients/tree/master/PHP-REST

The adapted code will look like:

<?php
// This file is NOT a part of Moodle - http://moodle.org/
//
// This client for Moodle 2 is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
/**
* REST client for Moodle 2
* Return JSON or XML format
*
* @authorr Jerome Mouneyrac
*/
/// SETUP - NEED TO BE CHANGED
$token = 'acabec9d20933913f14301785324f579';


// REST RETURNED VALUES FORMAT
$restformat = 'xml'; //Also possible in Moodle 2.2 and later: 'json'
//Setting it to 'json' will fail all calls on earlier Moodle version
$functionname = 'mod_assign_get_grades';
$params = array('assignmentids' => array(1,2,3,4));
// these numbers are the assignment IDs- you will need to find them via another webservice call or get from the database

// REST CALL
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);

Make sure you have set up your webservices correctly! See https://docs.moodle.org/20/en/Using_web_services for instructions...