---
title: "openemail.imports"
description: "Every method in this namespace: its signature, its parameters, what it returns and an example."
url: "https://openemail.uk/docs/sdk/reference/imports"
area: "SDK"
category: "Reference"
---

# openemail.imports

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

## Methods

Bring an old mailbox across from a Google Takeout, .mbox, .eml, .zip or .tgz export, with progress and a list of what did not come through.

### `imports.list()`

List one page of mailbox imports

```ts
list(options?: ImportListOptions): Promise<Page<ImportResource>>
```

Returns one page of the imports in the workspace, newest first. Nothing is dropped from the history, so following `nextCursor` while `hasMore` is true reaches the very first import, and `listAll` and `iterate` do that walk for you. Each carries its status, the bytes read so far out of the total, and running counts of messages seen, imported, skipped as duplicates, left out by your options and not imported.

A key limited to particular addresses sees only imports into those addresses.

Scopes: `threads:read`.

**Parameters**

- `options.addressId` (`string`): Only imports into this address.
- `options.limit` (`number`): Rows per page, a whole number from 1 to 100. The server defaults to 25.
- `options.cursor` (`string`): The `nextCursor` from the previous page, an import id. One that names no import this key can see is a 400 `invalid_cursor`.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`Page<ImportResource>` with `items`, `hasMore` and `nextCursor`.

**Example**

```ts
const page = await openemail.imports.list({ limit: 50 })

for (const item of page.items) {
    console.log(item.address, item.status, item.counts.imported)
}
```

**Notes**

- A GET is retried automatically on network failure and on 408, 429 and 5xx responses, up to the client `maxRetries`.

Also available in: API [`GET /imports`](https://openemail.uk/docs/api/reference/imports#get-imports); CLI [`openemail imports list`](https://openemail.uk/docs/cli/reference/imports#imports-list).

### `imports.listAll()`

Collect every mailbox import into one array

```ts
listAll(options?: ImportListOptions): Promise<Array<ImportResource>>
```

Follows `nextCursor` from page to page and resolves with every import in the workspace, newest first, narrowed to one address when `addressId` is given. A key limited to particular addresses sees only imports into those addresses.

Scopes: `threads:read`.

**Parameters**

- `options.addressId` (`string`): Only imports into this address.
- `options.limit` (`number`): Page size per request, from 1 to 100, defaulting to 25 on the server.
- `options.cursor` (`string`): An import id to start after, skipping everything newer.
- `options.signal` (`AbortSignal`): Cancels the request in flight and rejects the whole walk.
- `options.apiKey` (`string`): Overrides the client API key for every page of this walk.

**Returns**

`Array<ImportResource>` holding every import across all pages.

**Example**

```ts
const imports = await openemail.imports.listAll()

const failed = imports.filter((item) => item.status === 'failed')

console.log(`${failed.length} of ${imports.length} imports failed`)
```

**Notes**

- A failure on any page rejects the whole call.

Also available in: API [`GET /imports`](https://openemail.uk/docs/api/reference/imports#get-imports).

### `imports.iterate()`

Stream mailbox imports one at a time

```ts
iterate(options?: ImportListOptions): AsyncGenerator<ImportResource, void, undefined>
```

Returns an async generator that yields imports individually, newest first, and requests the next page only once the current one is drained. Breaking out of the loop stops the requests.

Scopes: `threads:read`.

**Parameters**

- `options.addressId` (`string`): Only imports into this address.
- `options.limit` (`number`): Page size per request, from 1 to 100, defaulting to 25 on the server.
- `options.cursor` (`string`): An import id to start after, skipping everything newer.
- `options.signal` (`AbortSignal`): Cancels the request in flight and rejects the whole walk.
- `options.apiKey` (`string`): Overrides the client API key for every page of this walk.

**Returns**

`AsyncGenerator<ImportResource, void, undefined>` yielding one import per step.

**Example**

```ts
for await (const item of openemail.imports.iterate({ addressId: 'addr_2b7e' })) {
    if (item.status === 'running') {
        console.log(item.id, item.counts.imported)
        break
    }
}
```

**Notes**

- The generator is lazy, so an abandoned loop costs only the pages you consumed.

Also available in: API [`GET /imports`](https://openemail.uk/docs/api/reference/imports#get-imports).

### `imports.get()`

Read one mailbox import

```ts
get(id: string, options?: RequestScope): Promise<ImportResource>
```

Resolves one import with its status, byte progress and counts. Poll it while `status` is `queued` or `running`; it settles on `completed`, `failed` or `cancelled`.

An id from another workspace answers exactly like one that never existed, with 404.

Scopes: `threads:read`.

**Parameters**

- `id` (`string`, required): Import id, `imp_` followed by 24 hex characters.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportResource`.

**Example**

```ts
const item = await openemail.imports.get('imp_3f9c2a7b1e4d8f60a5c7b92d')

console.log(item.status, item.processedBytes, '/', item.totalBytes)
```

**Notes**

- `lastError` is set only when `status` is `failed`.

Also available in: API [`GET /imports/{id}`](https://openemail.uk/docs/api/reference/imports#get-imports-id); CLI [`openemail imports get`](https://openemail.uk/docs/cli/reference/imports#imports-get).

### `imports.create()`

Create a mailbox import and get its upload plan

```ts
create(body: ImportCreate, options?: RequestScope): Promise<ImportResource>
```

Creates an import into one address of the workspace and returns it with `status: uploading`. Each file is uploaded in parts of `chunkBytes`, `files[i].chunks` of them, through `uploadChunk`, and `start` then queues the import.

The import reads Google Takeout archives, .mbox files from Apple Mail, Thunderbird and most desktop apps, .eml files, and .zip or .tgz archives holding any of those, up to 100 GB a file and 50 files an import. Threads, dates and labels come across. Imported mail is quiet: it runs no rules, forwards, notifications, summaries or webhooks.

`importFiles` does create, upload and start in one call.

Scopes: `threads:write`.

**Parameters**

- `body.addressId` (`string`, required): The address the mail belongs to. It must be an address this workspace owns and this key may act for.
- `body.files` (`Array<ImportFileDescriptor>`, required): Each file as `{ name, bytes }`, 1 to 50 of them, each at most 100 GB.
- `body.options.keepInbox` (`boolean`): Default true: mail that was in the old inbox lands in Inbox with its unread state. False files everything under Archive.
- `body.options.includeSpam` (`boolean`): Default false.
- `body.options.includeTrash` (`boolean`): Default false.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportResource` with `status: uploading`, `chunkBytes` and each file's `chunks`.

**Example**

```ts
const item = await openemail.imports.create({
    addressId: 'addr_2b7e',
    files: [{ name: 'takeout-001.zip', bytes: 2147483648 }]
})

console.log(item.chunkBytes, item.files[0].chunks)
```

**Notes**

- An address with an import already queued or running is 409 `already_running`.
- Not retried automatically.

Also available in: API [`POST /imports`](https://openemail.uk/docs/api/reference/imports#post-imports); CLI [`openemail imports create`](https://openemail.uk/docs/cli/reference/imports#imports-create).

### `imports.uploadState()`

See which parts of the upload have arrived

```ts
uploadState(id: string, options?: RequestScope): Promise<ImportUploadResource>
```

For each file, the indexes of the parts already stored, so an interrupted upload sends only what is missing. Empty once the import has left the `uploading` state.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): Import id, `imp_` followed by 24 hex characters.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportUploadResource` with `received`, one sorted array of part indexes per file.

**Example**

```ts
const state = await openemail.imports.uploadState('imp_3f9c2a7b1e4d8f60a5c7b92d')

console.log(state.received[0].length)
```

Also available in: API [`GET /imports/{id}/upload`](https://openemail.uk/docs/api/reference/imports#get-imports-id-upload); CLI [`openemail imports upload-state`](https://openemail.uk/docs/cli/reference/imports#imports-upload-state).

### `imports.uploadChunk()`

Upload one part of an import file

```ts
uploadChunk(id: string, file: number, chunk: number, data: RawBody, options?: RequestScope): Promise<ImportChunkResource>
```

Stores one part of file `file`: the bytes from `chunk * chunkBytes` up to the next part. Every part is exactly `chunkBytes` long except the last, and a part of the wrong length is 400 `bad_chunk`. Sending a part again replaces it, so a failed part can simply be retried.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): Import id, `imp_` followed by 24 hex characters.
- `file` (`number`, required): The file index, in the order given to `create`.
- `chunk` (`number`, required): The part index, from 0.
- `data` (`RawBody`, required): The part as a `Blob`, `Uint8Array` or `ArrayBuffer`.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportChunkResource` echoing `file`, `chunk` and the `bytes` stored.

**Example**

```ts
await openemail.imports.uploadChunk(item.id, 0, 0, bytes.subarray(0, item.chunkBytes))
```

**Notes**

- Retried automatically on network failure and on 408, 429 and 5xx responses, since a repeated part replaces itself.

Also available in: API [`PUT /imports/{id}/files/{file}/chunks/{chunk}`](https://openemail.uk/docs/api/reference/imports#put-imports-id-files-file-chunks-chunk); CLI [`openemail imports upload-chunk`](https://openemail.uk/docs/cli/reference/imports#imports-upload-chunk).

### `imports.start()`

Queue an import once its files are uploaded

```ts
start(id: string, options?: RequestScope): Promise<ImportResource>
```

Checks that every part of every file has arrived, recognises each file's format and queues the import. A file still missing parts is 412 `missing_chunks`, and a file that is not an archive or a mailbox is 400 `unsupported_file`. Calling it on an import that has already left `uploading` returns it unchanged.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): Import id, `imp_` followed by 24 hex characters.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportResource` with `status: queued`.

**Example**

```ts
const queued = await openemail.imports.start(item.id)

console.log(queued.status)
```

Also available in: API [`POST /imports/{id}/start`](https://openemail.uk/docs/api/reference/imports#post-imports-id-start); CLI [`openemail imports start`](https://openemail.uk/docs/cli/reference/imports#imports-start).

### `imports.cancel()`

Cancel a mailbox import

```ts
cancel(id: string, options?: RequestScope): Promise<ImportResource>
```

Stops an import at its next checkpoint. Mail already imported stays in the mailbox. A finished import is 409 `not_cancellable`.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): Import id, `imp_` followed by 24 hex characters.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportResource` with `status: cancelled`.

**Example**

```ts
await openemail.imports.cancel('imp_3f9c2a7b1e4d8f60a5c7b92d')
```

Also available in: API [`POST /imports/{id}/cancel`](https://openemail.uk/docs/api/reference/imports#post-imports-id-cancel); CLI [`openemail imports cancel`](https://openemail.uk/docs/cli/reference/imports#imports-cancel).

### `imports.listFailures()`

List what an import could not bring across

```ts
listFailures(id: string, options?: ImportFailuresOptions): Promise<ImportFailurePage>
```

Each message or archive entry that did not come across, with the reason: `too-large` (over 50 MB), `unparseable`, `no-date`, `storage-error`, `unreadable-entry`, `encrypted-entry` or `archive-limit`. Page with `after`, passing the `nextCursor` of the previous page.

Scopes: `threads:read`.

**Parameters**

- `id` (`string`, required): Import id, `imp_` followed by 24 hex characters.
- `options.after` (`number`): The `nextCursor` of the previous page.
- `options.limit` (`number`): At most 100, the default.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportFailurePage` with `data` and `nextCursor`.

**Example**

```ts
const page = await openemail.imports.listFailures(item.id)

for (const failure of page.data) console.log(failure.reason, failure.subject)
```

Also available in: API [`GET /imports/{id}/failures`](https://openemail.uk/docs/api/reference/imports#get-imports-id-failures); CLI [`openemail imports list-failures`](https://openemail.uk/docs/cli/reference/imports#imports-list-failures).

### `imports.deleteUpload()`

Delete the files uploaded for an import

```ts
deleteUpload(id: string, options?: RequestScope): Promise<ImportResource>
```

Removes the uploaded archive. Mail already imported stays in the mailbox. An import still uploading is cancelled at the same time, and one that is queued or running is 409 `still_running`.

Scopes: `threads:write`.

**Parameters**

- `id` (`string`, required): Import id, `imp_` followed by 24 hex characters.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportResource` with `uploadDeleted: true`.

**Example**

```ts
await openemail.imports.deleteUpload('imp_3f9c2a7b1e4d8f60a5c7b92d')
```

Also available in: API [`DELETE /imports/{id}/upload`](https://openemail.uk/docs/api/reference/imports#delete-imports-id-upload); CLI [`openemail imports delete-upload`](https://openemail.uk/docs/cli/reference/imports#imports-delete-upload).

### `imports.importFiles()`

Create, upload and start an import in one call

```ts
importFiles(input: ImportFilesInput, options?: RequestScope): Promise<ImportResource>
```

Creates the import, uploads every file part by part and starts it, reporting progress through `onProgress`. Pass each file as a `Blob`, `Uint8Array` or `ArrayBuffer`; parts are sliced from it, so a `Blob` backed by a file on disk is never read into memory at once.

It resolves once the import is queued. Poll `get` to follow it.

Scopes: `threads:write`.

**Parameters**

- `input.addressId` (`string`, required): The address the mail belongs to.
- `input.files` (`Array<ImportSource>`, required): Each file as `{ name, data }`.
- `input.options` (`ImportOptions`): `keepInbox`, `includeSpam` and `includeTrash`, as for `create`.
- `input.onProgress` (`ImportProgress`): Called after each part with the bytes uploaded and the total.
- `options.signal` (`AbortSignal`): Cancels the request.
- `options.apiKey` (`string`): Overrides the client API key for this call only.

**Returns**

`ImportResource` with `status: queued`.

**Example**

```ts
import { openAsBlob } from 'node:fs'

const takeout = await openAsBlob('takeout-001.zip')

const item = await openemail.imports.importFiles({
    addressId: 'addr_2b7e',
    files: [{ name: 'takeout-001.zip', data: takeout }],
    onProgress: (done, total) => console.log(Math.round((done / total) * 100) + '%')
})
```

**Notes**

- If a part fails after its retries, the import is left in `uploading`; `uploadState` then tells you which parts to send before calling `start`.

Also available in: API [`POST /imports`](https://openemail.uk/docs/api/reference/imports#post-imports); CLI [`openemail imports import-files`](https://openemail.uk/docs/cli/reference/imports#imports-import-files).
