---
title: "client.exports"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://openemail.uk/docs/ruby/reference/exports"
area: "Ruby"
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.preview`

See what an export would hold

```ruby
preview(api_key: nil) -> Hash
```

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 nil.

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**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

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

**Example**

```ruby
preview = client.exports.preview

puts "An export can start now: #{preview[:counts]}" if preview[:allowed] && preview[:nextAvailableAt].nil?
```

**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); CLI [`openemail exports preview`](https://openemail.uk/docs/cli/reference/exports#exports-preview).

### `exports.list`

List the exports

```ruby
list(limit: nil, offset: nil, api_key: nil) -> Hash
```

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` (`Integer`): Exports per page, from 1 to 100. The server defaults to 25.
- `offset` (`Integer`): How many exports to skip.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash, not an `OpenEmail::Page`, with `data`, an Array of export Hashes shaped like the one `get` returns, plus `total` and `hasMore`. Ask for the next page with `offset:`.

**Example**

```ruby
exports = client.exports.list

ready = exports[:data].find { |item| item[:status] == "ready" }
puts ready[:id], ready[:fileName] if ready
```

**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); CLI [`openemail exports list`](https://openemail.uk/docs/cli/reference/exports#exports-list).

### `exports.get`

Retrieve an export

```ruby
get(id, api_key: nil) -> Hash
```

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 `start` or `list`.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

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

**Example**

```ruby
item = client.exports.get("exp_8c1e4a7f2b9d3e6a0c5f1b28")

puts item[:status], item[:threadsDone], item[:threadsTotal]
```

**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); CLI [`openemail exports get`](https://openemail.uk/docs/cli/reference/exports#exports-get).

### `exports.start`

Start an export

```ruby
start(api_key: nil) -> Hash
```

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 `get` until `status` is `ready`, then `download` 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**

- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A Hash for the new export, shaped like the one `get` returns.

**Example**

```ruby
started = client.exports.start

puts started[:id], started[:status]
```

**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); CLI [`openemail exports start`](https://openemail.uk/docs/cli/reference/exports#exports-start).

### `exports.download`

Download an export

```ruby
download(id, api_key: nil) -> String
```

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 `start` or `list`.
- `api_key` (`String`): Overrides the client's API key for this call only.

**Returns**

A binary String holding the zip.

**Example**

```ruby
item = client.exports.get("exp_8c1e4a7f2b9d3e6a0c5f1b28")
zip = client.exports.download(item[:id])

File.binwrite(item[:fileName] || "export.zip", zip)
```

**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); CLI [`openemail exports download`](https://openemail.uk/docs/cli/reference/exports#exports-download).
