Reference > SDK > Tenant Manager
Tenant Manager
TenantManagerSdk reference - create and manage tenants programmatically
- How to access the Tenant Manager SDK?
- How to create and install new tenants?
- How to disable and enable existing tenants?
- How to handle tenant management errors?
Overview
The TenantManagerSdk provides methods for creating, installing, disabling, and enabling tenants programmatically. Access it via the tenantManager namespace on your Webiny SDK instance. Creating a new tenant requires two steps: createTenant() to register the tenant, then installTenant() to provision its resources and configurations.
All tenant management operations require an API key with tenant manager permissions.
Class Reference
TenantManagerSdk
The Tenant Manager SDK is accessed via sdk.tenantManager on a Webiny instance:
Methods
createTenant
Creates a new tenant in the system. Returns the tenant ID on success.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
params | CreateTenantParams | Yes | Tenant creation parameters |
params.data | CreateTenantInput | Yes | Tenant data |
params.data.id | string | No | Custom tenant ID (generated if omitted) |
params.data.name | string | Yes | Tenant name |
params.data.description | string | No | Tenant description |
Returns:
Result<boolean, HttpError | GraphQLError | NetworkError> - Success returns true, failure returns error with message and code.
Example:
installTenant
Installs and provisions a tenant with default settings and configurations. Must be called after createTenant() before the tenant is usable.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
params | InstallTenantParams | Yes | Installation parameters |
params.tenantId | string | Yes | ID of the tenant to install |
Returns:
Result<boolean, HttpError | GraphQLError | NetworkError> - Success returns true, failure returns error with message and code.
Example:
disableTenant
Disables a tenant, preventing access to its resources. Disabled tenants cannot be accessed until re-enabled.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
params | DisableTenantParams | Yes | Disable parameters |
params.tenantId | string | Yes | ID of the tenant to disable |
Returns:
Result<boolean, HttpError | GraphQLError | NetworkError> - Success returns true, failure returns error with message and code.
Example:
enableTenant
Re-enables a previously disabled tenant, restoring access to its resources.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
params | EnableTenantParams | Yes | Enable parameters |
params.tenantId | string | Yes | ID of the tenant to enable |
Returns:
Result<boolean, HttpError | GraphQLError | NetworkError> - Success returns true, failure returns error with message and code.
Example:
Error Handling
All tenant manager methods return a Result type. Check for errors before accessing the value:
Common error scenarios:
- Permission denied (API key lacks tenant manager permissions)
- Tenant already exists (duplicate tenant ID)
- Tenant not found (invalid tenant ID)
- Network errors (API unreachable)
Examples
Creating and Installing a New Tenant
The complete flow for provisioning a new tenant requires two steps:
Disabling and Enabling a Tenant
Error Handling Pattern