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

# client.Exports

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

## Methods

A zip of the whole workspace, as the Export page makes it: see what it would hold, start one, follow it while it is made and download it once it is ready.

### `Exports.PreviewAsync`

See what an export would hold

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

Returns whether the workspace can be exported by the caller now, when the next export can start, the export still being made, if there is one, and how much an export would hold: conversations, attachments and their size, contacts, audiences, calendar events, templates, rules, labels, notes and addresses. When `allowed` is false, `reason` says why and `counts` is null.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

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

**Returns**

A `JsonObject` with `allowed`, `reason`, `nextAvailableAt`, `activeExportId` and `counts`, an object of `threads`, `attachments`, `attachmentBytes`, `deletedFiles`, `contacts`, `audiences`, `calendarEvents`, `templates`, `rules`, `labels`, `notes` and `addresses`.

**Example**

```csharp
var preview = await client.Exports.PreviewAsync();

if ((bool?)preview["allowed"] != true)
{
    Console.WriteLine($"Cannot export: {preview["reason"]}");
}
else if (preview["activeExportId"] is not null)
{
    Console.WriteLine($"Export {preview["activeExportId"]} is still being made");
}
else
{
    Console.WriteLine($"{preview["counts"]?["threads"]} conversations and {preview["counts"]?["attachments"]} attachments");
}
```

**Notes**

- `reason` is `not-permitted`, `mailbox-login` or `two-factor-required`.

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

### `Exports.ListAsync`

List the exports

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

Returns every export of the workspace, newest first, a page at a time, with its status, its progress through the conversations and, once it is `ready`, its size, file name and when it is deleted.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

- `limit` (`int?`): Exports per page, from 1 to 100. The server defaults to 25.
- `offset` (`int?`): How many exports to skip.
- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject`, not a `Page`, with `data`, a list of export objects shaped like the one `Exports.GetAsync` returns, plus `total` and `hasMore`. Ask for the next page with `offset:`.

**Example**

```csharp
using OpenEmail.Constants;

var exports = await client.Exports.ListAsync(limit: 10);

foreach (var export in exports["data"]?.AsArray() ?? [])
{
    if ((string?)export?["status"] == ExportStatuses.Ready)
    {
        Console.WriteLine($"{export?["id"]} {export?["fileName"]} {export?["sizeBytes"]} bytes, kept until {export?["expiresAt"]}");
    }
}
```

**Notes**

- A workspace can be exported once a day, and each export is kept for a year, so the list stays short.

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

### `Exports.GetAsync`

Retrieve an export

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

Returns one export: its `status`, `phase` and progress while it is made, and once it is `ready` its size, file name and when it is deleted.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

- `id` (`string`, required): The export id from `Exports.StartAsync` or `Exports.ListAsync`.
- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A `JsonObject` with `id`, `status`, `phase`, `createdAt`, `createdBy`, `startedAt`, `finishedAt`, `expiresAt`, `sizeBytes`, `fileName`, `threadsDone`, `threadsTotal` and `error`.

**Example**

```csharp
var export = await client.Exports.GetAsync("exp_8c1e4a7f2b9d3e6a0c5f1b28");

Console.WriteLine($"{export["status"]} {export["error"]}");
```

**Notes**

- An unknown id is a 404.

Also available in: API [`GET /exports/{id}`](https://openemail.uk/docs/api/reference/exports#get-exports-id); TypeScript [`exports.get()`](https://openemail.uk/docs/sdk/reference/exports#get); Python [`exports.get()`](https://openemail.uk/docs/python/reference/exports#get); Ruby [`exports.get`](https://openemail.uk/docs/ruby/reference/exports#get); PHP [`exports->get`](https://openemail.uk/docs/php/reference/exports#get); Go [`Exports.Get`](https://openemail.uk/docs/go/reference/exports#get); Java [`exports().get`](https://openemail.uk/docs/java/reference/exports#get); CLI [`openemail exports get`](https://openemail.uk/docs/cli/reference/exports#exports-get).

### `Exports.StartAsync`

Start an export

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

Starts making a zip of the whole workspace, as Export now on the Export page does, and returns the export, `queued`. It is made in the background: poll `Exports.GetAsync` until `status` is `ready`, then `Exports.DownloadAsync` it. One export runs at a time, and a workspace can be exported once a day.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

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

**Returns**

A `JsonObject` for the new export, shaped like the one `Exports.GetAsync` returns.

**Example**

```csharp
try
{
    var export = await client.Exports.StartAsync();

    Console.WriteLine($"Export {export["id"]} is {export["status"]}");
}
catch (OpenEmailApiException error)
{
    Console.WriteLine($"Not now: {error.Message}");
}
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`. An API key is never asked.
- An export already being made is 409 `already_running`, and a workspace exported in the last day is 429 `export_limit_reached`.
- The SDK does not retry it.

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

### `Exports.DownloadAsync`

Download an export

```csharp
Task<byte[]> DownloadAsync(
    string id,
    string? apiKey = null,
    CancellationToken cancellationToken = default)
```

Returns the zip of a `ready` export, the same file the Download action on the Export page saves.

Only the workspace owner, or a member whose role holds every permission, can export the workspace: an API key, or an access token connected with every address. A key or token limited to particular addresses or domains is 422 `capability_unsupported`, and an account the workspace cannot export for is 403 `export_not_permitted`.

Scopes: `threads:read`.

**Parameters**

- `id` (`string`, required): The export id from `Exports.StartAsync` or `Exports.ListAsync`.
- `apiKey` (`string?`): Overrides the client's API key for this call only.
- `cancellationToken` (`CancellationToken`): Cancels the request.

**Returns**

A string holding the bytes of the zip.

**Example**

```csharp
var export = await client.Exports.GetAsync("exp_8c1e4a7f2b9d3e6a0c5f1b28");

var zip = await client.Exports.DownloadAsync(export["id"]!.GetValue<string>());

Console.WriteLine($"{zip.Length} bytes saved");
```

**Notes**

- With an OAuth access token it asks for a verification code: until the app has verified one, it is refused with 403 `step_up_required`. An API key is never asked.
- Before the export is `ready` the call is 409 `export_not_ready`, and an export older than a year is 409 `expired`.
- The whole zip is held in memory, and a large workspace makes a large zip.

Also available in: API [`GET /exports/{id}/content`](https://openemail.uk/docs/api/reference/exports#get-exports-id-content); TypeScript [`exports.download()`](https://openemail.uk/docs/sdk/reference/exports#download); Python [`exports.download()`](https://openemail.uk/docs/python/reference/exports#download); Ruby [`exports.download`](https://openemail.uk/docs/ruby/reference/exports#download); PHP [`exports->download`](https://openemail.uk/docs/php/reference/exports#download); Go [`Exports.Download`](https://openemail.uk/docs/go/reference/exports#download); Java [`exports().download`](https://openemail.uk/docs/java/reference/exports#download); CLI [`openemail exports download`](https://openemail.uk/docs/cli/reference/exports#exports-download).
