openemail.exports
Каждый метод этого пространства имён: его сигнатура, параметры, что он возвращает, и пример.
Методы
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
preview(options?: RequestScope): Promise<ExportPreviewResource>Resolves 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.
Параметры
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Возвращает
ExportPreviewResource with allowed, reason, nextAvailableAt, activeExportId and counts.
Пример
const preview = await openemail.exports.preview() if (preview.allowed && !preview.nextAvailableAt) console.log('an export can start now', preview.counts)Примечания
reasonisnot-permitted,mailbox-loginortwo-factor-required.
Также доступно в
exports.list()
List the exports
list(options?: ExportListOptions): Promise<ExportListResource>Resolves 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.
Параметры
options.limitnumberExports per page, from 1 to 100. The server defaults to 25.
options.offsetnumberHow many exports to skip.
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Возвращает
ExportListResource with data, total and hasMore.
Пример
const { data } = await openemail.exports.list() const ready = data.find((item) => item.status === 'ready')Примечания
A workspace can be exported once a day, and each export is kept for a year, so the list stays short.
Также доступно в
exports.get()
Retrieve an export
get(id: string, options?: RequestScope): Promise<ExportResource>Resolves 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.
Параметры
idstringОбязательноThe export id from
startorlist.options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Возвращает
ExportResource.
Пример
const item = await openemail.exports.get('exp_8c1e4a7f2b9d3e6a0c5f1b28') console.log(item.status, item.threadsDone, item.threadsTotal)Примечания
An unknown id is a 404.
Также доступно в
exports.start()
Start an export
start(options?: RequestScope): Promise<ExportResource>Starts making a zip of the whole workspace, as Export now on the Export page does, and resolves with 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.
Параметры
options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Возвращает
ExportResource for the new export.
Пример
const started = await openemail.exports.start() console.log(started.id, started.status)Примечания
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 429export_limit_reached.The SDK does not retry it.
Также доступно в
exports.download()
Download an export
download(id: string, options?: RequestScope): Promise<Uint8Array>Resolves with 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.
Параметры
idstringОбязательноThe export id from
startorlist.options.signalAbortSignalCancels the request.
options.apiKeystringOverrides the client's API key for this call only.
Возвращает
Uint8Array holding the zip.
Пример
import { writeFile } from 'node:fs/promises' const item = await openemail.exports.get('exp_8c1e4a7f2b9d3e6a0c5f1b28')const zip = await openemail.exports.download(item.id) await writeFile(item.fileName ?? 'export.zip', zip)Примечания
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
readythe call is 409export_not_ready, and an export older than a year is 409expired.The whole zip is held in memory, and a large workspace makes a large zip.