Skip to content

Web services

The Multi-tenancy plugin exposes a set of Moodle web services for integration with external systems. All write operations require the tool/mutenancy:admin capability at system context. All services will return an error if multi-tenancy is not active on the site.

The following fields are returned by tool_mutenancy_get_tenants, tool_mutenancy_create_tenant, and tool_mutenancy_update_tenant:

FieldTypeDescription
idintTenant id.
namestringTenant name.
idnumberstringTenant ID number.
loginshowboolWhether the tenant is shown on the login page.
memberlimitintMaximum number of tenant members. 0 means no limit.
categoryidintTenant course category id.
cohortidintTenant members cohort id.
assoccohortidintAssociated users cohort id.
sitefullnamestringTenant site full name.
siteshortnamestringTenant site short name.
archivedboolArchived flag.
timecreatedintCreation date.
timemodifiedintLast modification date.

Returns a list of tenants matching the given search parameters.

Capability: tool/mutenancy:view (system context)

Parameters:

NameTypeDescription
fieldvaluesarrayList of field/value pairs to filter by. Accepted fields: id, name, idnumber, archived.

Returns: Array of tenant objects.


Creates a new tenant.

Capability: tool/mutenancy:admin (system context)

Parameters:

NameTypeRequiredDescription
namestringyesTenant name.
idnumberstringyesTenant ID number.
loginshowboolnoShow on login page.
memberlimitintnoMaximum number of members.
sitefullnamestringnoSite full name.
siteshortnamestringnoSite short name.
categorynamestringnoTenant category name.
categoryidnumberstringnoTenant category ID number.
cohortnamestringnoTenant cohort name.
cohortidnumberstringnoTenant cohort ID number.
assoccohortcreateboolnoWhether to create an associated users cohort.

Returns: Created tenant object.


Updates an existing tenant.

Capability: tool/mutenancy:admin (system context)

Parameters:

NameTypeRequiredDescription
idintyesTenant id.
namestringnoTenant name.
idnumberstringnoTenant ID number.
loginshowboolnoShow on login page.
memberlimitintnoMaximum number of members.
sitefullnamestringnoSite full name.
siteshortnamestringnoSite short name.
categorynamestringnoTenant category name.
categoryidnumberstringnoTenant category ID number.
cohortnamestringnoTenant cohort name.
cohortidnumberstringnoTenant cohort ID number.

Returns: Updated tenant object.


Returns the list of managers for a tenant.

Capability: tool/mutenancy:view (tenant context)

Parameters:

NameTypeDescription
tenantidintTenant id.

Returns: Array of user objects with the following fields:

FieldTypeDescription
idintUser id.
usernamestringUsername.
firstnamestringFirst name.
lastnamestringLast name.
emailstringEmail address.
tenantidintTenant id if the manager is also a member of the tenant, otherwise NULL.

Adds a user to the tenant manager position.

Capability: tool/mutenancy:admin (system context)

Parameters:

NameTypeDescription
tenantidintTenant id.
useridintUser id.

Returns: true if added, false if the user was already a manager.


Removes a user from the tenant manager position.

Capability: tool/mutenancy:admin (system context)

Parameters:

NameTypeDescription
tenantidintTenant id.
useridintUser id.

Returns: true if removed, false if the user was not a manager.


Allocates a user as a tenant member, or deallocates them to a global user.

Capability: tool/mutenancy:allocate (system context)

Parameters:

NameTypeDescription
useridintUser id.
tenantidintTenant id to allocate to, or NULL to make the user a global user.

Returns: true if the allocation changed, false if the user was already in the requested state.