-

Note: You are currently viewing documentation for Moodle 3.10. Up-to-date documentation for the latest stable version of Moodle may be available here: Migration Web services.

Migration Web services

From MoodleDocs
Revision as of 14:32, 15 January 2021 by Marina Glancy (talk | contribs) (Created page with "{{Workplace}} == Overview == Web services for the Moodle Workplace Migrations feature. == Set up == * Create a new service with the functions: '''tool_wp_perform_export...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

workplacelogo.png This feature is part of Moodle Workplace, which is available through Moodle Partners.


Overview

Web services for the Moodle Workplace Migrations feature.

Set up

  • Create a new service with the functions: tool_wp_perform_export, tool_wp_perform_import, tool_wp_retrieve_export_file or add these functions to the existing service
  • Allow this service for everybody or for users who you want to be able to use them
  • Create tokens for the users, enable protocols, add capabilities to use protocols

See more information under Using web services

Export

The following examples use command-line calls using the REST protocol. The output is piped through jq command to display JSON in a more readable way. There are many ways to call web-services and there are other alternatives of how to parse JSON. Adjust commands as needed. Do not forget to replace the site name and the token with your token.

Dry run

First execute the web-service tool_wp_perform_export with the parameter dryrun=1, it will validate input, show some information but will not actually schedule an export. You must pass parameter exporter. If the exporter is not available the error message will be displayed. The error message contains the list of all available exporters. For example:

$ curl 'https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json' \ --data 'wsfunction=tool_wp_perform_export&exporter=&dryrun=1&wstoken=cf3788edbe41d7a89e963d9432b15331' \ | jq

{

 "exception": "invalid_parameter_exception",
 "errorcode": "invalidparameter",
 "message": "Invalid parameter value detected (Could not find exporter \nChoose from: tool_certification\\tool_wp\\exporter\\certifications, tool_dynamicrule\\tool_wp\\exporter\\rules, tool_organisation\\tool_wp\\exporter\\jobs, tool_organisation\\tool_wp\\exporter\\orgstructure, tool_program\\tool_wp\\exporter\\programs, tool_reportbuilder\\tool_wp\\exporter\\customreports, tool_tenant\\tool_wp\\exporter\\tenants, tool_wp\\tool_wp\\exporter\\certificates, tool_wp\\tool_wp\\exporter\\cohorts, tool_wp\\tool_wp\\exporter\\coursecategories, tool_wp\\tool_wp\\exporter\\courses, tool_wp\\tool_wp\\exporter\\site, tool_wp\\tool_wp\\exporter\\users)"

}

Now try again with the exporter name:

$ curl 'https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json' \ --data 'wsfunction=tool_wp_perform_export&exporter=tool_organisation\tool_wp\exporter\orgstructure&wstoken=cf3788edbe41d7a89e963d9432b15331' \ | jq

{

   "id": 0,
   "settings": [
       {
           "name": "export_instances",
           "value": "all"
       },
       {
           "name": "select_frameworks",
           "value": ""
       }
   ]

}

Because it is a dry-run, the id=0 is returned (export was not actually scheduled). The web service also returns the list of settings that will be applied to the export. You may wish to change some of these settings, for example, we can export only positions by adding &settings[0][name]=export_instances&settings[0][value]=positions to the URL (to pass more settings use a different index).

Schedule export

Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:

curl 'http://localhost/workplace/webservice/rest/server.php?moodlewsrestformat=json' \ --data 'wsfunction=tool_wp_perform_export&exporter=tool_organisation\tool_wp\exporter\orgstructure&settings[0][name]=export_instances&settings[0][value]=positions&wstoken=cf3788edbe41d7a89e963d9432b15331' \ | jq

{

 "id": 19,
 "settings": [
   {
     "name": "export_instances",
     "value": "positions"
   },
   {
     "name": "select_frameworks",
     "value": ""
   }
 ]

}