Skip to main content

Create a tenant with the .NET SDK

permitClient.Api.CreateTenant() creates a tenant in the environment that your API key belongs to. This reference is for .NET developers who manage tenants from backend code.

CreateTenant signature

public async Task<TenantRead> CreateTenant(TenantCreate tenantCreate)

CreateTenant parameters

ParameterTypeRequiredDescription
tenantCreateTenantCreateYesThe tenant to create. The TenantCreate class is in the PermitSDK.OpenAPI.Models namespace.

TenantCreate properties

PropertyTypeRequiredDescription
KeystringYesA unique ID by which Permit identifies the tenant. The key must be URL-friendly (slugified).
NamestringYesA descriptive name for the tenant.
Descriptionstring?NoA longer description of the tenant.
Attributesobject?NoTenant attributes that attribute-based access control (ABAC) policies evaluate, as key-value pairs.

Build a TenantCreate object named tenantObj with these properties. Replace the placeholder values key, name, and description with the values for your tenant:

var tenantObj = new TenantCreate
{
Key = "key",
Name = "name",
Description = "description"
};

Example: create a tenant with CreateTenant

The example uses a client named permitClient, created with new Permit(...) as shown in Check permissions with the .NET SDK, and a TenantCreate object named tenantObj:

var response = await permitClient.Api.CreateTenant(tenantObj);

CreateTenant return value and errors

On success, CreateTenant returns a TenantRead with the tenant's Key, Id, Name, Description, and Attributes. If a tenant with the same key already exists, the Permit API returns the existing tenant instead of an error.

If the Permit API returns an error, CreateTenant throws a PermitApiException. The exception's StatusCode property has the HTTP status, such as 422 when a property fails validation, and its Response property has the response body.