---
title: "client.Workspaces"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://openemail.uk/docs/csharp/reference/workspaces"
area: "C#"
category: "Reference"
---

# client.Workspaces

Every method in this namespace: its signature, its parameters, what it returns and an example.

## Methods

The workspaces the person behind the key or the app can open: list them, create one, choose the one the app opens, and delete the workspace the key or the app belongs to. An API key acts for the workspace owner, and an app for the person who connected it.

### `Workspaces.ListAsync`

List your workspaces

```csharp
Task<JsonObject> ListAsync(string? apiKey = null, CancellationToken cancellationToken = default)
```

Returns every workspace the person behind the client can open, the ones they own first, as the workspace switcher of the app lists them. It is about the person, not the workspace the key belongs to. An API key answers for the workspace owner, and an app for the person who connected it.

`activeWorkspaceId` is the workspace the app opens for them, `primaryWorkspaceId` the first one they made, which can never be deleted, and `personalWorkspaceId` their personal space, which holds their free address and is not in `data`.

Scopes: `account:read`.

**Parameters**

- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject` with `data`, a list of objects, one per workspace, and `activeWorkspaceId`, `primaryWorkspaceId` and `personalWorkspaceId`.

**Example**

```csharp
var workspaces = await client.Workspaces.ListAsync();

Console.WriteLine(workspaces.ToJsonString());
```

**Notes**

- The key or the app still acts for its own workspace in every other call.

Also available in: API [`GET /workspaces`](https://openemail.uk/docs/api/reference/workspaces#get-workspaces); TypeScript [`workspaces.list()`](https://openemail.uk/docs/sdk/reference/workspaces#list); Python [`workspaces.list()`](https://openemail.uk/docs/python/reference/workspaces#list); Ruby [`workspaces.list`](https://openemail.uk/docs/ruby/reference/workspaces#list); PHP [`workspaces->list`](https://openemail.uk/docs/php/reference/workspaces#list); Go [`Workspaces.List`](https://openemail.uk/docs/go/reference/workspaces#list); Java [`workspaces().list`](https://openemail.uk/docs/java/reference/workspaces#list); CLI [`openemail workspaces list`](https://openemail.uk/docs/cli/reference/workspaces#workspaces-list).

### `Workspaces.CreateAsync`

Create a workspace

```csharp
Task<JsonObject> CreateAsync(
    IReadOnlyDictionary<string, object?> body,
    string? apiKey = null,
    CancellationToken cancellationToken = default)
```

Makes a new workspace owned by the person, on the Free plan, and makes it the workspace the app opens for them, as creating one in the app does. The key or the app making the call keeps acting for its own workspace.

An account can own one workspace on the Free plan. While it owns one, the call is refused with 403 `workspace_allowance_reached` and the message names that workspace: upgrade it first.

Scopes: `account:write`.

**Parameters**

- `name` (`string`, required): Up to 64 characters. Leading and trailing spaces are trimmed.
- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject` with `id`, `name`, `slug` and `active` set to true.

**Example**

```csharp
try
{
    var workspace = await client.Workspaces.CreateAsync(new Body { ["name"] = "Acme Support" });

    Console.WriteLine($"{workspace["id"]} {workspace["slug"]}");
}
catch (OpenEmailApiException error)
{
    if (error.Code != "workspace_allowance_reached")
    {
        throw;
    }

    Console.WriteLine(error.Message);
}
```

**Notes**

- Not retried automatically. The same name sent twice within ten seconds returns the workspace the first call made, so a retry right after a lost response is safe.

Also available in: API [`POST /workspaces`](https://openemail.uk/docs/api/reference/workspaces#post-workspaces); TypeScript [`workspaces.create()`](https://openemail.uk/docs/sdk/reference/workspaces#create); Python [`workspaces.create()`](https://openemail.uk/docs/python/reference/workspaces#create); Ruby [`workspaces.create`](https://openemail.uk/docs/ruby/reference/workspaces#create); PHP [`workspaces->create`](https://openemail.uk/docs/php/reference/workspaces#create); Go [`Workspaces.Create`](https://openemail.uk/docs/go/reference/workspaces#create); Java [`workspaces().create`](https://openemail.uk/docs/java/reference/workspaces#create); CLI [`openemail workspaces create`](https://openemail.uk/docs/cli/reference/workspaces#workspaces-create).

### `Workspaces.GetActiveAsync`

Read the workspace the app opens

```csharp
Task<JsonObject> GetActiveAsync(
    string? apiKey = null,
    CancellationToken cancellationToken = default)
```

Returns the workspace the app opens for the person when they sign in, or the one it falls back to when they never chose one. It is not the workspace the key or the app acts on, which never changes.

Scopes: `account:read`.

**Parameters**

- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject` with `id`, `name`, `slug`, `email`, `kind`, `isOwner` and `createdAt`.

**Example**

```csharp
var opened = await client.Workspaces.GetActiveAsync();

Console.WriteLine($"{opened["name"]} ({opened["kind"]})");
```

**Notes**

- `kind` is `personal` when the app opens the personal space.

Also available in: API [`GET /workspaces/active`](https://openemail.uk/docs/api/reference/workspaces#get-workspaces-active); TypeScript [`workspaces.getActive()`](https://openemail.uk/docs/sdk/reference/workspaces#getActive); Python [`workspaces.get_active()`](https://openemail.uk/docs/python/reference/workspaces#getActive); Ruby [`workspaces.get_active`](https://openemail.uk/docs/ruby/reference/workspaces#getActive); PHP [`workspaces->getActive`](https://openemail.uk/docs/php/reference/workspaces#getActive); Go [`Workspaces.GetActive`](https://openemail.uk/docs/go/reference/workspaces#getActive); Java [`workspaces().getActive`](https://openemail.uk/docs/java/reference/workspaces#getActive); CLI [`openemail workspaces get-active`](https://openemail.uk/docs/cli/reference/workspaces#workspaces-get-active).

### `Workspaces.SetActiveAsync`

Choose the workspace the app opens

```csharp
Task<JsonObject> SetActiveAsync(
    string workspaceId,
    string? apiKey = null,
    CancellationToken cancellationToken = default)
```

Switches the workspace the app opens for the person, as the workspace switcher does, to any workspace they can open. It changes nothing for the key or the app making the call, which keeps acting for its own workspace.

Scopes: `account:write`.

**Parameters**

- `workspaceId` (`string`, required): A workspace id from `ListAsync`.
- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

The same object as `Workspaces.GetActiveAsync`, for the workspace the app opens now.

**Example**

```csharp
var workspaces = await client.Workspaces.ListAsync();

var opened = await client.Workspaces.SetActiveAsync(workspaces["primaryWorkspaceId"]!.GetValue<string>());

Console.WriteLine($"The app now opens {opened["name"]}");
```

**Notes**

- A workspace the person cannot open is a 404 `resource_not_found`.
- Retried automatically on network failure, since choosing the same workspace twice changes nothing.

Also available in: API [`PUT /workspaces/active`](https://openemail.uk/docs/api/reference/workspaces#put-workspaces-active); TypeScript [`workspaces.setActive()`](https://openemail.uk/docs/sdk/reference/workspaces#setActive); Python [`workspaces.set_active()`](https://openemail.uk/docs/python/reference/workspaces#setActive); Ruby [`workspaces.set_active`](https://openemail.uk/docs/ruby/reference/workspaces#setActive); PHP [`workspaces->setActive`](https://openemail.uk/docs/php/reference/workspaces#setActive); Go [`Workspaces.SetActive`](https://openemail.uk/docs/go/reference/workspaces#setActive); Java [`workspaces().setActive`](https://openemail.uk/docs/java/reference/workspaces#setActive); CLI [`openemail workspaces set-active`](https://openemail.uk/docs/cli/reference/workspaces#workspaces-set-active).

### `Workspaces.DeleteAsync`

Delete the workspace

```csharp
Task<JsonObject> DeleteAsync(
    string id,
    string confirm,
    string? apiKey = null,
    CancellationToken cancellationToken = default)
```

Deletes the workspace the key or the app belongs to, with its domains, addresses, mail and members, and cancels its plan. It cannot be undone. `confirm` has to be the name of the workspace, as `ListAsync` shows it, the same way the app asks the person to type it.

Only the owner may do it. An access token acting for a member is refused with 403 `owner_only`, and a key or an app limited to particular addresses or domains with 422 `capability_unsupported`. Any other workspace id is a 404, the first workspace an account made is refused with 409 `first_workspace`, and one with a domain being moved in or out with 409 `domain_moving`.

Scopes: `account:write`.

**Parameters**

- `id` (`string`, required): The id of the workspace the key or the app belongs to, which `Me.GetAsync` reports as `workspaceId`.
- `confirm` (`string`, required): The name of the workspace. Letter case and the spaces around it do not matter. Sent as a query parameter.
- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject` with `id`, `deleted` set to true and `activeWorkspaceId`, the workspace the app opens from now on.

**Example**

```csharp
var key = await client.Me.GetAsync();

var deleted = await client.Workspaces.DeleteAsync(key["workspaceId"]!.GetValue<string>(), "Acme Support");

Console.WriteLine($"Deleted. The app now opens {deleted["activeWorkspaceId"]}");
```

**Notes**

- An OAuth access token needs a verification code for this call, and is refused with 403 `step_up_required` until the app has verified one in the last 60 minutes. `IsStepUpRequired` on the error says so. An API key is never asked for a code.
- The key or the app loses its workspace with it, so every later call with it is refused.
- Not retried automatically. A retry after a lost response is a 404, since the workspace is already gone.

Also available in: API [`DELETE /workspaces/{id}`](https://openemail.uk/docs/api/reference/workspaces#delete-workspaces-id); TypeScript [`workspaces.delete()`](https://openemail.uk/docs/sdk/reference/workspaces#delete); Python [`workspaces.delete()`](https://openemail.uk/docs/python/reference/workspaces#delete); Ruby [`workspaces.delete`](https://openemail.uk/docs/ruby/reference/workspaces#delete); PHP [`workspaces->delete`](https://openemail.uk/docs/php/reference/workspaces#delete); Go [`Workspaces.Delete`](https://openemail.uk/docs/go/reference/workspaces#delete); Java [`workspaces().delete`](https://openemail.uk/docs/java/reference/workspaces#delete); CLI [`openemail workspaces delete`](https://openemail.uk/docs/cli/reference/workspaces#workspaces-delete).
