-
-
Save timhunt/51987ad386faca61fe013904c242e9b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(__DIR__ . '/config.php'); | |
require_once($CFG->dirroot . '/webservice/lib.php'); | |
$systemcontext = context_system::instance(); | |
// Enable web services and REST protocol. | |
set_config('enablewebservices', true); | |
set_config('webserviceprotocols', 'rest'); | |
// Create a web service user. | |
$webserviceuser = $this->datagenerator->create_user([ | |
'username' => 'ws-externalquiz-user', 'firstname' => 'Externalquiz grades', | |
'lastname' => 'User']); | |
// Create a web service role. | |
$wsroleid = create_role('WS Role for Externalquiz grades', 'ws-externalquiz-role', ''); | |
set_role_contextlevels($wsroleid, [CONTEXT_SYSTEM]); | |
assign_capability('webservice/rest:use', CAP_ALLOW, $wsroleid, $systemcontext->id, true); | |
assign_capability('mod/externalquiz:receivegrades', CAP_ALLOW, $wsroleid, $systemcontext->id, true); | |
// Give the user the role. | |
role_assign($wsroleid, $webserviceuser->id, $systemcontext->id); | |
// Enable the externalquiz webservice. | |
$webservicemanager = new webservice(); | |
$service = $webservicemanager->get_external_service_by_shortname('mod_externalquiz_receive_grades'); | |
$service->enabled = true; | |
$webservicemanager->update_external_service($service); | |
// Authorise the user to use the service. | |
$webservicemanager->add_ws_authorised_user((object) ['externalserviceid' => $service->id, | |
'userid' => $webserviceuser->id]); | |
// Create a token for the user. | |
$token = external_generate_token(EXTERNAL_TOKEN_PERMANENT, $service, $webserviceuser->id, $systemcontext); |
Hi, sorry, any have the endpoints for use the API of Moodle ?
Do you have any answer?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, sorry, any have the endpoints for use the API of Moodle ?