<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/310/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marina.glancy</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/310/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marina.glancy"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/Special:Contributions/Marina.glancy"/>
	<updated>2026-04-11T05:00:55Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_Release_notes&amp;diff=139820</id>
		<title>Moodle Workplace Release notes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_Release_notes&amp;diff=139820"/>
		<updated>2021-03-09T10:02:03Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to dev:Moodle Workplace releases&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[:dev:Moodle_Workplace_releases]]&lt;br /&gt;
&lt;br /&gt;
This page has been moved to [[:dev:Moodle_Workplace_releases|Moodle Workplace releases]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.10.1_new_features_page&amp;diff=139819</id>
		<title>Moodle Workplace 3.10.1 new features page</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.10.1_new_features_page&amp;diff=139819"/>
		<updated>2021-03-09T10:01:23Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to Moodle Workplace new features&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Moodle Workplace new features]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.10_new_features_page&amp;diff=139818</id>
		<title>Moodle Workplace 3.10 new features page</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.10_new_features_page&amp;diff=139818"/>
		<updated>2021-03-09T10:01:05Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to Moodle Workplace new features&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Moodle Workplace new features]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.9.2_new_features_page&amp;diff=139817</id>
		<title>Moodle Workplace 3.9.2 new features page</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.9.2_new_features_page&amp;diff=139817"/>
		<updated>2021-03-09T10:00:38Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to Moodle Workplace new features&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Moodle Workplace new features]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.9.1_new_features_page&amp;diff=139816</id>
		<title>Moodle Workplace 3.9.1 new features page</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.9.1_new_features_page&amp;diff=139816"/>
		<updated>2021-03-09T10:00:10Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to Moodle Workplace new features&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Moodle Workplace new features]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.9_new_features_page&amp;diff=139815</id>
		<title>Moodle Workplace 3.9 new features page</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.9_new_features_page&amp;diff=139815"/>
		<updated>2021-03-09T09:59:26Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to Moodle Workplace new features&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Moodle Workplace new features]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.8.2_new_features_page&amp;diff=139814</id>
		<title>Moodle Workplace 3.8.2 new features page</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.8.2_new_features_page&amp;diff=139814"/>
		<updated>2021-03-09T09:56:00Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to Moodle Workplace new features&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Moodle Workplace new features]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.9_new_features_page&amp;diff=139813</id>
		<title>Moodle Workplace 3.9 new features page</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_3.9_new_features_page&amp;diff=139813"/>
		<updated>2021-03-09T09:51:09Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to dev:Moodle Workplace releases&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[:dev:Moodle_Workplace_releases]]&lt;br /&gt;
&lt;br /&gt;
This page has been moved to [[:dev:Moodle_Workplace_releases|Moodle Workplace releases]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_Release_notes&amp;diff=139810</id>
		<title>Moodle Workplace Release notes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_Release_notes&amp;diff=139810"/>
		<updated>2021-03-09T07:52:40Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
This page has been moved to [https://docs.moodle.org/dev/Moodle_Workplace_releases Moodle Workplace releases]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This page contains release notes for Moodle Workplace releases.&lt;br /&gt;
&lt;br /&gt;
=3.10.1=&lt;br /&gt;
See our [[Moodle Workplace 3.10.1 new features page]] in the user documentation for an introduction to Moodle Workplace 3.10.1 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* Bulk actions for users allocated on programs/certifications. Program and Certification users allocations can now be all edited at once. Available bulk actions for allocations are: Edit status and dates, Reset users program and De-allocate users.&lt;br /&gt;
* Dynamic rules UI improvements. Rules that are not completely based on events and, therefore, are not instant, are now marked as &amp;quot;Scheduled tasks&amp;quot; in the UI. Also, new filters had been added, making it easier to look for existing rules.&lt;br /&gt;
* Keep enrolments in the shared programs’ courses when used is moved to another tenant. When a user is moved to another tenant, it&#039;s correspondent enrolment in all shared programs is kept and course groups are changed accordingly.&lt;br /&gt;
&lt;br /&gt;
=3.10=&lt;br /&gt;
See our [[Moodle Workplace 3.10 new features page]] in the user documentation for an introduction to Moodle Workplace 3.10 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* Multi-tenant authentication: Selected authentication settings such as authentication instructions and allowed domains can be overridden for individual tenants. Site administrators are also able to force some settings for all tenants. Tenant admin can override common settings or settings for multi-tenant auth plugins in their tenant using the new Authentication tab in the Users page.&lt;br /&gt;
* Multi-tenant auth plugins: Email-based self-registration and OAuth2 are now multi-tenant. Global administrator or tenant administrator can enable/disable these plugins on a tenant level and override their settings. When a new user signs up from a tenant-specific login page their account is automatically registered inside this tenant.&lt;br /&gt;
* [[Report_builder#Shared_reports|Shared reports]]: Reports are available now in the Shared Space and can be shared with all tenants or be only accessible to users with access to the shared space. This feature enables users to use the same report definition site-wide without duplicating the same reports in all tenants. It also allows to create cross-tenant reports. When a shared report is viewed from inside the tenant it only displays the users and entities from this tenant. When a shared report is viewed from Shared space it shows information from all tenants.&lt;br /&gt;
* Full site content [[Migrations|migration]]: Now it’s possible to migrate all the site content including all tenants in the system and all the courses with user data. This feature uses all the chained exporters and importers we introduced on the previous releases.&lt;br /&gt;
* Tenant-allocation [[Dynamic rules|dynamic rules]]: Addition of users to tenants now can be automated using Dynamic Rules. We’ve introduced a new condition to target new users which can be combined with any other conditions such as email domains or authentication plugins to decide where to allocate them. Tenant allocation dynamic rules should be normally created inside the Default tenant.&lt;br /&gt;
* New Workplace native site users page: Revamped Browse all users page with the list of all users on the site with the tenant information, bulk actions and filters.&lt;br /&gt;
&lt;br /&gt;
===Upgrade notes for 3.10===&lt;br /&gt;
Upgrading workplace to 3.10:&lt;br /&gt;
* New capability tool/tenant:authconfig can be added to the &amp;quot;Tenant administrator&amp;quot; role to allow tenant administrators to override authentication settings. New installations of Moodle Workplace 3.10 will have this capability allowed by default. For security reasons this capability is not added to the &amp;quot;Tenant administrator&amp;quot; role during upgrade from Workplace 3.9 since no configuration settings are forced by default.&lt;br /&gt;
* If you have plugins that use workplace APIs, such as multi-tenancy or dynamic rules check out the CHANGELOG.md file in the respective plugins (admin/tool/tenant and admin/tool/dynamicrule). From now on the workplace team will be maintaining the changelogs for API changes.&lt;br /&gt;
&lt;br /&gt;
=3.9.2=&lt;br /&gt;
See our [[Moodle Workplace 3.9.2 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9.2 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Multi-tenancy#Shared_Space|Shared Space]] enables easy sharing of entities across all tenants. It works like a special tenant where users can create supported entities to be available in other tenants.&lt;br /&gt;
* [[Programs#Shared_programs|Shared Programs]] and [[Certifications#Shared_Certifications|Shared certifications]]: making use of the Shared Space, now it’s possible to share Programs and Certifications across all tenants.&lt;br /&gt;
* Tenants [[Migrations|migration]]: now it’s possible to migrate whole tenants’ content and configuration using all the chained exporters and importers we introduced on the previous releases.&lt;br /&gt;
* Learning tab: this is a major change in the [[Learner_dashboard|Workplace learner dashboard]]. Programs and Courses are not separated in different tabs anymore, with the new Learning tab all the learning entities are shown in the same tab. We took the opportunity to improve the UI as well.&lt;br /&gt;
* [[Certificate_course_activity|Course certificate]]: with this activity module now it’s possible to configure certificates at a course level. This certificate can be configured to be issued automatically when the activity is available without any user intervention.&lt;br /&gt;
&lt;br /&gt;
=3.9.1=&lt;br /&gt;
See our [[Moodle Workplace 3.9.1 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9.1 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Migrations|Migration feature]]. New exporters and importers:&lt;br /&gt;
** [[Report builder]]: custom reports, including schedules and audiences&lt;br /&gt;
** [[Certificates]]: templates and issued certificates&lt;br /&gt;
** [[Organisation structure]] CSV: importers for departments and positions hierarchies from external systems in CSV format&lt;br /&gt;
* Direct reports Teams tab filter: added a new filter to made the teams tab only show people directly underneath the current user&lt;br /&gt;
* Added download options to system reports, such as Users list on the tenant management page&lt;br /&gt;
&lt;br /&gt;
=3.9=&lt;br /&gt;
See our [[Moodle Workplace 3.9 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Migrations|Migration feature]]: this tool, through an intuitive step-by-step process, offers the capacity to export different parts of a Moodle Workplace instance and import them into the same or a different site.&lt;br /&gt;
* Exporters and Importers included in 3.9: &lt;br /&gt;
** Programs: definition, courses, user allocations and component dynamic rules.&lt;br /&gt;
** Certifications: definition, associated programs, courses, user allocations and component dynamic rules.&lt;br /&gt;
** Dynamic Rules: definition, conditions and actions,&lt;br /&gt;
** Organisation Structure (Jobs): jobs details with their associated department and position frameworks.&lt;br /&gt;
** Organisation Structure (Frameworks): department and position frameworks with the whole hierarchy for departments and/or positions.&lt;br /&gt;
** Courses using default course backup options.&lt;br /&gt;
* Command-line interactive interface for Migration&lt;br /&gt;
* Dynamic Rules additional capabilities check for each condition and action. Now we check users capabilities for each type of dynamic rules conditions and actions, enabling more granularity in Dynamic Rules permissions.&lt;br /&gt;
* Video conferencing with BigBlueButton, built-in in Workplace on MoodleCloud.&lt;br /&gt;
* Report Builder filter and condition for the current user: pre-filter any report to show only information related to the viewer.&lt;br /&gt;
* Improved course information modal: now users can access all the information about course in a program from the UI.&lt;br /&gt;
&lt;br /&gt;
=3.8.2=&lt;br /&gt;
&lt;br /&gt;
See our [[Workplace new features]] page in the user documentation for an introduction to Moodle Workplace 3.8.2 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Programs]] - addition to the [[Moodle_Workplace#Dashboard|Workplace Dashboard]] to allow users to search for their own programs&lt;br /&gt;
* [[Programs]] - improved programs list view on the [[Moodle_Workplace#Dashboard|Workplace Dashboard]], with expandable courses information&lt;br /&gt;
* [[Report builder]] and [[Dynamic rules]] - Live Search is now available for Conditions and Actions on Dynamic Rules and for Entities and fields (Report Builder) on Report Builder&lt;br /&gt;
* Login page - new auth instructions redesign and addition of the language selector&lt;br /&gt;
* [[Report builder]] - Sort columns on click&lt;br /&gt;
* [[Report builder]] - Collapsable left container and &lt;br /&gt;
* [[Report builder]] - Preview and filter buttons redesigning&lt;br /&gt;
* Test coverage and performance improvements across all Workplace features&lt;br /&gt;
* Workplace testing environment for plugin developers now available&lt;br /&gt;
* Workplace launcher - an alternative view as a modal dialog box is now available (experimental)&lt;br /&gt;
* Auto-updating for restricted activities in Workplace list course format&lt;br /&gt;
* Fixed app link in Workplace footer&lt;br /&gt;
&lt;br /&gt;
=3.8.1=&lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* [[Appointments]] - continued user interface polishing and improvements; new [[Report builder]] datasource to facilitate custom reporting; improvements to custom fields&lt;br /&gt;
* [[Certifications#Users|Certifications]] - new &amp;quot;Certification activity log&amp;quot; to show a users progress through an allocated certification&lt;br /&gt;
* [[Programs]] - addition to the [[Moodle_Workplace#Dashboard|Workplace Dashboard]] to allow users to filter their own programs&lt;br /&gt;
* [[Programs]] and [[Certifications]] - improvements to automatic [[Dynamic rules]] (clearer names, improved conditions, ability to set allocation start date in future); improved custom field support&lt;br /&gt;
* Improvements to the [[Multi-tenancy#Tenant_administration|Tenant administrator]] role - the list of capabilities that can be granted to a tenant administrator is restricted to those capabilities that support [[Multi-tenancy]] as defined by the Workplace plugins. Manually assigning Workplace roles is no longer possible via the assign roles page to avoid confusion, however the list of allowed capabilities in these roles may be changed by the site administrator&lt;br /&gt;
* Improved performance when editing tenant theme settings - caches are now purged only for the relevant tenant, rather than for all&lt;br /&gt;
* Consistent configuration for setting limits for [[Multi-tenancy#Limiting_number_of_tenants|Tenants]], [[Dynamic_rules#Limiting_number_of_dynamic_rules|Dynamic rules]] and [[Report_builder#Limiting_number_of_custom_reports|Report builder]]&lt;br /&gt;
* Privacy API improvements&lt;br /&gt;
&lt;br /&gt;
=3.8=&lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* [[Programs#Program_reset|Program reset]] - allows to reset a program and all courses it in for an individual user&lt;br /&gt;
* [[Certifications#Recertification|Recertification]] - allows to configure the workflow for regular recertification&lt;br /&gt;
* [[Report builder#Configuring_audience|Audience]] in report builder allows to give granular access to individual reports&lt;br /&gt;
* [[Appointments]] - new module that allows to book face-to-face appointments between trainers and students in a course&lt;br /&gt;
* [[Certificates]] no longer belong to the tenants but instead can be created in course categories&lt;br /&gt;
* [[Programs#Shared_courses|Sharing courses]] between tenants and using them in the programs&lt;br /&gt;
&lt;br /&gt;
==Important upgrade notes==&lt;br /&gt;
&lt;br /&gt;
===Report builder changes===&lt;br /&gt;
&lt;br /&gt;
Organisation managers can no longer access the reports on their team by default. Instead, tenant administrators need to create new reports with the condition &amp;quot;Relation to report viewer&amp;quot; and set the &amp;quot;Audience&amp;quot; to include an organisation manager&#039;s job.&lt;br /&gt;
&lt;br /&gt;
===Certificates===&lt;br /&gt;
&lt;br /&gt;
The Certificates plugin has been reworked to allow users to create certificates in course categories instead of binding them to tenants. This plugin will be made available in the future outside of Moodle Workplace.&lt;br /&gt;
&lt;br /&gt;
The upgrade script will automatically unallocate the existing certificates from the tenants and allocate them to the respective course categories of the tenants. However &#039;&#039;&#039;if there was a tenant without a course category and with certificates&#039;&#039;&#039;, the administrator needs &#039;&#039;&#039;to fix it manually&#039;&#039;&#039; - create a category for the tenant and move the certificate(s) to this category.&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:verifyforalltenants&#039; is removed and instead we have [[Capabilities/tool/certificate:verify|&#039;tool/certificate:verify&#039;]] that will allow users to verify certificates for any tenant (by code).&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:issueforalltenants&#039; is removed. Users with the capability [[Capabilities/tool/certificate:issue|&#039;tool/certificate:issue&#039;]] can issue certificates to users from their tenant. If such user also has capabilities allowing him to view users from other tenants, they will be able to issue certificate to all users.&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:manageforalltenants&#039; is removed. Instead, capability [[Capabilities/tool/certificate:manage|&#039;tool/certificate:manage&#039;]] can be assigned in different contexts and will work on templates that are defined in the relevant contexts.&lt;br /&gt;
&lt;br /&gt;
Capability [[Capabilities/tool/certificate:issue|&#039;tool/certificate:issue&#039;]] can now be assigned in different contexts (system or course category). Users who have it can issue certificates that are defined in the same context (or lower).&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:imageforalltenants&#039; is renamed to [[Capabilities/tool/certificate:image|&#039;tool/certificate:image&#039;]] - allows users to manage shared images.&lt;br /&gt;
&lt;br /&gt;
Capability [[Capabilities/tool/certificate:viewallcertificates|&#039;tool/certificate:viewallcertificates&#039;]] can also be assigned in different contexts now. Similar to &#039;issue&#039; capability, users will only see other users from the same tenant (unless they have additional capabilities that allow them to view users in other tenants)&lt;br /&gt;
&lt;br /&gt;
The element type &amp;quot;Program&amp;quot; is now called &#039;&#039;&#039;&amp;quot;Dynamic rule data&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Setting limits for tenant-related data==&lt;br /&gt;
&lt;br /&gt;
It is possible for site administrators to limit the amount of data related to a tenant for certain features:&lt;br /&gt;
&lt;br /&gt;
* The number of [[Multi-tenancy|tenants]] can be restricted by setting &#039;$CFG-&amp;gt;tool_tenant_tenantlimit = &amp;lt;VALUE&amp;gt;;&#039; in your [[Configuration_file|site configuration]]&lt;br /&gt;
* The number of [[Report_builder#Creating_a_custom_report|custom reports]] can be restricted per site/tenant by setting &#039;$CFG-&amp;gt;tool_reportbuilder_sitelimit&#039; and &#039;$CFG-&amp;gt;tool_reportbuilder_tenantlimit&#039; respectively&lt;br /&gt;
* The number of [[Dynamic_rules#Creating_dynamic_rules|dynamic rules]] can be restricted per site/tenant by setting &#039;$CFG-&amp;gt;tool_dynamicrule_sitelimit&#039; and &#039;$CFG-&amp;gt;tool_dynamicrule_tenantlimit&#039; respectively&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_Release_notes&amp;diff=139809</id>
		<title>Moodle Workplace Release notes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_Release_notes&amp;diff=139809"/>
		<updated>2021-03-09T07:51:30Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [https://docs.moodle.org/dev/Moodle_Workplace_releases]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
This page has been moved to [https://docs.moodle.org/dev/Moodle_Workplace_releases Moodle Workplace releases]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This page contains release notes for Moodle Workplace releases.&lt;br /&gt;
&lt;br /&gt;
=3.10.1=&lt;br /&gt;
See our [[Moodle Workplace 3.10.1 new features page]] in the user documentation for an introduction to Moodle Workplace 3.10.1 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* Bulk actions for users allocated on programs/certifications. Program and Certification users allocations can now be all edited at once. Available bulk actions for allocations are: Edit status and dates, Reset users program and De-allocate users.&lt;br /&gt;
* Dynamic rules UI improvements. Rules that are not completely based on events and, therefore, are not instant, are now marked as &amp;quot;Scheduled tasks&amp;quot; in the UI. Also, new filters had been added, making it easier to look for existing rules.&lt;br /&gt;
* Keep enrolments in the shared programs’ courses when used is moved to another tenant. When a user is moved to another tenant, it&#039;s correspondent enrolment in all shared programs is kept and course groups are changed accordingly.&lt;br /&gt;
&lt;br /&gt;
=3.10=&lt;br /&gt;
See our [[Moodle Workplace 3.10 new features page]] in the user documentation for an introduction to Moodle Workplace 3.10 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* Multi-tenant authentication: Selected authentication settings such as authentication instructions and allowed domains can be overridden for individual tenants. Site administrators are also able to force some settings for all tenants. Tenant admin can override common settings or settings for multi-tenant auth plugins in their tenant using the new Authentication tab in the Users page.&lt;br /&gt;
* Multi-tenant auth plugins: Email-based self-registration and OAuth2 are now multi-tenant. Global administrator or tenant administrator can enable/disable these plugins on a tenant level and override their settings. When a new user signs up from a tenant-specific login page their account is automatically registered inside this tenant.&lt;br /&gt;
* [[Report_builder#Shared_reports|Shared reports]]: Reports are available now in the Shared Space and can be shared with all tenants or be only accessible to users with access to the shared space. This feature enables users to use the same report definition site-wide without duplicating the same reports in all tenants. It also allows to create cross-tenant reports. When a shared report is viewed from inside the tenant it only displays the users and entities from this tenant. When a shared report is viewed from Shared space it shows information from all tenants.&lt;br /&gt;
* Full site content [[Migrations|migration]]: Now it’s possible to migrate all the site content including all tenants in the system and all the courses with user data. This feature uses all the chained exporters and importers we introduced on the previous releases.&lt;br /&gt;
* Tenant-allocation [[Dynamic rules|dynamic rules]]: Addition of users to tenants now can be automated using Dynamic Rules. We’ve introduced a new condition to target new users which can be combined with any other conditions such as email domains or authentication plugins to decide where to allocate them. Tenant allocation dynamic rules should be normally created inside the Default tenant.&lt;br /&gt;
* New Workplace native site users page: Revamped Browse all users page with the list of all users on the site with the tenant information, bulk actions and filters.&lt;br /&gt;
&lt;br /&gt;
===Upgrade notes for 3.10===&lt;br /&gt;
Upgrading workplace to 3.10:&lt;br /&gt;
* New capability tool/tenant:authconfig can be added to the &amp;quot;Tenant administrator&amp;quot; role to allow tenant administrators to override authentication settings. New installations of Moodle Workplace 3.10 will have this capability allowed by default. For security reasons this capability is not added to the &amp;quot;Tenant administrator&amp;quot; role during upgrade from Workplace 3.9 since no configuration settings are forced by default.&lt;br /&gt;
* If you have plugins that use workplace APIs, such as multi-tenancy or dynamic rules check out the CHANGELOG.md file in the respective plugins (admin/tool/tenant and admin/tool/dynamicrule). From now on the workplace team will be maintaining the changelogs for API changes.&lt;br /&gt;
&lt;br /&gt;
=3.9.2=&lt;br /&gt;
See our [[Moodle Workplace 3.9.2 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9.2 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Multi-tenancy#Shared_Space|Shared Space]] enables easy sharing of entities across all tenants. It works like a special tenant where users can create supported entities to be available in other tenants.&lt;br /&gt;
* [[Programs#Shared_programs|Shared Programs]] and [[Certifications#Shared_Certifications|Shared certifications]]: making use of the Shared Space, now it’s possible to share Programs and Certifications across all tenants.&lt;br /&gt;
* Tenants [[Migrations|migration]]: now it’s possible to migrate whole tenants’ content and configuration using all the chained exporters and importers we introduced on the previous releases.&lt;br /&gt;
* Learning tab: this is a major change in the [[Learner_dashboard|Workplace learner dashboard]]. Programs and Courses are not separated in different tabs anymore, with the new Learning tab all the learning entities are shown in the same tab. We took the opportunity to improve the UI as well.&lt;br /&gt;
* [[Certificate_course_activity|Course certificate]]: with this activity module now it’s possible to configure certificates at a course level. This certificate can be configured to be issued automatically when the activity is available without any user intervention.&lt;br /&gt;
&lt;br /&gt;
=3.9.1=&lt;br /&gt;
See our [[Moodle Workplace 3.9.1 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9.1 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Migrations|Migration feature]]. New exporters and importers:&lt;br /&gt;
** [[Report builder]]: custom reports, including schedules and audiences&lt;br /&gt;
** [[Certificates]]: templates and issued certificates&lt;br /&gt;
** [[Organisation structure]] CSV: importers for departments and positions hierarchies from external systems in CSV format&lt;br /&gt;
* Direct reports Teams tab filter: added a new filter to made the teams tab only show people directly underneath the current user&lt;br /&gt;
* Added download options to system reports, such as Users list on the tenant management page&lt;br /&gt;
&lt;br /&gt;
=3.9=&lt;br /&gt;
See our [[Moodle Workplace 3.9 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Migrations|Migration feature]]: this tool, through an intuitive step-by-step process, offers the capacity to export different parts of a Moodle Workplace instance and import them into the same or a different site.&lt;br /&gt;
* Exporters and Importers included in 3.9: &lt;br /&gt;
** Programs: definition, courses, user allocations and component dynamic rules.&lt;br /&gt;
** Certifications: definition, associated programs, courses, user allocations and component dynamic rules.&lt;br /&gt;
** Dynamic Rules: definition, conditions and actions,&lt;br /&gt;
** Organisation Structure (Jobs): jobs details with their associated department and position frameworks.&lt;br /&gt;
** Organisation Structure (Frameworks): department and position frameworks with the whole hierarchy for departments and/or positions.&lt;br /&gt;
** Courses using default course backup options.&lt;br /&gt;
* Command-line interactive interface for Migration&lt;br /&gt;
* Dynamic Rules additional capabilities check for each condition and action. Now we check users capabilities for each type of dynamic rules conditions and actions, enabling more granularity in Dynamic Rules permissions.&lt;br /&gt;
* Video conferencing with BigBlueButton, built-in in Workplace on MoodleCloud.&lt;br /&gt;
* Report Builder filter and condition for the current user: pre-filter any report to show only information related to the viewer.&lt;br /&gt;
* Improved course information modal: now users can access all the information about course in a program from the UI.&lt;br /&gt;
&lt;br /&gt;
=3.8.2=&lt;br /&gt;
&lt;br /&gt;
See our [[Workplace new features]] page in the user documentation for an introduction to Moodle Workplace 3.8.2 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Programs]] - addition to the [[Moodle_Workplace#Dashboard|Workplace Dashboard]] to allow users to search for their own programs&lt;br /&gt;
* [[Programs]] - improved programs list view on the [[Moodle_Workplace#Dashboard|Workplace Dashboard]], with expandable courses information&lt;br /&gt;
* [[Report builder]] and [[Dynamic rules]] - Live Search is now available for Conditions and Actions on Dynamic Rules and for Entities and fields (Report Builder) on Report Builder&lt;br /&gt;
* Login page - new auth instructions redesign and addition of the language selector&lt;br /&gt;
* [[Report builder]] - Sort columns on click&lt;br /&gt;
* [[Report builder]] - Collapsable left container and &lt;br /&gt;
* [[Report builder]] - Preview and filter buttons redesigning&lt;br /&gt;
* Test coverage and performance improvements across all Workplace features&lt;br /&gt;
* Workplace testing environment for plugin developers now available&lt;br /&gt;
* Workplace launcher - an alternative view as a modal dialog box is now available (experimental)&lt;br /&gt;
* Auto-updating for restricted activities in Workplace list course format&lt;br /&gt;
* Fixed app link in Workplace footer&lt;br /&gt;
&lt;br /&gt;
=3.8.1=&lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* [[Appointments]] - continued user interface polishing and improvements; new [[Report builder]] datasource to facilitate custom reporting; improvements to custom fields&lt;br /&gt;
* [[Certifications#Users|Certifications]] - new &amp;quot;Certification activity log&amp;quot; to show a users progress through an allocated certification&lt;br /&gt;
* [[Programs]] - addition to the [[Moodle_Workplace#Dashboard|Workplace Dashboard]] to allow users to filter their own programs&lt;br /&gt;
* [[Programs]] and [[Certifications]] - improvements to automatic [[Dynamic rules]] (clearer names, improved conditions, ability to set allocation start date in future); improved custom field support&lt;br /&gt;
* Improvements to the [[Multi-tenancy#Tenant_administration|Tenant administrator]] role - the list of capabilities that can be granted to a tenant administrator is restricted to those capabilities that support [[Multi-tenancy]] as defined by the Workplace plugins. Manually assigning Workplace roles is no longer possible via the assign roles page to avoid confusion, however the list of allowed capabilities in these roles may be changed by the site administrator&lt;br /&gt;
* Improved performance when editing tenant theme settings - caches are now purged only for the relevant tenant, rather than for all&lt;br /&gt;
* Consistent configuration for setting limits for [[Multi-tenancy#Limiting_number_of_tenants|Tenants]], [[Dynamic_rules#Limiting_number_of_dynamic_rules|Dynamic rules]] and [[Report_builder#Limiting_number_of_custom_reports|Report builder]]&lt;br /&gt;
* Privacy API improvements&lt;br /&gt;
&lt;br /&gt;
=3.8=&lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* [[Programs#Program_reset|Program reset]] - allows to reset a program and all courses it in for an individual user&lt;br /&gt;
* [[Certifications#Recertification|Recertification]] - allows to configure the workflow for regular recertification&lt;br /&gt;
* [[Report builder#Configuring_audience|Audience]] in report builder allows to give granular access to individual reports&lt;br /&gt;
* [[Appointments]] - new module that allows to book face-to-face appointments between trainers and students in a course&lt;br /&gt;
* [[Certificates]] no longer belong to the tenants but instead can be created in course categories&lt;br /&gt;
* [[Programs#Shared_courses|Sharing courses]] between tenants and using them in the programs&lt;br /&gt;
&lt;br /&gt;
==Important upgrade notes==&lt;br /&gt;
&lt;br /&gt;
===Report builder changes===&lt;br /&gt;
&lt;br /&gt;
Organisation managers can no longer access the reports on their team by default. Instead, tenant administrators need to create new reports with the condition &amp;quot;Relation to report viewer&amp;quot; and set the &amp;quot;Audience&amp;quot; to include an organisation manager&#039;s job.&lt;br /&gt;
&lt;br /&gt;
===Certificates===&lt;br /&gt;
&lt;br /&gt;
The Certificates plugin has been reworked to allow users to create certificates in course categories instead of binding them to tenants. This plugin will be made available in the future outside of Moodle Workplace.&lt;br /&gt;
&lt;br /&gt;
The upgrade script will automatically unallocate the existing certificates from the tenants and allocate them to the respective course categories of the tenants. However &#039;&#039;&#039;if there was a tenant without a course category and with certificates&#039;&#039;&#039;, the administrator needs &#039;&#039;&#039;to fix it manually&#039;&#039;&#039; - create a category for the tenant and move the certificate(s) to this category.&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:verifyforalltenants&#039; is removed and instead we have [[Capabilities/tool/certificate:verify|&#039;tool/certificate:verify&#039;]] that will allow users to verify certificates for any tenant (by code).&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:issueforalltenants&#039; is removed. Users with the capability [[Capabilities/tool/certificate:issue|&#039;tool/certificate:issue&#039;]] can issue certificates to users from their tenant. If such user also has capabilities allowing him to view users from other tenants, they will be able to issue certificate to all users.&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:manageforalltenants&#039; is removed. Instead, capability [[Capabilities/tool/certificate:manage|&#039;tool/certificate:manage&#039;]] can be assigned in different contexts and will work on templates that are defined in the relevant contexts.&lt;br /&gt;
&lt;br /&gt;
Capability [[Capabilities/tool/certificate:issue|&#039;tool/certificate:issue&#039;]] can now be assigned in different contexts (system or course category). Users who have it can issue certificates that are defined in the same context (or lower).&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:imageforalltenants&#039; is renamed to [[Capabilities/tool/certificate:image|&#039;tool/certificate:image&#039;]] - allows users to manage shared images.&lt;br /&gt;
&lt;br /&gt;
Capability [[Capabilities/tool/certificate:viewallcertificates|&#039;tool/certificate:viewallcertificates&#039;]] can also be assigned in different contexts now. Similar to &#039;issue&#039; capability, users will only see other users from the same tenant (unless they have additional capabilities that allow them to view users in other tenants)&lt;br /&gt;
&lt;br /&gt;
The element type &amp;quot;Program&amp;quot; is now called &#039;&#039;&#039;&amp;quot;Dynamic rule data&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Setting limits for tenant-related data==&lt;br /&gt;
&lt;br /&gt;
It is possible for site administrators to limit the amount of data related to a tenant for certain features:&lt;br /&gt;
&lt;br /&gt;
* The number of [[Multi-tenancy|tenants]] can be restricted by setting &#039;$CFG-&amp;gt;tool_tenant_tenantlimit = &amp;lt;VALUE&amp;gt;;&#039; in your [[Configuration_file|site configuration]]&lt;br /&gt;
* The number of [[Report_builder#Creating_a_custom_report|custom reports]] can be restricted per site/tenant by setting &#039;$CFG-&amp;gt;tool_reportbuilder_sitelimit&#039; and &#039;$CFG-&amp;gt;tool_reportbuilder_tenantlimit&#039; respectively&lt;br /&gt;
* The number of [[Dynamic_rules#Creating_dynamic_rules|dynamic rules]] can be restricted per site/tenant by setting &#039;$CFG-&amp;gt;tool_dynamicrule_sitelimit&#039; and &#039;$CFG-&amp;gt;tool_dynamicrule_tenantlimit&#039; respectively&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139486</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139486"/>
		<updated>2021-01-28T22:25:07Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_get_export_file&lt;br /&gt;
* tool_wp_get_export_status&lt;br /&gt;
* tool_wp_get_import_status&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_export_file&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_export_status&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_import_status&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
First execute the web-service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; with the parameter &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt;, 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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;all\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because it is a dry-run, the &amp;lt;tt&amp;gt;id=0&amp;lt;/tt&amp;gt; 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 &#039;&#039;&#039;&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&#039;&#039;&#039; to the URL (to pass more settings use a different index). Consider html encoding settings parameter value, as depending on use, there might be issues when you pass it in request.&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; without the &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;positions\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command.&lt;br /&gt;
&lt;br /&gt;
=== Get status of export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_export_status&amp;lt;/tt&amp;gt; with id from previous example to retrieve the status of the export:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_get_export_status&amp;amp;exportid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_get_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To download the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from a previous Workplace export with id 19 add &amp;lt;tt&amp;gt;exportid=19&amp;lt;/tt&amp;gt; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &amp;lt;tt&amp;gt;file=123456678&amp;lt;/tt&amp;gt; . Similar to the export, you can use &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv&#039;&#039;&#039;. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note1: To demonstrate custom column mappings in this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the default mappings.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note2: File name is important. If you choose to create a new framework during the import (default behavior), the file name will become a framework name&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* &amp;lt;tt&amp;gt;tool_organisation\tool_wp\importer\positions_csv&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;tool_organisation\tool_wp\importer\departments_csv&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;lt;tt&amp;gt;ismanager&amp;lt;/tt&amp;gt; was not mapped because the importer expects it to be called &amp;lt;tt&amp;gt;globalmanager&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;manager&amp;lt;/tt&amp;gt;). We can correct the mapping by adding to the request: &amp;lt;tt&amp;gt;&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;: &amp;quot;ismanager&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;:&amp;quot;ismanager&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;ismanager\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
=== Get status of import ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_import_status&amp;lt;/tt&amp;gt; with id from scheduling import example to retrieve the status of the import:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_get_import_status&amp;amp;importid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139485</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139485"/>
		<updated>2021-01-28T16:51:00Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Retrieve export file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
* tool_wp_get_export_status&lt;br /&gt;
* tool_wp_get_import_status&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_export_status&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_import_status&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
First execute the web-service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; with the parameter &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt;, 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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;all\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because it is a dry-run, the &amp;lt;tt&amp;gt;id=0&amp;lt;/tt&amp;gt; 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 &#039;&#039;&#039;&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&#039;&#039;&#039; to the URL (to pass more settings use a different index). Consider html encoding settings parameter value, as depending on use, there might be issues when you pass it in request.&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; without the &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;positions\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command.&lt;br /&gt;
&lt;br /&gt;
=== Get status of export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_export_status&amp;lt;/tt&amp;gt; with id from previous example to retrieve the status of the export:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_get_export_status&amp;amp;exportid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To download the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from a previous Workplace export with id 19 add &amp;lt;tt&amp;gt;exportid=19&amp;lt;/tt&amp;gt; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &amp;lt;tt&amp;gt;file=123456678&amp;lt;/tt&amp;gt; . Similar to the export, you can use &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv&#039;&#039;&#039;. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note1: To demonstrate custom column mappings in this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the default mappings.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note2: File name is important. If you choose to create a new framework during the import (default behavior), the file name will become a framework name&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* &amp;lt;tt&amp;gt;tool_organisation\tool_wp\importer\positions_csv&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;tool_organisation\tool_wp\importer\departments_csv&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;lt;tt&amp;gt;ismanager&amp;lt;/tt&amp;gt; was not mapped because the importer expects it to be called &amp;lt;tt&amp;gt;globalmanager&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;manager&amp;lt;/tt&amp;gt;). We can correct the mapping by adding to the request: &amp;lt;tt&amp;gt;&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;: &amp;quot;ismanager&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;:&amp;quot;ismanager&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;ismanager\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
=== Get status of import ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_import_status&amp;lt;/tt&amp;gt; with id from scheduling import example to retrieve the status of the import:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_get_import_status&amp;amp;importid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139484</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139484"/>
		<updated>2021-01-28T16:49:05Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Get status of import */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
* tool_wp_get_export_status&lt;br /&gt;
* tool_wp_get_import_status&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_export_status&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_import_status&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
First execute the web-service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; with the parameter &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt;, 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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;all\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because it is a dry-run, the &amp;lt;tt&amp;gt;id=0&amp;lt;/tt&amp;gt; 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 &#039;&#039;&#039;&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&#039;&#039;&#039; to the URL (to pass more settings use a different index). Consider html encoding settings parameter value, as depending on use, there might be issues when you pass it in request.&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; without the &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;positions\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command.&lt;br /&gt;
&lt;br /&gt;
=== Get status of export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_export_status&amp;lt;/tt&amp;gt; with id from previous example to retrieve the status of the export:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_get_export_status&amp;amp;exportid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from a previous Workplace export with id 19 add &amp;lt;tt&amp;gt;exportid=19&amp;lt;/tt&amp;gt; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &amp;lt;tt&amp;gt;file=123456678&amp;lt;/tt&amp;gt; . Similar to the export, you can use &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv&#039;&#039;&#039;. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note1: To demonstrate custom column mappings in this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the default mappings.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note2: File name is important. If you choose to create a new framework during the import (default behavior), the file name will become a framework name&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* &amp;lt;tt&amp;gt;tool_organisation\tool_wp\importer\positions_csv&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;tool_organisation\tool_wp\importer\departments_csv&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;lt;tt&amp;gt;ismanager&amp;lt;/tt&amp;gt; was not mapped because the importer expects it to be called &amp;lt;tt&amp;gt;globalmanager&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;manager&amp;lt;/tt&amp;gt;). We can correct the mapping by adding to the request: &amp;lt;tt&amp;gt;&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;: &amp;quot;ismanager&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;:&amp;quot;ismanager&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;ismanager\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
=== Get status of import ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_import_status&amp;lt;/tt&amp;gt; with id from scheduling import example to retrieve the status of the import:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_get_import_status&amp;amp;importid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139483</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139483"/>
		<updated>2021-01-28T16:48:36Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Get status of export */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
* tool_wp_get_export_status&lt;br /&gt;
* tool_wp_get_import_status&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_export_status&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_import_status&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
First execute the web-service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; with the parameter &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt;, 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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;all\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because it is a dry-run, the &amp;lt;tt&amp;gt;id=0&amp;lt;/tt&amp;gt; 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 &#039;&#039;&#039;&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&#039;&#039;&#039; to the URL (to pass more settings use a different index). Consider html encoding settings parameter value, as depending on use, there might be issues when you pass it in request.&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; without the &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;positions\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command.&lt;br /&gt;
&lt;br /&gt;
=== Get status of export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_export_status&amp;lt;/tt&amp;gt; with id from previous example to retrieve the status of the export:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_get_export_status&amp;amp;exportid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from a previous Workplace export with id 19 add &amp;lt;tt&amp;gt;exportid=19&amp;lt;/tt&amp;gt; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &amp;lt;tt&amp;gt;file=123456678&amp;lt;/tt&amp;gt; . Similar to the export, you can use &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv&#039;&#039;&#039;. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note1: To demonstrate custom column mappings in this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the default mappings.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note2: File name is important. If you choose to create a new framework during the import (default behavior), the file name will become a framework name&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* &amp;lt;tt&amp;gt;tool_organisation\tool_wp\importer\positions_csv&amp;lt;/tt&amp;gt;&lt;br /&gt;
* &amp;lt;tt&amp;gt;tool_organisation\tool_wp\importer\departments_csv&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;lt;tt&amp;gt;ismanager&amp;lt;/tt&amp;gt; was not mapped because the importer expects it to be called &amp;lt;tt&amp;gt;globalmanager&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;manager&amp;lt;/tt&amp;gt;). We can correct the mapping by adding to the request: &amp;lt;tt&amp;gt;&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;: &amp;quot;ismanager&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;:&amp;quot;ismanager&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;ismanager\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
=== Get status of import ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_import_status&amp;lt;/tt&amp;gt; with id from scheduling import example to retrieve the status of the import:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; --data &#039;wsfunction=tool_wp_get_import_status&amp;amp;importid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139479</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139479"/>
		<updated>2021-01-28T15:00:00Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Get status of export */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
* tool_wp_get_export_status&lt;br /&gt;
* tool_wp_get_import_status&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_export_status&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_import_status&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
First execute the web-service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; with the parameter &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt;, 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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;all\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because it is a dry-run, the &amp;lt;tt&amp;gt;id=0&amp;lt;/tt&amp;gt; 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 &#039;&#039;&#039;&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&#039;&#039;&#039; to the URL (to pass more settings use a different index). Consider html encoding settings parameter value, as depending on use, there might be issues when you pass it in request.&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; without the &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;positions\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command.&lt;br /&gt;
&lt;br /&gt;
=== Get status of export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_export_status&amp;lt;/tt&amp;gt; with id from previous example to retrieve the status of the export:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; --data &#039;wsfunction=tool_wp_get_export_status&amp;amp;exportid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from a previous Workplace export with id 19 add &amp;lt;tt&amp;gt;exportid=19&amp;lt;/tt&amp;gt; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &amp;lt;tt&amp;gt;file=123456678&amp;lt;/tt&amp;gt; . Similar to the export, you can use &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv&#039;&#039;&#039;. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note1: To demonstrate custom column mappings in this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the default mappings.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note2: File name is important. If you choose to create a new framework during the import (default behavior), the file name will become a framework name&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;lt;tt&amp;gt;ismanager&amp;lt;/tt&amp;gt; was not mapped because the importer expects it to be called &amp;lt;tt&amp;gt;globalmanager&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;manager&amp;lt;/tt&amp;gt;). We can correct the mapping by adding to the request: &amp;lt;tt&amp;gt;&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;: &amp;quot;ismanager&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;: &amp;quot;ismanager&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;ismanager\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
=== Get status of import ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_import_status&amp;lt;/tt&amp;gt; with id from scheduling import example to retrieve the status of the import:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; --data &#039;wsfunction=tool_wp_get_import_status&amp;amp;importid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139478</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139478"/>
		<updated>2021-01-28T14:59:27Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Get status of import */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
* tool_wp_get_export_status&lt;br /&gt;
* tool_wp_get_import_status&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_export_status&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_get_import_status&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
First execute the web-service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; with the parameter &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt;, 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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;all\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because it is a dry-run, the &amp;lt;tt&amp;gt;id=0&amp;lt;/tt&amp;gt; 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 &#039;&#039;&#039;&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&#039;&#039;&#039; to the URL (to pass more settings use a different index). Consider html encoding settings parameter value, as depending on use, there might be issues when you pass it in request.&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; without the &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings={&amp;quot;export_instances&amp;quot;: &amp;quot;positions&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;export_instances\&amp;quot;:\&amp;quot;positions\&amp;quot;,\&amp;quot;select_frameworks\&amp;quot;:[]}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command.&lt;br /&gt;
&lt;br /&gt;
=== Get status of export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_export_status&amp;lt;/tt&amp;gt; with id from previous example to retrieve the status of the export:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;http://moodle.local/webservice/rest/server.php?moodlewsrestformat=json&#039; --data &#039;wsfunction=tool_wp_get_export_status&amp;amp;exportid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_export&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from a previous Workplace export with id 19 add &amp;lt;tt&amp;gt;exportid=19&amp;lt;/tt&amp;gt; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &amp;lt;tt&amp;gt;file=123456678&amp;lt;/tt&amp;gt; . Similar to the export, you can use &amp;lt;tt&amp;gt;dryrun=1&amp;lt;/tt&amp;gt; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv&#039;&#039;&#039;. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note1: To demonstrate custom column mappings in this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the default mappings.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note2: File name is important. If you choose to create a new framework during the import (default behavior), the file name will become a framework name&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;lt;tt&amp;gt;ismanager&amp;lt;/tt&amp;gt; was not mapped because the importer expects it to be called &amp;lt;tt&amp;gt;globalmanager&amp;lt;/tt&amp;gt; (or &amp;lt;tt&amp;gt;manager&amp;lt;/tt&amp;gt;). We can correct the mapping by adding to the request: &amp;lt;tt&amp;gt;&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;: &amp;quot;ismanager&amp;quot;}&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;settings={&amp;quot;csvmapping:globalmanager&amp;quot;: &amp;quot;ismanager&amp;quot;}&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: &amp;quot;{\&amp;quot;target_framework\&amp;quot;:\&amp;quot;new\&amp;quot;,\&amp;quot;hierarchy\&amp;quot;:\&amp;quot;selected\&amp;quot;,\&amp;quot;identifier\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:name\&amp;quot;:\&amp;quot;name\&amp;quot;,\&amp;quot;csvmapping:idnumber\&amp;quot;:\&amp;quot;idnumber\&amp;quot;,\&amp;quot;csvmapping:description\&amp;quot;:\&amp;quot;description\&amp;quot;,\&amp;quot;csvmapping:descriptionformat\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;csvdefault:descriptionformat\&amp;quot;:\&amp;quot;1\&amp;quot;,\&amp;quot;csvmapping:parentid\&amp;quot;:\&amp;quot;parent\&amp;quot;,\&amp;quot;csvmapping:globalmanager\&amp;quot;:\&amp;quot;ismanager\&amp;quot;,\&amp;quot;csvmapping:departmentmanager\&amp;quot;:\&amp;quot;\&amp;quot;,\&amp;quot;select_framework\&amp;quot;:null}&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the &amp;lt;tt&amp;gt;tool_wp_perform_import&amp;lt;/tt&amp;gt; web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;br /&gt;
&lt;br /&gt;
=== Get status of import ===&lt;br /&gt;
&lt;br /&gt;
Call the web service &amp;lt;tt&amp;gt;tool_wp_get_import_status&amp;lt;/tt&amp;gt; with id from scheduling import example to retrieve the status of the import:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; --data &#039;wsfunction=tool_wp_get_import_status&amp;amp;importid=72&amp;amp;wstoken=f1355062bead0eab2f3d101e54243e0d&#039; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;status&amp;quot;: 2,&lt;br /&gt;
  &amp;quot;statusstr&amp;quot;: &amp;quot;Scheduled&amp;quot;,&lt;br /&gt;
  &amp;quot;progress&amp;quot;: 0&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139356</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139356"/>
		<updated>2021-01-15T20:15:40Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Upload file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from a previous Workplace export with id 19 add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv&#039;&#039;&#039;. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note1: To demonstrate custom column mappings in this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the default mappings.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note2: File name is important. If you choose to create a new framework during the import (default behavior), the file name will become a framework name&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;manager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;quot;&#039;&#039;&#039;ismanager&#039;&#039;&#039;&amp;quot; was not mapped because the importer expects it to be called &#039;&#039;&#039;globalmanager&#039;&#039;&#039; (or &#039;&#039;&#039;manager&#039;&#039;&#039;). We can correct the mapping by adding to the request: settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager &lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the tool_wp_perform_import web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    ...&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;ismanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    ...&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139355</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139355"/>
		<updated>2021-01-15T20:15:29Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Import */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from a previous Workplace export with id 19 add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv&#039;&#039;&#039;. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note1: To demonstrate custom column mappings in this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the default mappings.&#039;&#039;&lt;br /&gt;
&#039;&#039;Note2: File name is important. If you choose to create a new framework during the import (default behavior), the file name will become a framework name&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;manager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;quot;&#039;&#039;&#039;ismanager&#039;&#039;&#039;&amp;quot; was not mapped because the importer expects it to be called &#039;&#039;&#039;globalmanager&#039;&#039;&#039; (or &#039;&#039;&#039;manager&#039;&#039;&#039;). We can correct the mapping by adding to the request: settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager &lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the tool_wp_perform_import web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    ...&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;ismanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    ...&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139354</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139354"/>
		<updated>2021-01-15T20:07:16Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Retrieving the import logs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv.&#039;&#039;&#039; It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note: For the purpose of this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the mapping.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;manager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;quot;&#039;&#039;&#039;ismanager&#039;&#039;&#039;&amp;quot; was not mapped because the importer expects it to be called &#039;&#039;&#039;globalmanager&#039;&#039;&#039; (or &#039;&#039;&#039;manager&#039;&#039;&#039;). We can correct the mapping by adding to the request: settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager &lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the tool_wp_perform_import web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    ...&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;ismanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    ...&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
[[File:wp_ws_import_log_example.png]]&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=File:wp_ws_import_log_example.png&amp;diff=139353</id>
		<title>File:wp ws import log example.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=File:wp_ws_import_log_example.png&amp;diff=139353"/>
		<updated>2021-01-15T20:06:16Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139352</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139352"/>
		<updated>2021-01-15T20:03:40Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Upload file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv.&#039;&#039;&#039; It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note: For the purpose of this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the mapping.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;manager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;quot;&#039;&#039;&#039;ismanager&#039;&#039;&#039;&amp;quot; was not mapped because the importer expects it to be called &#039;&#039;&#039;globalmanager&#039;&#039;&#039; (or &#039;&#039;&#039;manager&#039;&#039;&#039;). We can correct the mapping by adding to the request: settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager &lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the tool_wp_perform_import web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    ...&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;ismanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    ...&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139351</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139351"/>
		<updated>2021-01-15T20:03:22Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Upload file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file &#039;&#039;&#039;positions.csv.&#039;&#039;&#039; It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name &#039;&#039;&#039;positions.csv&#039;&#039;&#039; with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,&#039;&#039;&#039;ismanager&#039;&#039;&#039;&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note: For the purpose of this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the mapping.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;manager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;quot;&#039;&#039;&#039;ismanager&#039;&#039;&#039;&amp;quot; was not mapped because the importer expects it to be called &#039;&#039;&#039;globalmanager&#039;&#039;&#039; (or &#039;&#039;&#039;manager&#039;&#039;&#039;). We can correct the mapping by adding to the request: settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager &lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the tool_wp_perform_import web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    ...&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;ismanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    ...&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139350</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139350"/>
		<updated>2021-01-15T20:02:44Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Upload file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name positions.csv with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,ismanager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Note: For the purpose of this tutorial we called the last column &amp;quot;ismanager&amp;quot;. If you call it &amp;quot;manager&amp;quot; or &amp;quot;globalmanager&amp;quot; you will not need to change the mapping.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;manager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;quot;&#039;&#039;&#039;ismanager&#039;&#039;&#039;&amp;quot; was not mapped because the importer expects it to be called &#039;&#039;&#039;globalmanager&#039;&#039;&#039; (or &#039;&#039;&#039;manager&#039;&#039;&#039;). We can correct the mapping by adding to the request: settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager &lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the tool_wp_perform_import web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    ...&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;ismanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    ...&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139349</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139349"/>
		<updated>2021-01-15T20:00:37Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Scheduling import */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name positions.csv with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,manager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;manager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;quot;&#039;&#039;&#039;ismanager&#039;&#039;&#039;&amp;quot; was not mapped because the importer expects it to be called &#039;&#039;&#039;globalmanager&#039;&#039;&#039; (or &#039;&#039;&#039;manager&#039;&#039;&#039;). We can correct the mapping by adding to the request: settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager &lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the tool_wp_perform_import web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    ...&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;ismanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    ...&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The next cron run will execute this import.&lt;br /&gt;
&lt;br /&gt;
=== Retrieving the import logs ===&lt;br /&gt;
&lt;br /&gt;
Currently you can only see the import logs via the web interface. We will add a new web service for it soon.&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139348</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139348"/>
		<updated>2021-01-15T19:59:07Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Dry-run */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name positions.csv with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,manager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;manager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The mapping of columns in the CSV file is picked automatically in the most cases, however the column &amp;quot;&#039;&#039;&#039;ismanager&#039;&#039;&#039;&amp;quot; was not mapped because the importer expects it to be called &#039;&#039;&#039;globalmanager&#039;&#039;&#039; (or &#039;&#039;&#039;manager&#039;&#039;&#039;). We can correct the mapping by adding to the request: settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager &lt;br /&gt;
&lt;br /&gt;
=== Scheduling import ===&lt;br /&gt;
&lt;br /&gt;
Now we can execute the tool_wp_perform_import web service without dryrun parameter. The result will return the import id:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;settings[0][name]=csvmapping:globalmanager&amp;amp;settings[0][value]=ismanager&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 56,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    ...&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;ismanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    ...&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139347</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139347"/>
		<updated>2021-01-15T19:48:03Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Upload file */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
Imagine we have a file with the name positions.csv with the following contents:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
idnumber,parent,name,description,manager&lt;br /&gt;
CEO,,Chief Executive Officer,Chief Executive Officer position,1&lt;br /&gt;
COO,CEO,Chief Operating Officer,Chief Operating Officer position,1&lt;br /&gt;
HMD,COO,Head of Marketing and Design,Head of Marketing and Design position,1&lt;br /&gt;
MCO,HMD,Marketing Consultant,Marketing Consultant position,0&lt;br /&gt;
OM,COO,Office Manager,Office Manager position,0&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling], for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 \&lt;br /&gt;
| jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;globalmanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139346</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139346"/>
		<updated>2021-01-15T19:46:37Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Dry-run */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;target_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;new&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;hierarchy&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;selected&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;identifier&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:name&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;name&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:idnumber&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;idnumber&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:description&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;description&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvdefault:descriptionformat&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;1&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:parentid&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;parent&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:globalmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;globalmanager&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;csvmapping:departmentmanager&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_framework&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: null&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139345</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139345"/>
		<updated>2021-01-15T19:38:46Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
100   613  100   505  100   108   3686    788 --:--:-- --:--:-- --:--:--  4442&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Additional parameters ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has parameters:&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139344</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139344"/>
		<updated>2021-01-15T19:38:08Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Additional arguments ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_export web service has arguments&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the export should be made&lt;br /&gt;
* notenant (bool) - Perform export without the tenant (only for exporters that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants. &lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
100   613  100   505  100   108   3686    788 --:--:-- --:--:-- --:--:--  4442&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Additional arguments ===&lt;br /&gt;
&lt;br /&gt;
Additionally, the tool_wp_perform_import web service has arguments&lt;br /&gt;
* tenant (int|string) - Database ID or non-numeric idnumber of the tenant where the import should be made&lt;br /&gt;
* notenant (bool) - Perform import without the tenant (only for importers that support this).&lt;br /&gt;
&lt;br /&gt;
They can be used by global administrator or another user who has permission to switch between tenants.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139343</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139343"/>
		<updated>2021-01-15T19:31:02Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [https://docs.moodle.org/dev/Web_services_files_handling Web services files handling]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting &#039;&#039;&#039;$CFG-&amp;gt;enablewsdocumentation&#039;&#039;&#039; and navigate to &#039;&#039;&#039;Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
100   613  100   505  100   108   3686    788 --:--:-- --:--:-- --:--:--  4442&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139342</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139342"/>
		<updated>2021-01-15T19:29:41Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
The following web services are available in the Moodle Workplace for export and import:&lt;br /&gt;
* tool_wp_perform_export&lt;br /&gt;
* tool_wp_perform_import&lt;br /&gt;
* tool_wp_retrieve_export_file&lt;br /&gt;
&lt;br /&gt;
Standard Moodle LMS functionality is available for uploading a file, see [[Web services files handling]]&lt;br /&gt;
&lt;br /&gt;
To see the exact description of the parameters and return values of these web services in your version of Moodle Workplace, please turn on the admin setting $CFG-&amp;gt;enablewsdocumentation and navigate to Site administration &amp;gt; Plugins &amp;gt; Web services&amp;gt; API Documentation&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
100   613  100   505  100   108   3686    788 --:--:-- --:--:-- --:--:--  4442&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139341</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139341"/>
		<updated>2021-01-15T18:42:19Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Import */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
The web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039; is responsible for importing.&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
100   613  100   505  100   108   3686    788 --:--:-- --:--:-- --:--:--  4442&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139340</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139340"/>
		<updated>2021-01-15T18:40:22Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Dry-run */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
100   613  100   505  100   108   3686    788 --:--:-- --:--:-- --:--:--  4442&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
At the moment of writing this, there are two CSV importers in the Moodle Workplace distribution:&lt;br /&gt;
* tool_organisation\tool_wp\importer\positions_csv&lt;br /&gt;
* tool_organisation\tool_wp\importer\departments_csv&lt;br /&gt;
&lt;br /&gt;
More importers may be added later to the Moodle Workplace and also more importers may be implemented by the plugins.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s execute the same web service &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;  specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139339</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139339"/>
		<updated>2021-01-15T18:37:53Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Import */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
100   613  100   505  100   108   3686    788 --:--:-- --:--:-- --:--:--  4442&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (More than one importer is available, importer must be specified\nChoose from: tool_organisation\\tool_wp\\importer\\departments_csv, tool_organisation\\tool_wp\\importer\\positions_csv)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Execute the same web service specifying the positions importer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;http://localhost/workplace/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
&amp;gt; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=212744242&amp;amp;tenant=t6&amp;amp;importer=tool_organisation\tool_wp\importer\positions_csv&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
&amp;gt; | jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139337</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139337"/>
		<updated>2021-01-15T15:17:39Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Schedule export */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This call returned id 19, we will need it in the next command&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
# TODO....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139336</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139336"/>
		<updated>2021-01-15T14:49:59Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Dry-run */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
# TODO....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139335</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139335"/>
		<updated>2021-01-15T14:48:39Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Import */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;br /&gt;
&lt;br /&gt;
You can perform an import from an export file or upload a local file. To perform import from an export file add &#039;&#039;&#039;exportid=19&#039;&#039;&#039; to the parameters. To perform import from a file you need to first upload a file and then use a draft item id as an argument, for example &#039;&#039;&#039;file=123456678&#039;&#039;&#039; . Similar to the export, you can use &#039;&#039;&#039;dryrun=1&#039;&#039;&#039; parameter to validate parameters without actually scheduling import.&lt;br /&gt;
&lt;br /&gt;
=== Upload file ===&lt;br /&gt;
&lt;br /&gt;
In this example we upload a local file positions.csv. It will be placed in a draft area for the current user. The script returns itemid of the draft area. It can be used only by the same user and will be automatically deleted by Moodle after two days.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl -X POST -F &amp;quot;image=@positions.csv&amp;quot; https://SITENAME/webservice/upload.php?token=cf3788edbe41d7a89e963d9432b15331 | jq&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;component&amp;quot;: &amp;quot;user&amp;quot;,&lt;br /&gt;
    &amp;quot;contextid&amp;quot;: 567,&lt;br /&gt;
    &amp;quot;userid&amp;quot;: &amp;quot;123&amp;quot;,&lt;br /&gt;
    &amp;quot;filearea&amp;quot;: &amp;quot;draft&amp;quot;,&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;positions.csv&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;itemid&amp;quot;: 880413439,&lt;br /&gt;
    &amp;quot;license&amp;quot;: &amp;quot;allrightsreserved&amp;quot;,&lt;br /&gt;
    &amp;quot;author&amp;quot;: &amp;quot;User User&amp;quot;,&lt;br /&gt;
    &amp;quot;source&amp;quot;: &amp;quot;O:8:\&amp;quot;stdClass\&amp;quot;:1:{s:6:\&amp;quot;source\&amp;quot;;s:13:\&amp;quot;positions.csv\&amp;quot;;}&amp;quot;&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dry-run ===&lt;br /&gt;
&lt;br /&gt;
Example importing the export with id 19:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;exportid=19&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example importing the file that is located in the draft area with itemid 880413439. This is a CSV file and there are several available importers, therefore an error will be raised. The error message will contain the list of available importers:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; --data &#039;wsfunction=tool_wp_perform_import&amp;amp;file=880413439&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
# TODO....&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139334</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139334"/>
		<updated>2021-01-15T14:36:58Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Retrieve export file ===&lt;br /&gt;
&lt;br /&gt;
After the next cron run on the server you can retrieve the export file. If the cron has not run yet this command will return an error &amp;quot;Export not ready&amp;quot;. Successful return will look like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_retrieve_export_file&amp;amp;exportid=19&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
[&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;filename&amp;quot;: &amp;quot;organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;filepath&amp;quot;: &amp;quot;/&amp;quot;,&lt;br /&gt;
    &amp;quot;filesize&amp;quot;: 3396,&lt;br /&gt;
    &amp;quot;fileurl&amp;quot;: &amp;quot;https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip&amp;quot;,&lt;br /&gt;
    &amp;quot;timemodified&amp;quot;: 1610721298,&lt;br /&gt;
    &amp;quot;mimetype&amp;quot;: &amp;quot;application/zip&amp;quot;,&lt;br /&gt;
    &amp;quot;isexternalfile&amp;quot;: false&lt;br /&gt;
  }&lt;br /&gt;
]&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To retrieve the file you need to add your token to the fileurl:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl https://SITENAME/webservice/pluginfile.php/1/tool_wp/export/19/organisation-structure-frameworks-export-20210115-1534.zip?token=cf3788edbe41d7a89e963d9432b15331 &amp;gt; exportfile.zip&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Import ==&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139333</id>
		<title>Migration Web services</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Migration_Web_services&amp;diff=139333"/>
		<updated>2021-01-15T14:32:01Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Created page with &amp;quot;{{Workplace}}  == Overview == Web services for the Moodle Workplace Migrations feature.  == Set up ==  * Create a new service with the functions: &amp;#039;&amp;#039;&amp;#039;tool_wp_perform_export...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Web services for the Moodle Workplace [[Migrations]] feature.&lt;br /&gt;
&lt;br /&gt;
== Set up ==&lt;br /&gt;
&lt;br /&gt;
* Create a new service with the functions: &#039;&#039;&#039;tool_wp_perform_export&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_perform_import&#039;&#039;&#039;, &#039;&#039;&#039;tool_wp_retrieve_export_file&#039;&#039;&#039; or add these functions to the existing service&lt;br /&gt;
* Allow this service for everybody or for users who you want to be able to use them&lt;br /&gt;
* Create tokens for the users, enable protocols, add capabilities to use protocols&lt;br /&gt;
&lt;br /&gt;
See more information under [[Using web services]]&lt;br /&gt;
&lt;br /&gt;
== Export ==&lt;br /&gt;
&lt;br /&gt;
The following examples use command-line calls using the REST protocol. The output is piped through &#039;&#039;&#039;jq&#039;&#039;&#039; 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.&lt;br /&gt;
&lt;br /&gt;
=== Dry run ===&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=&amp;amp;dryrun=1&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;exception&amp;quot;: &amp;quot;invalid_parameter_exception&amp;quot;,&lt;br /&gt;
  &amp;quot;errorcode&amp;quot;: &amp;quot;invalidparameter&amp;quot;,&lt;br /&gt;
  &amp;quot;message&amp;quot;: &amp;quot;Invalid parameter value detected (Could not find exporter &#039;&#039;\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)&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now try again with the exporter name:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
$ curl &#039;https://SITENAME/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
    &amp;quot;id&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;settings&amp;quot;: [&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;all&amp;quot;&lt;br /&gt;
        },&lt;br /&gt;
        {&lt;br /&gt;
            &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
            &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
        }&lt;br /&gt;
    ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
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 &#039;&#039;&#039;&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&#039;&#039;&#039; to the URL (to pass more settings use a different index).&lt;br /&gt;
&lt;br /&gt;
=== Schedule export ===&lt;br /&gt;
&lt;br /&gt;
Call the web service tool_wp_perform_export without the dryrun=1 parameter. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
curl &#039;http://localhost/workplace/webservice/rest/server.php?moodlewsrestformat=json&#039; \&lt;br /&gt;
--data &#039;wsfunction=tool_wp_perform_export&amp;amp;exporter=tool_organisation\tool_wp\exporter\orgstructure&amp;amp;settings[0][name]=export_instances&amp;amp;settings[0][value]=positions&amp;amp;wstoken=cf3788edbe41d7a89e963d9432b15331&#039; \&lt;br /&gt;
| jq&lt;br /&gt;
&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;id&amp;quot;: 19,&lt;br /&gt;
  &amp;quot;settings&amp;quot;: [&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;export_instances&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;positions&amp;quot;&lt;br /&gt;
    },&lt;br /&gt;
    {&lt;br /&gt;
      &amp;quot;name&amp;quot;: &amp;quot;select_frameworks&amp;quot;,&lt;br /&gt;
      &amp;quot;value&amp;quot;: &amp;quot;&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=admin/tool/wp/export&amp;diff=139271</id>
		<title>admin/tool/wp/export</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=admin/tool/wp/export&amp;diff=139271"/>
		<updated>2021-01-11T10:40:03Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to Migrations&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Migrations]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=admin/tool/wp/import&amp;diff=139270</id>
		<title>admin/tool/wp/import</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=admin/tool/wp/import&amp;diff=139270"/>
		<updated>2021-01-11T10:39:26Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Redirected page to Migrations&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Migrations]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139197</id>
		<title>Programs</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139197"/>
		<updated>2020-12-23T14:19:40Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Programs are entities that contain a list of courses that are required to be completed by users. These courses can be grouped into a hierarchical structure and can be arranged in a specific order within the program. Some programs (or sets inside the program) may be configured so that learner needs to complete only several of the courses in order for the program (or set) to be considered completed, in this case learner can choose which courses to take. Learners allocated to the programs can see their current programs on their [[Learner dashboard|Learner dashboards]] and self-enrol into the program courses by clicking on them. Some program courses may not be available until the per-requisites are completed, in which case the appropriate message will be displayed.&lt;br /&gt;
&lt;br /&gt;
As a tenant administrator or Programs manager you can access the Programs tool by selecting Programs from the Workplace launcher.&lt;br /&gt;
&lt;br /&gt;
{{MediaPlayer | url = https://youtu.be/s_CMgdbnxP8 | desc = Moodle Workplace | Training | Programs}}&lt;br /&gt;
&lt;br /&gt;
== Programs list ==&lt;br /&gt;
This list shows all existing programs according to their &amp;quot;Active&amp;quot; or &amp;quot;Archived&amp;quot; status. Active programs are the ones we can modify and are available to users. Archived programs cannot be edited and are not available to users. Only archived programs can be deleted from the system but doing so we will lose related data in reports.&lt;br /&gt;
&lt;br /&gt;
On this page we can also duplicate a program, which includes all configuration and content but excludes user allocations.&lt;br /&gt;
&lt;br /&gt;
== Creating a new program ==&lt;br /&gt;
To create a new program press the &amp;quot;Add new program&amp;quot; button and choose a name and description for your program. In case you have previously created program custom fields they will appear at the end of this form. Once this step is complete, we can configure the program content and allocate users.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-new.png]]&lt;br /&gt;
&lt;br /&gt;
== Adding courses ==&lt;br /&gt;
Courses can be added to your program from the program &amp;quot;Content&amp;quot; tab. We can either add individual courses, or group them together in &amp;quot;sets&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* To add a course click the add button and select &amp;quot;Course&amp;quot;. You can select as many courses as you want.&lt;br /&gt;
* To add &amp;quot;sets&amp;quot; of courses click the add button and select &amp;quot;Set&amp;quot;. Give your set a name and select which courses you want to add to it. See the section on [[#Completion|completion]] below to define how the set should be completed by a user&lt;br /&gt;
&lt;br /&gt;
You can use drag-and-drop o re-order elements within the program in order to set a specific order.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-add-courses.png]]&lt;br /&gt;
&lt;br /&gt;
=== Completion ===&lt;br /&gt;
Each program, and course sets within it, can define how they should be considered as being completed by the user:&lt;br /&gt;
&lt;br /&gt;
* All in order - the user must complete all courses in the order specified&lt;br /&gt;
* All in any order - the user must complete all courses in no particular order&lt;br /&gt;
* At least X - the user must complete at least X number of the courses&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-set-completion.png]]&lt;br /&gt;
&lt;br /&gt;
== Schedule ==&lt;br /&gt;
Under the program &amp;quot;Schedule&amp;quot; tab, we can define the availability and allocation times for the program. The &amp;quot;Allocation window&amp;quot; defines when a user can be allocated to a program. The &amp;quot;Availability&amp;quot; section defines a start and end date during which time a user can access the program. The due date is the time by which the user should have completed the program. Each of the times can be set relative to another, for example a users start date could be considered to be immediately after their allocation date with a due date one month later.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-schedule.png]]&lt;br /&gt;
&lt;br /&gt;
== User allocation ==&lt;br /&gt;
Users can be manually allocated to a program from the &amp;quot;Users&amp;quot; tab. This page also lists all allocated users from other sources (such as via a Certification). For those users allocated to a program via a [[Certifications|certification]], the status of the certification is also shown.&lt;br /&gt;
&lt;br /&gt;
On this page we can also modify allocation dates (start date, due date and end date) individually for each user, suspend a user allocation and reset a user&#039;s program (caution: this will reset all program set/course completion for the user).&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-users.png]]&lt;br /&gt;
&lt;br /&gt;
== Dynamic rules ==&lt;br /&gt;
The [[Dynamic rules]] tab gives quick access to some rules which affect this program and are created by default. This will allow the site administrator to do things like sending a notification to the user when they&#039;re allocated to the program, issuing a certificate or a badge, granting a competency upon program completion, or sending a reminder when the program is overdue.  Set actions for these predefined rules and click the toggle button to activate them.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dynamicrules.png]]&lt;br /&gt;
&lt;br /&gt;
== User Dashboard ==&lt;br /&gt;
&lt;br /&gt;
When a user logs into Moodle Workplace and visits their [[Moodle_Workplace#Dashboard|Dashboard]] they will see all the active programs they have been allocated to, showing their completion status and allowing easy access to the courses contained within the program. User will have to complete courses in each set according to the completion criteria previously defined in the program content page.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dashboard.png]]wp-shared-program.png&lt;br /&gt;
&lt;br /&gt;
== Program reset ==&lt;br /&gt;
&lt;br /&gt;
A manager is able to reset a program for an individual user from the program users list. This will reset all courses that are part of this program. The users&#039; course completion data, individual assignments, grades and ratings will be reset. Data related to collaborative activities inside program courses will not be reset - this includes workshop, forum, assignment group submissions and collaborative wikis.&lt;br /&gt;
&lt;br /&gt;
A course reset report is also available from the [[Report builder]]. To generate it a manager just needs to go into the Report builder tool and create a new report using the “Course reset for individual user” report source.&lt;br /&gt;
&lt;br /&gt;
== Shared courses ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between tenants&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In the default Workplace installation users do not have the capability [[Capabilities/moodle/category:viewcourselist|moodle/category:viewcourselist]] outside of their tenant&#039;s category. This means that the Tenant administrator or Programs Manager will not see courses outside of their own tenant&#039;s course category when they add courses to the programs.&lt;br /&gt;
&lt;br /&gt;
However the site can be configured so that there is a &amp;quot;Shared&amp;quot; course category that overrides permissions and allows users to browse courses there, or a special user could be created who creates programs for different tenants and has access to all courses. In any case, it is possible to add the same course to different programs that belong to different tenants. &lt;br /&gt;
&lt;br /&gt;
A manager who manages the program will see the &amp;quot;attention&amp;quot; icon next to the courses that do not belong to the current tenant&#039;s course category. It is highly recommended to &#039;&#039;&#039;have all shared courses in &amp;quot;Separate groups&amp;quot; mode&#039;&#039;&#039; and force the group mode for all activities. &lt;br /&gt;
&lt;br /&gt;
The Programs enrolment method &#039;&#039;&#039;will always allocate users from different tenants into different groups&#039;&#039;&#039;. Groups will be created automatically based on the name of the tenant. They can be manually renamed later without affecting the allocation of future students. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between programs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Even within the same tenant, multiple programs may use the same course. By default users enrolled into the same course via different programs will &#039;&#039;&#039;not&#039;&#039;&#039; be in different groups, however it is possible to specify in Program settings that a group has to be created in each program course for the users allocated to the program. &lt;br /&gt;
&lt;br /&gt;
The same can be done for certifications. Each certification can have their own groups in the courses. For example, a new certification may be created for each cohort of students taking the same program and by separating them into groups the manager can ensure that they don&#039;t see forum posts or other activity from other cohorts.&lt;br /&gt;
&lt;br /&gt;
== Shared programs ==&lt;br /&gt;
After enabling [[Multi-tenancy#Shared_Space|Shared space]], users can create shared programs inside of it. These shared programs will be listed in Programs main page in all tenants and will be marked with a &amp;quot;Shared space&amp;quot; label next to it. Users from these tenants with no access to the Shared space will be only able to allocate users to these programs.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-shared-program.png]]&lt;br /&gt;
&lt;br /&gt;
=== Creating a new shared program ===&lt;br /&gt;
Access the Shared space from the tenant switch dropdown, in the navigation bar. When inside the Shared space go to Programs in the Workplace launcher and create a new program as usual.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139196</id>
		<title>Programs</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139196"/>
		<updated>2020-12-23T14:17:32Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Programs are entities that contain a list of courses that are required to be completed by users. These courses can be grouped into a hierarchical structure and can be arranged in a specific order within the program. Some programs (or sets inside the program) may be configured so that learner needs to complete only several of the courses in order for the program (or set) to be considered completed, in this case learner can choose which courses to take. Learners allocated to the programs can see their current programs on their [[Learner dashboard|Learner dashboards]] and self-enrol into the program courses by clicking on them. Some courses may not be available until the per-requisites are completed, in which case the appropriate message will be displayed.&lt;br /&gt;
&lt;br /&gt;
As a tenant administrator or Programs manager you can access the Programs tool by selecting Programs from the Workplace launcher.&lt;br /&gt;
&lt;br /&gt;
{{MediaPlayer | url = https://youtu.be/s_CMgdbnxP8 | desc = Moodle Workplace | Training | Programs}}&lt;br /&gt;
&lt;br /&gt;
== Programs list ==&lt;br /&gt;
This list shows all existing programs according to their &amp;quot;Active&amp;quot; or &amp;quot;Archived&amp;quot; status. Active programs are the ones we can modify and are available to users. Archived programs cannot be edited and are not available to users. Only archived programs can be deleted from the system but doing so we will lose related data in reports.&lt;br /&gt;
&lt;br /&gt;
On this page we can also duplicate a program, which includes all configuration and content but excludes user allocations.&lt;br /&gt;
&lt;br /&gt;
== Creating a new program ==&lt;br /&gt;
To create a new program press the &amp;quot;Add new program&amp;quot; button and choose a name and description for your program. In case you have previously created program custom fields they will appear at the end of this form. Once this step is complete, we can configure the program content and allocate users.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-new.png]]&lt;br /&gt;
&lt;br /&gt;
== Adding courses ==&lt;br /&gt;
Courses can be added to your program from the program &amp;quot;Content&amp;quot; tab. We can either add individual courses, or group them together in &amp;quot;sets&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* To add a course click the add button and select &amp;quot;Course&amp;quot;. You can select as many courses as you want.&lt;br /&gt;
* To add &amp;quot;sets&amp;quot; of courses click the add button and select &amp;quot;Set&amp;quot;. Give your set a name and select which courses you want to add to it. See the section on [[#Completion|completion]] below to define how the set should be completed by a user&lt;br /&gt;
&lt;br /&gt;
You can use drag-and-drop o re-order elements within the program in order to set a specific order.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-add-courses.png]]&lt;br /&gt;
&lt;br /&gt;
=== Completion ===&lt;br /&gt;
Each program, and course sets within it, can define how they should be considered as being completed by the user:&lt;br /&gt;
&lt;br /&gt;
* All in order - the user must complete all courses in the order specified&lt;br /&gt;
* All in any order - the user must complete all courses in no particular order&lt;br /&gt;
* At least X - the user must complete at least X number of the courses&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-set-completion.png]]&lt;br /&gt;
&lt;br /&gt;
== Schedule ==&lt;br /&gt;
Under the program &amp;quot;Schedule&amp;quot; tab, we can define the availability and allocation times for the program. The &amp;quot;Allocation window&amp;quot; defines when a user can be allocated to a program. The &amp;quot;Availability&amp;quot; section defines a start and end date during which time a user can access the program. The due date is the time by which the user should have completed the program. Each of the times can be set relative to another, for example a users start date could be considered to be immediately after their allocation date with a due date one month later.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-schedule.png]]&lt;br /&gt;
&lt;br /&gt;
== User allocation ==&lt;br /&gt;
Users can be manually allocated to a program from the &amp;quot;Users&amp;quot; tab. This page also lists all allocated users from other sources (such as via a Certification). For those users allocated to a program via a [[Certifications|certification]], the status of the certification is also shown.&lt;br /&gt;
&lt;br /&gt;
On this page we can also modify allocation dates (start date, due date and end date) individually for each user, suspend a user allocation and reset a user&#039;s program (caution: this will reset all program set/course completion for the user).&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-users.png]]&lt;br /&gt;
&lt;br /&gt;
== Dynamic rules ==&lt;br /&gt;
The [[Dynamic rules]] tab gives quick access to some rules which affect this program and are created by default. This will allow the site administrator to do things like sending a notification to the user when they&#039;re allocated to the program, issuing a certificate or a badge, granting a competency upon program completion, or sending a reminder when the program is overdue.  Set actions for these predefined rules and click the toggle button to activate them.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dynamicrules.png]]&lt;br /&gt;
&lt;br /&gt;
== User Dashboard ==&lt;br /&gt;
&lt;br /&gt;
When a user logs into Moodle Workplace and visits their [[Moodle_Workplace#Dashboard|Dashboard]] they will see all the active programs they have been allocated to, showing their completion status and allowing easy access to the courses contained within the program. User will have to complete courses in each set according to the completion criteria previously defined in the program content page.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dashboard.png]]wp-shared-program.png&lt;br /&gt;
&lt;br /&gt;
== Program reset ==&lt;br /&gt;
&lt;br /&gt;
A manager is able to reset a program for an individual user from the program users list. This will reset all courses that are part of this program. The users&#039; course completion data, individual assignments, grades and ratings will be reset. Data related to collaborative activities inside program courses will not be reset - this includes workshop, forum, assignment group submissions and collaborative wikis.&lt;br /&gt;
&lt;br /&gt;
A course reset report is also available from the [[Report builder]]. To generate it a manager just needs to go into the Report builder tool and create a new report using the “Course reset for individual user” report source.&lt;br /&gt;
&lt;br /&gt;
== Shared courses ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between tenants&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In the default Workplace installation users do not have the capability [[Capabilities/moodle/category:viewcourselist|moodle/category:viewcourselist]] outside of their tenant&#039;s category. This means that the Tenant administrator or Programs Manager will not see courses outside of their own tenant&#039;s course category when they add courses to the programs.&lt;br /&gt;
&lt;br /&gt;
However the site can be configured so that there is a &amp;quot;Shared&amp;quot; course category that overrides permissions and allows users to browse courses there, or a special user could be created who creates programs for different tenants and has access to all courses. In any case, it is possible to add the same course to different programs that belong to different tenants. &lt;br /&gt;
&lt;br /&gt;
A manager who manages the program will see the &amp;quot;attention&amp;quot; icon next to the courses that do not belong to the current tenant&#039;s course category. It is highly recommended to &#039;&#039;&#039;have all shared courses in &amp;quot;Separate groups&amp;quot; mode&#039;&#039;&#039; and force the group mode for all activities. &lt;br /&gt;
&lt;br /&gt;
The Programs enrolment method &#039;&#039;&#039;will always allocate users from different tenants into different groups&#039;&#039;&#039;. Groups will be created automatically based on the name of the tenant. They can be manually renamed later without affecting the allocation of future students. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between programs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Even within the same tenant, multiple programs may use the same course. By default users enrolled into the same course via different programs will &#039;&#039;&#039;not&#039;&#039;&#039; be in different groups, however it is possible to specify in Program settings that a group has to be created in each program course for the users allocated to the program. &lt;br /&gt;
&lt;br /&gt;
The same can be done for certifications. Each certification can have their own groups in the courses. For example, a new certification may be created for each cohort of students taking the same program and by separating them into groups the manager can ensure that they don&#039;t see forum posts or other activity from other cohorts.&lt;br /&gt;
&lt;br /&gt;
== Shared programs ==&lt;br /&gt;
After enabling [[Multi-tenancy#Shared_Space|Shared space]], users can create shared programs inside of it. These shared programs will be listed in Programs main page in all tenants and will be marked with a &amp;quot;Shared space&amp;quot; label next to it. Users from these tenants with no access to the Shared space will be only able to allocate users to these programs.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-shared-program.png]]&lt;br /&gt;
&lt;br /&gt;
=== Creating a new shared program ===&lt;br /&gt;
Access the Shared space from the tenant switch dropdown, in the navigation bar. When inside the Shared space go to Programs in the Workplace launcher and create a new program as usual.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139195</id>
		<title>Programs</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139195"/>
		<updated>2020-12-23T14:15:09Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Programs are entities that contain a list of courses that are required to be completed by users. These courses can be grouped into a hierarchical structure and can be arranged in a specific order within the program. Some programs (or sets inside the program) may be configured so that learner needs to complete only several of the courses in order for the program (or set) to be considered completed, in this case learner can choose which courses to take. Learners allocated to the programs &#039;&#039;&#039;can see their current programs on their dashboards&#039;&#039;&#039; and self-enrol into the program courses by clicking on them. Some courses may not be available until the per-requisites are completed, in which case the appropriate message will be displayed.&lt;br /&gt;
&lt;br /&gt;
As a tenant administrator or Programs manager you can access the Programs tool by selecting Programs from the Workplace launcher.&lt;br /&gt;
&lt;br /&gt;
{{MediaPlayer | url = https://youtu.be/s_CMgdbnxP8 | desc = Moodle Workplace | Training | Programs}}&lt;br /&gt;
&lt;br /&gt;
== Programs list ==&lt;br /&gt;
This list shows all existing programs according to their &amp;quot;Active&amp;quot; or &amp;quot;Archived&amp;quot; status. Active programs are the ones we can modify and are available to users. Archived programs cannot be edited and are not available to users. Only archived programs can be deleted from the system but doing so we will lose related data in reports.&lt;br /&gt;
&lt;br /&gt;
On this page we can also duplicate a program, which includes all configuration and content but excludes user allocations.&lt;br /&gt;
&lt;br /&gt;
== Creating a new program ==&lt;br /&gt;
To create a new program press the &amp;quot;Add new program&amp;quot; button and choose a name and description for your program. In case you have previously created program custom fields they will appear at the end of this form. Once this step is complete, we can configure the program content and allocate users.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-new.png]]&lt;br /&gt;
&lt;br /&gt;
== Adding courses ==&lt;br /&gt;
Courses can be added to your program from the program &amp;quot;Content&amp;quot; tab. We can either add individual courses, or group them together in &amp;quot;sets&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* To add a course click the add button and select &amp;quot;Course&amp;quot;. You can select as many courses as you want.&lt;br /&gt;
* To add &amp;quot;sets&amp;quot; of courses click the add button and select &amp;quot;Set&amp;quot;. Give your set a name and select which courses you want to add to it. See the section on [[#Completion|completion]] below to define how the set should be completed by a user&lt;br /&gt;
&lt;br /&gt;
You can use drag-and-drop o re-order elements within the program in order to set a specific order.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-add-courses.png]]&lt;br /&gt;
&lt;br /&gt;
=== Completion ===&lt;br /&gt;
Each program, and course sets within it, can define how they should be considered as being completed by the user:&lt;br /&gt;
&lt;br /&gt;
* All in order - the user must complete all courses in the order specified&lt;br /&gt;
* All in any order - the user must complete all courses in no particular order&lt;br /&gt;
* At least X - the user must complete at least X number of the courses&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-set-completion.png]]&lt;br /&gt;
&lt;br /&gt;
== Schedule ==&lt;br /&gt;
Under the program &amp;quot;Schedule&amp;quot; tab, we can define the availability and allocation times for the program. The &amp;quot;Allocation window&amp;quot; defines when a user can be allocated to a program. The &amp;quot;Availability&amp;quot; section defines a start and end date during which time a user can access the program. The due date is the time by which the user should have completed the program. Each of the times can be set relative to another, for example a users start date could be considered to be immediately after their allocation date with a due date one month later.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-schedule.png]]&lt;br /&gt;
&lt;br /&gt;
== User allocation ==&lt;br /&gt;
Users can be manually allocated to a program from the &amp;quot;Users&amp;quot; tab. This page also lists all allocated users from other sources (such as via a Certification). For those users allocated to a program via a [[Certifications|certification]], the status of the certification is also shown.&lt;br /&gt;
&lt;br /&gt;
On this page we can also modify allocation dates (start date, due date and end date) individually for each user, suspend a user allocation and reset a user&#039;s program (caution: this will reset all program set/course completion for the user).&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-users.png]]&lt;br /&gt;
&lt;br /&gt;
== Dynamic rules ==&lt;br /&gt;
The [[Dynamic rules]] tab gives quick access to some rules which affect this program and are created by default. This will allow the site administrator to do things like sending a notification to the user when they&#039;re allocated to the program, issuing a certificate or a badge, granting a competency upon program completion, or sending a reminder when the program is overdue.  Set actions for these predefined rules and click the toggle button to activate them.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dynamicrules.png]]&lt;br /&gt;
&lt;br /&gt;
== User Dashboard ==&lt;br /&gt;
&lt;br /&gt;
When a user logs into Moodle Workplace and visits their [[Moodle_Workplace#Dashboard|Dashboard]] they will see all the active programs they have been allocated to, showing their completion status and allowing easy access to the courses contained within the program. User will have to complete courses in each set according to the completion criteria previously defined in the program content page.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dashboard.png]]wp-shared-program.png&lt;br /&gt;
&lt;br /&gt;
== Program reset ==&lt;br /&gt;
&lt;br /&gt;
A manager is able to reset a program for an individual user from the program users list. This will reset all courses that are part of this program. The users&#039; course completion data, individual assignments, grades and ratings will be reset. Data related to collaborative activities inside program courses will not be reset - this includes workshop, forum, assignment group submissions and collaborative wikis.&lt;br /&gt;
&lt;br /&gt;
A course reset report is also available from the [[Report builder]]. To generate it a manager just needs to go into the Report builder tool and create a new report using the “Course reset for individual user” report source.&lt;br /&gt;
&lt;br /&gt;
== Shared courses ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between tenants&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In the default Workplace installation users do not have the capability [[Capabilities/moodle/category:viewcourselist|moodle/category:viewcourselist]] outside of their tenant&#039;s category. This means that the Tenant administrator or Programs Manager will not see courses outside of their own tenant&#039;s course category when they add courses to the programs.&lt;br /&gt;
&lt;br /&gt;
However the site can be configured so that there is a &amp;quot;Shared&amp;quot; course category that overrides permissions and allows users to browse courses there, or a special user could be created who creates programs for different tenants and has access to all courses. In any case, it is possible to add the same course to different programs that belong to different tenants. &lt;br /&gt;
&lt;br /&gt;
A manager who manages the program will see the &amp;quot;attention&amp;quot; icon next to the courses that do not belong to the current tenant&#039;s course category. It is highly recommended to &#039;&#039;&#039;have all shared courses in &amp;quot;Separate groups&amp;quot; mode&#039;&#039;&#039; and force the group mode for all activities. &lt;br /&gt;
&lt;br /&gt;
The Programs enrolment method &#039;&#039;&#039;will always allocate users from different tenants into different groups&#039;&#039;&#039;. Groups will be created automatically based on the name of the tenant. They can be manually renamed later without affecting the allocation of future students. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between programs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Even within the same tenant, multiple programs may use the same course. By default users enrolled into the same course via different programs will &#039;&#039;&#039;not&#039;&#039;&#039; be in different groups, however it is possible to specify in Program settings that a group has to be created in each program course for the users allocated to the program. &lt;br /&gt;
&lt;br /&gt;
The same can be done for certifications. Each certification can have their own groups in the courses. For example, a new certification may be created for each cohort of students taking the same program and by separating them into groups the manager can ensure that they don&#039;t see forum posts or other activity from other cohorts.&lt;br /&gt;
&lt;br /&gt;
== Shared programs ==&lt;br /&gt;
After enabling [[Multi-tenancy#Shared_Space|Shared space]], users can create shared programs inside of it. These shared programs will be listed in Programs main page in all tenants and will be marked with a &amp;quot;Shared space&amp;quot; label next to it. Users from these tenants with no access to the Shared space will be only able to allocate users to these programs.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-shared-program.png]]&lt;br /&gt;
&lt;br /&gt;
=== Creating a new shared program ===&lt;br /&gt;
Access the Shared space from the tenant switch dropdown, in the navigation bar. When inside the Shared space go to Programs in the Workplace launcher and create a new program as usual.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139194</id>
		<title>Programs</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139194"/>
		<updated>2020-12-23T14:12:28Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Programs are entities that contain a list of courses that are required to be completed by users. These courses can be grouped into a hierarchical structure and can be arranged in a specific order within the program. Some programs (or sets inside the program) may be configured so that learner needs to complete only several of the courses in order for the program (or set) to be considered completed, in this case learner can choose which courses to take. Learners allocated to the programs can see their current programs on their dashboards and self-enrol into the program courses by clicking on them (after they have completed per-requisites).&lt;br /&gt;
&lt;br /&gt;
As a tenant administrator or Programs manager you can access the Programs tool by selecting Programs from the Workplace launcher.&lt;br /&gt;
&lt;br /&gt;
{{MediaPlayer | url = https://youtu.be/s_CMgdbnxP8 | desc = Moodle Workplace | Training | Programs}}&lt;br /&gt;
&lt;br /&gt;
== Programs list ==&lt;br /&gt;
This list shows all existing programs according to their &amp;quot;Active&amp;quot; or &amp;quot;Archived&amp;quot; status. Active programs are the ones we can modify and are available to users. Archived programs cannot be edited and are not available to users. Only archived programs can be deleted from the system but doing so we will lose related data in reports.&lt;br /&gt;
&lt;br /&gt;
On this page we can also duplicate a program, which includes all configuration and content but excludes user allocations.&lt;br /&gt;
&lt;br /&gt;
== Creating a new program ==&lt;br /&gt;
To create a new program press the &amp;quot;Add new program&amp;quot; button and choose a name and description for your program. In case you have previously created program custom fields they will appear at the end of this form. Once this step is complete, we can configure the program content and allocate users.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-new.png]]&lt;br /&gt;
&lt;br /&gt;
== Adding courses ==&lt;br /&gt;
Courses can be added to your program from the program &amp;quot;Content&amp;quot; tab. We can either add individual courses, or group them together in &amp;quot;sets&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* To add a course click the add button and select &amp;quot;Course&amp;quot;. You can select as many courses as you want.&lt;br /&gt;
* To add &amp;quot;sets&amp;quot; of courses click the add button and select &amp;quot;Set&amp;quot;. Give your set a name and select which courses you want to add to it. See the section on [[#Completion|completion]] below to define how the set should be completed by a user&lt;br /&gt;
&lt;br /&gt;
You can use drag-and-drop o re-order elements within the program in order to set a specific order.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-add-courses.png]]&lt;br /&gt;
&lt;br /&gt;
=== Completion ===&lt;br /&gt;
Each program, and course sets within it, can define how they should be considered as being completed by the user:&lt;br /&gt;
&lt;br /&gt;
* All in order - the user must complete all courses in the order specified&lt;br /&gt;
* All in any order - the user must complete all courses in no particular order&lt;br /&gt;
* At least X - the user must complete at least X number of the courses&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-set-completion.png]]&lt;br /&gt;
&lt;br /&gt;
== Schedule ==&lt;br /&gt;
Under the program &amp;quot;Schedule&amp;quot; tab, we can define the availability and allocation times for the program. The &amp;quot;Allocation window&amp;quot; defines when a user can be allocated to a program. The &amp;quot;Availability&amp;quot; section defines a start and end date during which time a user can access the program. The due date is the time by which the user should have completed the program. Each of the times can be set relative to another, for example a users start date could be considered to be immediately after their allocation date with a due date one month later.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-schedule.png]]&lt;br /&gt;
&lt;br /&gt;
== User allocation ==&lt;br /&gt;
Users can be manually allocated to a program from the &amp;quot;Users&amp;quot; tab. This page also lists all allocated users from other sources (such as via a Certification). For those users allocated to a program via a [[Certifications|certification]], the status of the certification is also shown.&lt;br /&gt;
&lt;br /&gt;
On this page we can also modify allocation dates (start date, due date and end date) individually for each user, suspend a user allocation and reset a user&#039;s program (caution: this will reset all program set/course completion for the user).&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-users.png]]&lt;br /&gt;
&lt;br /&gt;
== Dynamic rules ==&lt;br /&gt;
The [[Dynamic rules]] tab gives quick access to some rules which affect this program and are created by default. This will allow the site administrator to do things like sending a notification to the user when they&#039;re allocated to the program, issuing a certificate or a badge, granting a competency upon program completion, or sending a reminder when the program is overdue.  Set actions for these predefined rules and click the toggle button to activate them.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dynamicrules.png]]&lt;br /&gt;
&lt;br /&gt;
== User Dashboard ==&lt;br /&gt;
&lt;br /&gt;
When a user logs into Moodle Workplace and visits their [[Moodle_Workplace#Dashboard|Dashboard]] they will see all the active programs they have been allocated to, showing their completion status and allowing easy access to the courses contained within the program. User will have to complete courses in each set according to the completion criteria previously defined in the program content page.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dashboard.png]]wp-shared-program.png&lt;br /&gt;
&lt;br /&gt;
== Program reset ==&lt;br /&gt;
&lt;br /&gt;
A manager is able to reset a program for an individual user from the program users list. This will reset all courses that are part of this program. The users&#039; course completion data, individual assignments, grades and ratings will be reset. Data related to collaborative activities inside program courses will not be reset - this includes workshop, forum, assignment group submissions and collaborative wikis.&lt;br /&gt;
&lt;br /&gt;
A course reset report is also available from the [[Report builder]]. To generate it a manager just needs to go into the Report builder tool and create a new report using the “Course reset for individual user” report source.&lt;br /&gt;
&lt;br /&gt;
== Shared courses ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between tenants&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In the default Workplace installation users do not have the capability [[Capabilities/moodle/category:viewcourselist|moodle/category:viewcourselist]] outside of their tenant&#039;s category. This means that the Tenant administrator or Programs Manager will not see courses outside of their own tenant&#039;s course category when they add courses to the programs.&lt;br /&gt;
&lt;br /&gt;
However the site can be configured so that there is a &amp;quot;Shared&amp;quot; course category that overrides permissions and allows users to browse courses there, or a special user could be created who creates programs for different tenants and has access to all courses. In any case, it is possible to add the same course to different programs that belong to different tenants. &lt;br /&gt;
&lt;br /&gt;
A manager who manages the program will see the &amp;quot;attention&amp;quot; icon next to the courses that do not belong to the current tenant&#039;s course category. It is highly recommended to &#039;&#039;&#039;have all shared courses in &amp;quot;Separate groups&amp;quot; mode&#039;&#039;&#039; and force the group mode for all activities. &lt;br /&gt;
&lt;br /&gt;
The Programs enrolment method &#039;&#039;&#039;will always allocate users from different tenants into different groups&#039;&#039;&#039;. Groups will be created automatically based on the name of the tenant. They can be manually renamed later without affecting the allocation of future students. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between programs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Even within the same tenant, multiple programs may use the same course. By default users enrolled into the same course via different programs will &#039;&#039;&#039;not&#039;&#039;&#039; be in different groups, however it is possible to specify in Program settings that a group has to be created in each program course for the users allocated to the program. &lt;br /&gt;
&lt;br /&gt;
The same can be done for certifications. Each certification can have their own groups in the courses. For example, a new certification may be created for each cohort of students taking the same program and by separating them into groups the manager can ensure that they don&#039;t see forum posts or other activity from other cohorts.&lt;br /&gt;
&lt;br /&gt;
== Shared programs ==&lt;br /&gt;
After enabling [[Multi-tenancy#Shared_Space|Shared space]], users can create shared programs inside of it. These shared programs will be listed in Programs main page in all tenants and will be marked with a &amp;quot;Shared space&amp;quot; label next to it. Users from these tenants with no access to the Shared space will be only able to allocate users to these programs.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-shared-program.png]]&lt;br /&gt;
&lt;br /&gt;
=== Creating a new shared program ===&lt;br /&gt;
Access the Shared space from the tenant switch dropdown, in the navigation bar. When inside the Shared space go to Programs in the Workplace launcher and create a new program as usual.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139193</id>
		<title>Programs</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Programs&amp;diff=139193"/>
		<updated>2020-12-23T14:09:33Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
== Overview ==&lt;br /&gt;
Programs are entities that contain a list of courses that are required to be completed by users. These courses can be grouped into a hierarchical structure and can be arranged in a specific order within the program. Some programs (or sets inside the program) may be configured so that learner needs to complete only several of the courses in order for the program (or set) to be considered completed, in this case learner can choose which courses to take. Learners allocated to the programs can see their current programs on their dashboards and self-enrol into the program courses by clicking on them (after they have completed per-requisites).&lt;br /&gt;
&lt;br /&gt;
To access the Programs tool, select Programs from the Workplace launcher.&lt;br /&gt;
&lt;br /&gt;
{{MediaPlayer | url = https://youtu.be/s_CMgdbnxP8 | desc = Moodle Workplace | Training | Programs}}&lt;br /&gt;
&lt;br /&gt;
== Programs list ==&lt;br /&gt;
This list shows all existing programs according to their &amp;quot;Active&amp;quot; or &amp;quot;Archived&amp;quot; status. Active programs are the ones we can modify and are available to users. Archived programs cannot be edited and are not available to users. Only archived programs can be deleted from the system but doing so we will lose related data in reports.&lt;br /&gt;
&lt;br /&gt;
On this page we can also duplicate a program, which includes all configuration and content but excludes user allocations.&lt;br /&gt;
&lt;br /&gt;
== Creating a new program ==&lt;br /&gt;
To create a new program press the &amp;quot;Add new program&amp;quot; button and choose a name and description for your program. In case you have previously created program custom fields they will appear at the end of this form. Once this step is complete, we can configure the program content and allocate users.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-new.png]]&lt;br /&gt;
&lt;br /&gt;
== Adding courses ==&lt;br /&gt;
Courses can be added to your program from the program &amp;quot;Content&amp;quot; tab. We can either add individual courses, or group them together in &amp;quot;sets&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
* To add a course click the add button and select &amp;quot;Course&amp;quot;. You can select as many courses as you want.&lt;br /&gt;
* To add &amp;quot;sets&amp;quot; of courses click the add button and select &amp;quot;Set&amp;quot;. Give your set a name and select which courses you want to add to it. See the section on [[#Completion|completion]] below to define how the set should be completed by a user&lt;br /&gt;
&lt;br /&gt;
You can use drag-and-drop o re-order elements within the program in order to set a specific order.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-add-courses.png]]&lt;br /&gt;
&lt;br /&gt;
=== Completion ===&lt;br /&gt;
Each program, and course sets within it, can define how they should be considered as being completed by the user:&lt;br /&gt;
&lt;br /&gt;
* All in order - the user must complete all courses in the order specified&lt;br /&gt;
* All in any order - the user must complete all courses in no particular order&lt;br /&gt;
* At least X - the user must complete at least X number of the courses&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-set-completion.png]]&lt;br /&gt;
&lt;br /&gt;
== Schedule ==&lt;br /&gt;
Under the program &amp;quot;Schedule&amp;quot; tab, we can define the availability and allocation times for the program. The &amp;quot;Allocation window&amp;quot; defines when a user can be allocated to a program. The &amp;quot;Availability&amp;quot; section defines a start and end date during which time a user can access the program. The due date is the time by which the user should have completed the program. Each of the times can be set relative to another, for example a users start date could be considered to be immediately after their allocation date with a due date one month later.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-schedule.png]]&lt;br /&gt;
&lt;br /&gt;
== User allocation ==&lt;br /&gt;
Users can be manually allocated to a program from the &amp;quot;Users&amp;quot; tab. This page also lists all allocated users from other sources (such as via a Certification). For those users allocated to a program via a [[Certifications|certification]], the status of the certification is also shown.&lt;br /&gt;
&lt;br /&gt;
On this page we can also modify allocation dates (start date, due date and end date) individually for each user, suspend a user allocation and reset a user&#039;s program (caution: this will reset all program set/course completion for the user).&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-users.png]]&lt;br /&gt;
&lt;br /&gt;
== Dynamic rules ==&lt;br /&gt;
The [[Dynamic rules]] tab gives quick access to some rules which affect this program and are created by default. This will allow the site administrator to do things like sending a notification to the user when they&#039;re allocated to the program, issuing a certificate or a badge, granting a competency upon program completion, or sending a reminder when the program is overdue.  Set actions for these predefined rules and click the toggle button to activate them.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dynamicrules.png]]&lt;br /&gt;
&lt;br /&gt;
== User Dashboard ==&lt;br /&gt;
&lt;br /&gt;
When a user logs into Moodle Workplace and visits their [[Moodle_Workplace#Dashboard|Dashboard]] they will see all the active programs they have been allocated to, showing their completion status and allowing easy access to the courses contained within the program. User will have to complete courses in each set according to the completion criteria previously defined in the program content page.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-pr-dashboard.png]]wp-shared-program.png&lt;br /&gt;
&lt;br /&gt;
== Program reset ==&lt;br /&gt;
&lt;br /&gt;
A manager is able to reset a program for an individual user from the program users list. This will reset all courses that are part of this program. The users&#039; course completion data, individual assignments, grades and ratings will be reset. Data related to collaborative activities inside program courses will not be reset - this includes workshop, forum, assignment group submissions and collaborative wikis.&lt;br /&gt;
&lt;br /&gt;
A course reset report is also available from the [[Report builder]]. To generate it a manager just needs to go into the Report builder tool and create a new report using the “Course reset for individual user” report source.&lt;br /&gt;
&lt;br /&gt;
== Shared courses ==&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between tenants&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In the default Workplace installation users do not have the capability [[Capabilities/moodle/category:viewcourselist|moodle/category:viewcourselist]] outside of their tenant&#039;s category. This means that the Tenant administrator or Programs Manager will not see courses outside of their own tenant&#039;s course category when they add courses to the programs.&lt;br /&gt;
&lt;br /&gt;
However the site can be configured so that there is a &amp;quot;Shared&amp;quot; course category that overrides permissions and allows users to browse courses there, or a special user could be created who creates programs for different tenants and has access to all courses. In any case, it is possible to add the same course to different programs that belong to different tenants. &lt;br /&gt;
&lt;br /&gt;
A manager who manages the program will see the &amp;quot;attention&amp;quot; icon next to the courses that do not belong to the current tenant&#039;s course category. It is highly recommended to &#039;&#039;&#039;have all shared courses in &amp;quot;Separate groups&amp;quot; mode&#039;&#039;&#039; and force the group mode for all activities. &lt;br /&gt;
&lt;br /&gt;
The Programs enrolment method &#039;&#039;&#039;will always allocate users from different tenants into different groups&#039;&#039;&#039;. Groups will be created automatically based on the name of the tenant. They can be manually renamed later without affecting the allocation of future students. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Sharing courses between programs&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Even within the same tenant, multiple programs may use the same course. By default users enrolled into the same course via different programs will &#039;&#039;&#039;not&#039;&#039;&#039; be in different groups, however it is possible to specify in Program settings that a group has to be created in each program course for the users allocated to the program. &lt;br /&gt;
&lt;br /&gt;
The same can be done for certifications. Each certification can have their own groups in the courses. For example, a new certification may be created for each cohort of students taking the same program and by separating them into groups the manager can ensure that they don&#039;t see forum posts or other activity from other cohorts.&lt;br /&gt;
&lt;br /&gt;
== Shared programs ==&lt;br /&gt;
After enabling [[Multi-tenancy#Shared_Space|Shared space]], users can create shared programs inside of it. These shared programs will be listed in Programs main page in all tenants and will be marked with a &amp;quot;Shared space&amp;quot; label next to it. Users from these tenants with no access to the Shared space will be only able to allocate users to these programs.&lt;br /&gt;
&lt;br /&gt;
[[File:wp-shared-program.png]]&lt;br /&gt;
&lt;br /&gt;
=== Creating a new shared program ===&lt;br /&gt;
Access the Shared space from the tenant switch dropdown, in the navigation bar. When inside the Shared space go to Programs in the Workplace launcher and create a new program as usual.&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Multi-tenancy&amp;diff=139148</id>
		<title>Multi-tenancy</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Multi-tenancy&amp;diff=139148"/>
		<updated>2020-12-03T11:01:16Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Tenant administration */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
= Overview =&lt;br /&gt;
&lt;br /&gt;
Moodle Workplace allows the main administrator to create multiple &amp;quot;tenants&amp;quot; and allocate users to each of them. Tenant users will all be using the same site but will not see each other. Each tenant can have their own site name, logo and colour scheme.&lt;br /&gt;
&lt;br /&gt;
{{MediaPlayer | url = https://youtu.be/JbJwSzHSJKk | desc = Moodle Workplace | Training | Multi Tenancy}}&lt;br /&gt;
&lt;br /&gt;
When Moodle Workplace is installed, the site is prepared to be multi-tenant. The capability &#039;moodle/category:viewcourselist&#039; is removed from the roles &amp;quot;Authenticated user&amp;quot; and &amp;quot;Guest&amp;quot;. If you don&#039;t want to use Multitenancy functionality, you may consider allowing these capabilities.&lt;br /&gt;
&lt;br /&gt;
= Managing tenants =&lt;br /&gt;
&lt;br /&gt;
The main administrator or a user with the capability &#039;[[Capabilities/tool/tenant:manage|tool/tenant:manage]]&#039; is able to create tenants, change their settings, associate tenants with course categories and assign tenant administrators. Three additional roles are automatically created when Moodle Workplace is installed, automatically assigned to the following users:&lt;br /&gt;
&lt;br /&gt;
* &amp;quot;[[Tenant administrator role|Tenant administrator]]&amp;quot; role is assigned to the tenant administrator in the system context&lt;br /&gt;
* &amp;quot;[[Tenant administrator in course category role|Tenant administrator in course category]]&amp;quot; role is assigned to the tenant administrator in the context of this tenant&#039;s course category&lt;br /&gt;
* &amp;quot;[[Tenant user role|Tenant user]]&amp;quot; role is assigned to any user allocated to the tenant in the context of this tenant&#039;s course category. By default this role only has the capability &#039;moodle/category:viewcourselist&#039;&lt;br /&gt;
&lt;br /&gt;
These roles and role assignments can not be manually deleted, nor can a site administrator manually assign these roles to users. However the main administrator can modify the roles if necessary. For example, the &amp;quot;Tenant administrator&amp;quot; role by default contains the capability &#039;[[Capabilities/tool/tenant:managetheme|tool/tenant:managetheme]]&#039; that allows the tenant administrator to change the look of their tenant (logo and colours). The main administrator may decide that theme customisation should only be done centrally and prohibit this capability in the &amp;quot;Tenant administrator&amp;quot; role. The same can be done for the &#039;[[Capabilities/tool/tenant:manageusers|tool/tenant:manageusers]]&#039; capability.&lt;br /&gt;
&lt;br /&gt;
The main administrator or a user with the capability &#039;[[Capabilities/tool/tenant:allocate|tool/tenant:allocate]]&#039; is able to move users between tenants.&lt;br /&gt;
&lt;br /&gt;
== Limiting number of tenants ==&lt;br /&gt;
&lt;br /&gt;
A site administrator can restrict the number of tenants that can be created on the site from &amp;quot;Site administration &amp;gt; Advanced features &amp;gt; Enable tenant limit&amp;quot;. Enabling this setting and configuring &amp;quot;Tenant limit&amp;quot; to a specific value will prevent more than this number of tenants from being created. Note that archived tenants are also counted towards this limit. It&#039;s also possible to add the following lines to your [[Configuration_file|site configuration]] to hardcode this configuration:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$CFG-&amp;gt;tool_tenant_tenantlimitenabled = true;&lt;br /&gt;
$CFG-&amp;gt;tool_tenant_tenantlimit = &amp;lt;VALUE&amp;gt;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Tenant administration =&lt;br /&gt;
&lt;br /&gt;
The [[Tenant administrator role]] by default has the capability &#039;[[Capabilities/tool/tenant:manageusers|tool/tenant:manageusers]]&#039;. Unless this capability is removed from the role by the main administrator, the tenant administrator can create and edit users inside their tenant. &lt;br /&gt;
&lt;br /&gt;
The tenant administrator can assign other roles to their users, for example &amp;quot;Program manager&amp;quot; or &amp;quot;Organisation structure manager&amp;quot; in the system context.&lt;br /&gt;
&lt;br /&gt;
If the tenant has its own course category, the  tenant administrator also has a role &amp;quot;[[Tenant administrator in course category role|Tenant administrator in course category]]&amp;quot; in this course category and is able to assign roles in the context of this course category, for example &amp;quot;Course creator&amp;quot;. For easier management there is a single page that lists all the roles that the tenant administrator can assign in both system and category context. It can be accessed through &#039;&#039;&#039;Workplace launcher -&amp;gt; Users -&amp;gt; Roles&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:workplace_rolesmanagement.png|thumb|600px|center|Managing roles for tenant administrator]]&lt;br /&gt;
&lt;br /&gt;
The tenant administrator is also able to manage their course category and all courses in it. Access to the course management is done through &#039;&#039;&#039;Workplace launcher -&amp;gt; Courses&#039;&#039;&#039;.  Hint: check out the &amp;quot;Edit&amp;quot; menu for the course category.&lt;br /&gt;
&lt;br /&gt;
[[File:workplace_categorymanagement.png|thumb|600px|center|Category management]]&lt;br /&gt;
&lt;br /&gt;
= Authentication =&lt;br /&gt;
&lt;br /&gt;
The [[Tenant administrator role]] by default has the capability &#039;[[Capabilities/tool/tenant:authconfig|tool/tenant:authconfig]]&#039;. Unless this capability is removed from the role by the main administrator, the tenant administrator can manage authentication settings in their tenant. (See also [[Moodle_Workplace_Release_notes#Upgrade_notes_for_3.10|Upgrade notes for 3.10]])&lt;br /&gt;
&lt;br /&gt;
Now it’s possible to set different authentication configurations for each tenant in a Workplace site, including the availability of plugins or changing the settings for the same plugin in different tenants.&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;ul class=&amp;quot;thumbnails&amp;quot;&amp;gt;     &lt;br /&gt;
      &amp;lt;li class=&amp;quot;span6&amp;quot;&amp;gt;      &lt;br /&gt;
        &amp;lt;div class=&amp;quot;thumbnail&amp;quot;&amp;gt;     &lt;br /&gt;
[[File:Per-tenant authentication plugins - 01.png|600px]]&lt;br /&gt;
          &amp;lt;div class=&amp;quot;caption&amp;quot;&amp;gt;     &lt;br /&gt;
            &amp;lt;h4&amp;gt;Per-tenant authentication plugins&amp;lt;/h4&amp;gt;      &lt;br /&gt;
            &amp;lt;p&amp;gt;Selected authentication settings such as authentication instructions and allowed domains can be overridden for individual tenants. Site administrators are also able to force some settings for all tenants. Tenant admin can override common settings or settings for multi-tenant auth plugins in their tenant using the new Authentication tab in the Users page.&amp;lt;/p&amp;gt; &lt;br /&gt;
          &amp;lt;/div&amp;gt;      &lt;br /&gt;
        &amp;lt;/div&amp;gt;      &lt;br /&gt;
      &amp;lt;/li&amp;gt;&lt;br /&gt;
      &amp;lt;li class=&amp;quot;span6&amp;quot;&amp;gt;      &lt;br /&gt;
        &amp;lt;div class=&amp;quot;thumbnail&amp;quot;&amp;gt;     &lt;br /&gt;
[[File:Per-tenant authentication plugins - 03.png|600px]]&lt;br /&gt;
          &amp;lt;div class=&amp;quot;caption&amp;quot;&amp;gt;     &lt;br /&gt;
            &amp;lt;h4&amp;gt;Multi-tenant auth plugins&amp;lt;/h4&amp;gt;      &lt;br /&gt;
            &amp;lt;p&amp;gt;Email-based self-registration and OAuth2 are now multi-tenant. Global administrator or tenant administrator can enable/disable these plugins on a tenant level and override their settings. When a new user signs up from a tenant-specific login page their account is automatically registered inside this tenant.&amp;lt;/p&amp;gt; &lt;br /&gt;
          &amp;lt;/div&amp;gt;      &lt;br /&gt;
        &amp;lt;/div&amp;gt;      &lt;br /&gt;
      &amp;lt;/li&amp;gt;         &lt;br /&gt;
    &amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Sharing entities =&lt;br /&gt;
== Shared courses ==&lt;br /&gt;
&lt;br /&gt;
Normally each tenant has its own course category and its own courses. The manual enrolment method has been modified so the user picker only displays users from the current tenant.&lt;br /&gt;
&lt;br /&gt;
However there are some situations when an organisation wants to have courses that are shared between tenants. Please note that &#039;&#039;&#039;multitenancy will not apply to the course content&#039;&#039;&#039;. This means that if a user (either a learner or a trainer) is enrolled in a course, they will see users from other tenants while browsing the course. This could be forum posts, list of course participants, gradebook, reports or any other module that displays course participants. &lt;br /&gt;
&lt;br /&gt;
There are various reasons for this behaviour:&lt;br /&gt;
&lt;br /&gt;
# If the organisation wants to have shared courses they may actually expect this behaviour since they want the learners to study together and/or the trainer from one tenant to be a teacher for all learners regardless of their tenant&lt;br /&gt;
# It is simply impossible to modify all activity modules and reports to add multitenancy restrictions, especially considering that there can be third party plugins&lt;br /&gt;
# The same functionality can be achieved by using separate group mode if needed&lt;br /&gt;
&lt;br /&gt;
If you share courses between different tenants and you want users from each tenants to learn independently they must belong to different groups and &#039;&#039;&#039;the course has to be in separate group mode&#039;&#039;&#039; (preferably forced). Please review the &amp;quot;Trainer&amp;quot; and &amp;quot;Non-editing trainer&amp;quot; roles in the course and make sure that they do not have the [[Capabilities/moodle/site:accessallgroups|accessallgroups]] capability, and the trainers are also allocated to the relevant groups.&lt;br /&gt;
&lt;br /&gt;
Allocation to separate groups is done automatically when a shared course is part of a program. See also [[Programs#Shared_courses|Shared courses in programs]]&lt;br /&gt;
&lt;br /&gt;
== Shared Space ==&lt;br /&gt;
Shared Space enables easy sharing of entities across all tenants. It works like a special tenant where users can create supported entities to be available in other tenants.&lt;br /&gt;
&lt;br /&gt;
Note the Shared Space is considered a tenant, so it counts towards the tenants limit if any. See also [[Multi-tenancy#Limiting_number_of_tenants|Limiting number of tenants]].&lt;br /&gt;
&lt;br /&gt;
=== Enabling Shared space ===&lt;br /&gt;
Shared space can be activated either by clicking the &amp;quot;Shared space&amp;quot; item in the Tenant switch dropdown or the Tenants main page (found in the Workplace launcher). &lt;br /&gt;
&lt;br /&gt;
[[File:wp-enable-shared-space-dropdown.png]]&lt;br /&gt;
&lt;br /&gt;
A dialogue box will require confirmation and the Shared space will only be created after the user agrees with it. Th user also has the option to hit the &amp;quot;Not now&amp;quot; button which will remove it from the Tenant Menu and henceforth will only be visible in the Manage Tenants page .&lt;br /&gt;
&lt;br /&gt;
= Privacy considerations =&lt;br /&gt;
&lt;br /&gt;
All user information from each tenant is stored in the same database and in the same table. This may be a concern for you if your tenants are completely independent and you must comply with [[GDPR|GDPR requirements]] to store data separately. The benefit of the multi-tenancy feature is that you have a single Moodle Workplace instance for all tenants and users, making it easier for you to maintain and have shared data. If you are required by law to separate them, unfortunately you may not benefit from multi-tenancy and may need to set up separate sites.&lt;br /&gt;
&lt;br /&gt;
= See also =&lt;br /&gt;
&lt;br /&gt;
* [[Multi-tenancy capabilities]]&lt;br /&gt;
* [[Capabilities/tool/tenant:manage]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_Release_notes&amp;diff=139147</id>
		<title>Moodle Workplace Release notes</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Moodle_Workplace_Release_notes&amp;diff=139147"/>
		<updated>2020-12-03T10:59:57Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: /* Upgrade notes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
This page contains release notes for Moodle Workplace releases.&lt;br /&gt;
&lt;br /&gt;
=3.10=&lt;br /&gt;
See our [[Moodle Workplace 3.10 new features page]] in the user documentation for an introduction to Moodle Workplace 3.10 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* Multi-tenant authentication: Selected authentication settings such as authentication instructions and allowed domains can be overridden for individual tenants. Site administrators are also able to force some settings for all tenants. Tenant admin can override common settings or settings for multi-tenant auth plugins in their tenant using the new Authentication tab in the Users page.&lt;br /&gt;
* Multi-tenant auth plugins: Email-based self-registration and OAuth2 are now multi-tenant. Global administrator or tenant administrator can enable/disable these plugins on a tenant level and override their settings. When a new user signs up from a tenant-specific login page their account is automatically registered inside this tenant.&lt;br /&gt;
* [[Report_builder#Shared_reports|Shared reports]]: Reports are available now in the Shared Space and can be shared with all tenants or be only accessible to users with access to the shared space. This feature enables users to use the same report definition site-wide without duplicating the same reports in all tenants. It also allows to create cross-tenant reports. When a shared report is viewed from inside the tenant it only displays the users and entities from this tenant. When a shared report is viewed from Shared space it shows information from all tenants.&lt;br /&gt;
* Full site content [[Migrations|migration]]: Now it’s possible to migrate all the site content including all tenants in the system and all the courses with user data. This feature uses all the chained exporters and importers we introduced on the previous releases.&lt;br /&gt;
* Tenant-allocation [[Dynamic rules|dynamic rules]]: Addition of users to tenants now can be automated using Dynamic Rules. We’ve introduced a new condition to target new users which can be combined with any other conditions such as email domains or authentication plugins to decide where to allocate them. Tenant allocation dynamic rules should be normally created inside the Default tenant.&lt;br /&gt;
* New Workplace native site users page: Revamped Browse all users page with the list of all users on the site with the tenant information, bulk actions and filters.&lt;br /&gt;
&lt;br /&gt;
===Upgrade notes for 3.10===&lt;br /&gt;
Upgrading workplace to 3.10:&lt;br /&gt;
* New capability tool/tenant:authconfig can be added to the &amp;quot;Tenant administrator&amp;quot; role to allow tenant administrators to override authentication settings. New installations of Moodle Workplace 3.10 will have this capability allowed by default. For security reasons this capability is not added to the &amp;quot;Tenant administrator&amp;quot; role during upgrade from Workplace 3.9 since no configuration settings are forced by default.&lt;br /&gt;
* If you have plugins that use workplace APIs, such as multi-tenancy or dynamic rules check out the CHANGELOG.md file in the respective plugins (admin/tool/tenant and admin/tool/dynamicrule). From now on the workplace team will be maintaining the changelogs for API changes.&lt;br /&gt;
&lt;br /&gt;
=3.9.2=&lt;br /&gt;
See our [[Moodle Workplace 3.9.2 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9.2 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Multi-tenancy#Shared_Space|Shared Space]] enables easy sharing of entities across all tenants. It works like a special tenant where users can create supported entities to be available in other tenants.&lt;br /&gt;
* [[Programs#Shared_programs|Shared Programs]] and [[Certifications#Shared_Certifications|Shared certifications]]: making use of the Shared Space, now it’s possible to share Programs and Certifications across all tenants.&lt;br /&gt;
* Tenants [[Migrations|migration]]: now it’s possible to migrate whole tenants’ content and configuration using all the chained exporters and importers we introduced on the previous releases.&lt;br /&gt;
* Learning tab: this is a major change in the [[Learner_dashboard|Workplace learner dashboard]]. Programs and Courses are not separated in different tabs anymore, with the new Learning tab all the learning entities are shown in the same tab. We took the opportunity to improve the UI as well.&lt;br /&gt;
* [[Certificate_course_activity|Course certificate]]: with this activity module now it’s possible to configure certificates at a course level. This certificate can be configured to be issued automatically when the activity is available without any user intervention.&lt;br /&gt;
&lt;br /&gt;
=3.9.1=&lt;br /&gt;
See our [[Moodle Workplace 3.9.1 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9.1 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Migrations|Migration feature]]. New exporters and importers:&lt;br /&gt;
** [[Report builder]]: custom reports, including schedules and audiences&lt;br /&gt;
** [[Certificates]]: templates and issued certificates&lt;br /&gt;
** [[Organisation structure]] CSV: importers for departments and positions hierarchies from external systems in CSV format&lt;br /&gt;
* Direct reports Teams tab filter: added a new filter to made the teams tab only show people directly underneath the current user&lt;br /&gt;
* Added download options to system reports, such as Users list on the tenant management page&lt;br /&gt;
&lt;br /&gt;
=3.9=&lt;br /&gt;
See our [[Moodle Workplace 3.9 new features page]] in the user documentation for an introduction to Moodle Workplace 3.9 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Migrations|Migration feature]]: this tool, through an intuitive step-by-step process, offers the capacity to export different parts of a Moodle Workplace instance and import them into the same or a different site.&lt;br /&gt;
* Exporters and Importers included in 3.9: &lt;br /&gt;
** Programs: definition, courses, user allocations and component dynamic rules.&lt;br /&gt;
** Certifications: definition, associated programs, courses, user allocations and component dynamic rules.&lt;br /&gt;
** Dynamic Rules: definition, conditions and actions,&lt;br /&gt;
** Organisation Structure (Jobs): jobs details with their associated department and position frameworks.&lt;br /&gt;
** Organisation Structure (Frameworks): department and position frameworks with the whole hierarchy for departments and/or positions.&lt;br /&gt;
** Courses using default course backup options.&lt;br /&gt;
* Command-line interactive interface for Migration&lt;br /&gt;
* Dynamic Rules additional capabilities check for each condition and action. Now we check users capabilities for each type of dynamic rules conditions and actions, enabling more granularity in Dynamic Rules permissions.&lt;br /&gt;
* Video conferencing with BigBlueButton, built-in in Workplace on MoodleCloud.&lt;br /&gt;
* Report Builder filter and condition for the current user: pre-filter any report to show only information related to the viewer.&lt;br /&gt;
* Improved course information modal: now users can access all the information about course in a program from the UI.&lt;br /&gt;
&lt;br /&gt;
=3.8.2=&lt;br /&gt;
See our [[Moodle Workplace 3.8.2 new features page]] in the user documentation for an introduction to Moodle Workplace 3.8.2 with screenshots. &lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
* [[Programs]] - addition to the [[Moodle_Workplace#Dashboard|Workplace Dashboard]] to allow users to search for their own programs&lt;br /&gt;
* [[Programs]] - improved programs list view on the [[Moodle_Workplace#Dashboard|Workplace Dashboard]], with expandable courses information&lt;br /&gt;
* [[Report builder]] and [[Dynamic rules]] - Live Search is now available for Conditions and Actions on Dynamic Rules and for Entities and fields (Report Builder) on Report Builder&lt;br /&gt;
* Login page - new auth instructions redesign and addition of the language selector&lt;br /&gt;
* [[Report builder]] - Sort columns on click&lt;br /&gt;
* [[Report builder]] - Collapsable left container and &lt;br /&gt;
* [[Report builder]] - Preview and filter buttons redesigning&lt;br /&gt;
* Test coverage and performance improvements across all Workplace features&lt;br /&gt;
* Workplace testing environment for plugin developers now available&lt;br /&gt;
* Workplace launcher - an alternative view as a modal dialog box is now available (experimental)&lt;br /&gt;
* Auto-updating for restricted activities in Workplace list course format&lt;br /&gt;
* Fixed app link in Workplace footer&lt;br /&gt;
&lt;br /&gt;
=3.8.1=&lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* [[Appointments]] - continued user interface polishing and improvements; new [[Report builder]] datasource to facilitate custom reporting; improvements to custom fields&lt;br /&gt;
* [[Certifications#Users|Certifications]] - new &amp;quot;Certification activity log&amp;quot; to show a users progress through an allocated certification&lt;br /&gt;
* [[Programs]] - addition to the [[Moodle_Workplace#Dashboard|Workplace Dashboard]] to allow users to filter their own programs&lt;br /&gt;
* [[Programs]] and [[Certifications]] - improvements to automatic [[Dynamic rules]] (clearer names, improved conditions, ability to set allocation start date in future); improved custom field support&lt;br /&gt;
* Improvements to the [[Multi-tenancy#Tenant_administration|Tenant administrator]] role - the list of capabilities that can be granted to a tenant administrator is restricted to those capabilities that support [[Multi-tenancy]] as defined by the Workplace plugins. Manually assigning Workplace roles is no longer possible via the assign roles page to avoid confusion, however the list of allowed capabilities in these roles may be changed by the site administrator&lt;br /&gt;
* Improved performance when editing tenant theme settings - caches are now purged only for the relevant tenant, rather than for all&lt;br /&gt;
* Consistent configuration for setting limits for [[Multi-tenancy#Limiting_number_of_tenants|Tenants]], [[Dynamic_rules#Limiting_number_of_dynamic_rules|Dynamic rules]] and [[Report_builder#Limiting_number_of_custom_reports|Report builder]]&lt;br /&gt;
* Privacy API improvements&lt;br /&gt;
&lt;br /&gt;
=3.8.0=&lt;br /&gt;
&lt;br /&gt;
==Major features==&lt;br /&gt;
&lt;br /&gt;
* [[Programs#Program_reset|Program reset]] - allows to reset a program and all courses it in for an individual user&lt;br /&gt;
* [[Certifications#Recertification|Recertification]] - allows to configure the workflow for regular recertification&lt;br /&gt;
* [[Report builder#Configuring_audience|Audience]] in report builder allows to give granular access to individual reports&lt;br /&gt;
* [[Appointments]] - new module that allows to book face-to-face appointments between trainers and students in a course&lt;br /&gt;
* [[Certificates]] no longer belong to the tenants but instead can be created in course categories&lt;br /&gt;
* [[Programs#Shared_courses|Sharing courses]] between tenants and using them in the programs&lt;br /&gt;
&lt;br /&gt;
==Important upgrade notes==&lt;br /&gt;
&lt;br /&gt;
===Report builder changes===&lt;br /&gt;
&lt;br /&gt;
Organisation managers can no longer access the reports on their team by default. Instead, tenant administrators need to create new reports with the condition &amp;quot;Relation to report viewer&amp;quot; and set the &amp;quot;Audience&amp;quot; to include an organisation manager&#039;s job.&lt;br /&gt;
&lt;br /&gt;
===Certificates===&lt;br /&gt;
&lt;br /&gt;
The Certificates plugin has been reworked to allow users to create certificates in course categories instead of binding them to tenants. This plugin will be made available in the future outside of Moodle Workplace.&lt;br /&gt;
&lt;br /&gt;
The upgrade script will automatically unallocate the existing certificates from the tenants and allocate them to the respective course categories of the tenants. However &#039;&#039;&#039;if there was a tenant without a course category and with certificates&#039;&#039;&#039;, the administrator needs &#039;&#039;&#039;to fix it manually&#039;&#039;&#039; - create a category for the tenant and move the certificate(s) to this category.&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:verifyforalltenants&#039; is removed and instead we have [[Capabilities/tool/certificate:verify|&#039;tool/certificate:verify&#039;]] that will allow users to verify certificates for any tenant (by code).&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:issueforalltenants&#039; is removed. Users with the capability [[Capabilities/tool/certificate:issue|&#039;tool/certificate:issue&#039;]] can issue certificates to users from their tenant. If such user also has capabilities allowing him to view users from other tenants, they will be able to issue certificate to all users.&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:manageforalltenants&#039; is removed. Instead, capability [[Capabilities/tool/certificate:manage|&#039;tool/certificate:manage&#039;]] can be assigned in different contexts and will work on templates that are defined in the relevant contexts.&lt;br /&gt;
&lt;br /&gt;
Capability [[Capabilities/tool/certificate:issue|&#039;tool/certificate:issue&#039;]] can now be assigned in different contexts (system or course category). Users who have it can issue certificates that are defined in the same context (or lower).&lt;br /&gt;
&lt;br /&gt;
Capability &#039;tool/certificate:imageforalltenants&#039; is renamed to [[Capabilities/tool/certificate:image|&#039;tool/certificate:image&#039;]] - allows users to manage shared images.&lt;br /&gt;
&lt;br /&gt;
Capability [[Capabilities/tool/certificate:viewallcertificates|&#039;tool/certificate:viewallcertificates&#039;]] can also be assigned in different contexts now. Similar to &#039;issue&#039; capability, users will only see other users from the same tenant (unless they have additional capabilities that allow them to view users in other tenants)&lt;br /&gt;
&lt;br /&gt;
The element type &amp;quot;Program&amp;quot; is now called &#039;&#039;&#039;&amp;quot;Dynamic rule data&amp;quot;&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Setting limits for tenant-related data==&lt;br /&gt;
&lt;br /&gt;
It is possible for site administrators to limit the amount of data related to a tenant for certain features:&lt;br /&gt;
&lt;br /&gt;
* The number of [[Multi-tenancy|tenants]] can be restricted by setting &#039;$CFG-&amp;gt;tool_tenant_tenantlimit = &amp;lt;VALUE&amp;gt;;&#039; in your [[Configuration_file|site configuration]]&lt;br /&gt;
* The number of [[Report_builder#Creating_a_custom_report|custom reports]] can be restricted per site/tenant by setting &#039;$CFG-&amp;gt;tool_reportbuilder_sitelimit&#039; and &#039;$CFG-&amp;gt;tool_reportbuilder_tenantlimit&#039; respectively&lt;br /&gt;
* The number of [[Dynamic_rules#Creating_dynamic_rules|dynamic rules]] can be restricted per site/tenant by setting &#039;$CFG-&amp;gt;tool_dynamicrule_sitelimit&#039; and &#039;$CFG-&amp;gt;tool_dynamicrule_tenantlimit&#039; respectively&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Capabilities/tool/tenant:authconfig&amp;diff=139096</id>
		<title>Capabilities/tool/tenant:authconfig</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Capabilities/tool/tenant:authconfig&amp;diff=139096"/>
		<updated>2020-12-01T12:56:19Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: Created page with &amp;quot;{{Workplace}}  * Allows to control authentication settings inside the current tenant in the Workplace Multi-tenancy feature * This capability may only be applied in the sy...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
&lt;br /&gt;
* Allows to control authentication settings inside the current tenant in the Workplace [[Multi-tenancy]] feature&lt;br /&gt;
* This capability may only be applied in the system context.&lt;br /&gt;
* The default [[Tenant administrator role]] has this capability set to allow in the new installations, however it is not allowed automatically in the sites upgraded from a version below 3.10 for security reasons&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Moodle Workplace]]&lt;br /&gt;
* [[Multi-tenancy]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Capabilities]]&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/310/en/index.php?title=Multi-tenancy_capabilities&amp;diff=138739</id>
		<title>Multi-tenancy capabilities</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/310/en/index.php?title=Multi-tenancy_capabilities&amp;diff=138739"/>
		<updated>2020-11-05T10:33:46Z</updated>

		<summary type="html">&lt;p&gt;Marina.glancy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Workplace}}&lt;br /&gt;
{{Work in progress&lt;br /&gt;
|info = This page will apply to the version 3.10 of Moodle Workplace&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
Workplace and core capabilities and how they affect permissions to work with users &lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Capability&lt;br /&gt;
! Description&lt;br /&gt;
! Tenant admin&lt;br /&gt;
|-&lt;br /&gt;
| [[Capabilities/tool/tenant:manage|tool/tenant:manage]]&lt;br /&gt;
| Can browse users in any tenant &lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| tool/tenant:allocate&lt;br /&gt;
| Can see all tenants, browse users in all tenants, move users between tenants&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| tool/tenant:manageusers&lt;br /&gt;
| Can browse, edit, delete, suspend users in the current tenant or its sub-tenants [https://tracker.moodle.org/browse/WP-1124 WP-1124]&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| tool/tenant:browseusers&lt;br /&gt;
| Can browse users in the current tenant or its sub-tenants&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
| tool/tenant:authconfig&lt;br /&gt;
| Can edit authentication settings in the current tenant and its sub-tenants&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
| moodle/restore:createuser&lt;br /&gt;
|&lt;br /&gt;
| No [https://tracker.moodle.org/browse/WP-929 WP-929]&lt;br /&gt;
|-&lt;br /&gt;
| moodle/site:viewuseridentity&lt;br /&gt;
|&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
| moodle/site:uploadusers&lt;br /&gt;
|&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:create&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:delete&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:update&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:viewdetails&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:viewalldetails&lt;br /&gt;
|&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:viewlastip&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:viewhiddendetails&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:loginas&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:managesyspages&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:manageblocks&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:manageownblocks&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:manageownfiles&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/my:configsyspages&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/course:reviewotherusers&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/course:bulkmessaging&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/course:viewhiddenuserfields&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/site:viewparticipants&lt;br /&gt;
|&lt;br /&gt;
| No [https://tracker.moodle.org/browse/WP-1520 WP-1520]&lt;br /&gt;
|-&lt;br /&gt;
| moodle/user:editprofile&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/badges:awardbadge&lt;br /&gt;
|&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
| moodle/badges:revokebadge&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/badges:viewawarded&lt;br /&gt;
|&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
| moodle/site:messageanyuser&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| moodle/role:assign&lt;br /&gt;
|&lt;br /&gt;
| Yes&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
| &lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Marina.glancy</name></author>
	</entry>
</feed>