$client->exports
Jede Methode in diesem Namespace: ihre Signatur, ihre Parameter, was sie zurückgibt und ein Beispiel.
Methoden
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(?string $apiKey = null): arrayReturns 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.
Parameter
apiKeystringOverrides the client's API key for this call only.
Rückgabe
An array with allowed, reason, nextAvailableAt, activeExportId and counts, an array of threads, attachments, attachmentBytes, deletedFiles, contacts, audiences, calendarEvents, templates, rules, labels, notes and addresses.
Beispiel
$preview = $client->exports->preview(); if (!$preview['allowed']) { echo 'Cannot export: ', $preview['reason'], PHP_EOL;} elseif ($preview['activeExportId'] !== null) { echo 'Export ', $preview['activeExportId'], ' is still being made', PHP_EOL;} else { echo $preview['counts']['threads'], ' conversations and ', $preview['counts']['attachments'], ' attachments', PHP_EOL;}Hinweise
reasonisnot-permitted,mailbox-loginortwo-factor-required.
Auch verfügbar über
- API
GET /exports/preview- TypeScript
exports.preview()- Python
exports.preview()- Ruby
exports.preview- CLI
openemail exports preview
exports->list
List the exports
list(?int $limit = null, ?int $offset = null, ?string $apiKey = null): arrayReturns 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.
Parameter
limitintExports per page, from 1 to 100. The server defaults to 25.
offsetintHow many exports to skip.
apiKeystringOverrides the client's API key for this call only.
Rückgabe
An array, not a Page, with data, a list of export arrays shaped like the one exports->get returns, plus total and hasMore. Ask for the next page with offset:.
Beispiel
use OpenEmail\Constants\ExportStatuses; $exports = $client->exports->list(limit: 10); foreach ($exports['data'] as $export) { if ($export['status'] === ExportStatuses::READY) { echo $export['id'], ' ', $export['fileName'], ' ', $export['sizeBytes'], ' bytes, kept until ', $export['expiresAt'], PHP_EOL; }}Hinweise
A workspace can be exported once a day, and each export is kept for a year, so the list stays short.
Auch verfügbar über
- API
GET /exports- TypeScript
exports.list()- Python
exports.list()- Ruby
exports.list- CLI
openemail exports list
exports->get
Retrieve an export
get(string $id, ?string $apiKey = null): arrayReturns 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.
Parameter
idstringErforderlichThe export id from
exports->startorexports->list.apiKeystringOverrides the client's API key for this call only.
Rückgabe
An array with id, status, phase, createdAt, createdBy, startedAt, finishedAt, expiresAt, sizeBytes, fileName, threadsDone, threadsTotal and error.
Beispiel
use OpenEmail\Constants\ExportStatuses; $export = $client->exports->get('exp_8c1e4a7f2b9d3e6a0c5f1b28'); while (in_array($export['status'], [ExportStatuses::QUEUED, ExportStatuses::RUNNING], true)) { echo $export['phase'], ': ', $export['threadsDone'], ' of ', $export['threadsTotal'], PHP_EOL; sleep(10); $export = $client->exports->get($export['id']);} echo $export['status'], ' ', $export['error'] ?? '', PHP_EOL;Hinweise
An unknown id is a 404.
Auch verfügbar über
- API
GET /exports/{id}- TypeScript
exports.get()- Python
exports.get()- Ruby
exports.get- CLI
openemail exports get
exports->start
Start an export
start(?string $apiKey = null): arrayStarts 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->get until status is ready, then exports->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.
Parameter
apiKeystringOverrides the client's API key for this call only.
Rückgabe
An array for the new export, shaped like the one exports->get returns.
Beispiel
use OpenEmail\Exception\ApiException; try { $export = $client->exports->start(); echo 'Export ', $export['id'], ' is ', $export['status'], PHP_EOL;} catch (ApiException $error) { if (!in_array($error->errorCode, ['already_running', 'export_limit_reached'], true)) { throw $error; } echo 'Not now: ', $error->getMessage(), PHP_EOL;}Hinweise
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.
Auch verfügbar über
- API
POST /exports- TypeScript
exports.start()- Python
exports.start()- Ruby
exports.start- CLI
openemail exports start
exports->download
Download an export
download(string $id, ?string $apiKey = null): stringReturns 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.
Parameter
idstringErforderlichThe export id from
exports->startorexports->list.apiKeystringOverrides the client's API key for this call only.
Rückgabe
A string holding the bytes of the zip.
Beispiel
$export = $client->exports->get('exp_8c1e4a7f2b9d3e6a0c5f1b28'); $zip = $client->exports->download($export['id']); file_put_contents(basename($export['fileName'] ?? 'export.zip'), $zip); echo strlen($zip), ' bytes saved', PHP_EOL;Hinweise
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.
Auch verfügbar über
- API
GET /exports/{id}/content- TypeScript
exports.download()- Python
exports.download()- Ruby
exports.download- CLI
openemail exports download