Aller à la documentation
PHP

$client->labels

Chaque méthode de cet espace de noms : sa signature, ses paramètres, ce qu'elle retourne et un exemple.

Méthodes

The user labels a thread can carry: list, create, rename, recolour and delete them, and read the palette of colours the app offers.

labels->list

List the workspace's labels, a page at a time

Portéeslabels:readParcourt les résultats page par page
Signature
list(?int $limit = null, ?string $cursor = null, ?string $apiKey = null): Page

Returns one page of the workspace's user labels, sorted by name and then by id. labels->listAll collects every page and labels->iterate walks them lazily. Each label carries its colour, threadCount (how many conversations carry it now) and createdAt and updatedAt, which is everything the Labels table in the app shows.

System labels such as INBOX, STARRED and UNREAD are not listed. A thread carries them and threads->update takes them, but they cannot be renamed, recoloured or deleted.

color is null on a label saved with no colour. Otherwise color.backgroundColor is a hex value or a gradient token such as gradient:sunset, and color.textColor is the ink the app draws on it, worked out on the server rather than stored.

Paramètres

limitint

Page size, from 1 to 100. The server defaults to 25.

cursorstring

The nextCursor of the previous page, passed back as it came. Leave it out for the first page.

apiKeystring

Overrides the client's API key for this call only.

Retourne

A Page of label arrays, with items, hasMore and nextCursor. Each item has id, name, type, color, threadCount, createdAt and updatedAt.

Exemple

$page = $client->labels->list(limit: 50); foreach ($page as $label) {    echo $label['id'], ' ', $label['name'], ' on ', $label['threadCount'], ' conversations, ', $label['color']['backgroundColor'] ?? 'no colour', PHP_EOL;} if ($page->hasMore) {    $next = $client->labels->list(limit: 50, cursor: $page->nextCursor);     echo count($next), ' more', PHP_EOL;}

Remarques

  • Labels belong to the workspace, so a narrowed key still sees every label. threadCount is the exception: it counts only conversations delivered to the addresses the key holds.

  • An id is fixed when the label is created and survives a rename, so match on id rather than name in stored configuration.

  • The sidebar order in the app is each person's own arrangement and is not exposed.

  • The cursor is opaque and holds where the last row sat in this order, so a row deleted or edited between pages never breaks the walk: the next page starts at the first row that sorts after it. A cursor this list did not hand out is a 400 invalid_cursor.

Aussi disponible dans

API
GET /labels
TypeScript
labels.list()
Python
labels.list()
Ruby
labels.list
CLI
openemail labels list

labels->listAll

Collect every label into one array

Portéeslabels:readParcourt les résultats page par page
Signature
listAll(?int $limit = null, ?string $cursor = null, ?string $apiKey = null): array

Walks every page of labels->list and returns all labels in one array, sorted by name and then by id. One request per page.

Paramètres

limitint

Page size for each request, from 1 to 100. The server defaults to 25.

cursorstring

Starts the walk after this cursor instead of the first page.

apiKeystring

Overrides the client's API key for every page of this walk.

Retourne

A list of label arrays holding every label.

Exemple

$labels = $client->labels->listAll(limit: 100); $idsByName = array_column($labels, 'id', 'name'); echo count($labels), ' labels, Receipts is ', $idsByName['Receipts'] ?? 'missing', PHP_EOL;

Remarques

  • If any page fails, the exception is thrown and the labels already fetched are discarded.

Aussi disponible dans

API
GET /labels
TypeScript
labels.listAll()
Python
labels.list_all()
Ruby
labels.list_all

labels->iterate

Stream the labels one at a time

Portéeslabels:readParcourt les résultats page par page
Signature
iterate(?int $limit = null, ?string $cursor = null, ?string $apiKey = null): Generator

Returns a Generator that yields labels one at a time, sorted by name and then by id, and requests the next page only once the current one is used up. Nothing is fetched until the loop starts, and breaking out of the foreach stops the requests.

Paramètres

limitint

Page size for each request, from 1 to 100. The server defaults to 25.

cursorstring

Starts the walk after this cursor instead of the first page.

apiKeystring

Overrides the client's API key for every page of this walk.

Retourne

A Generator that yields one label array per step.

Exemple

foreach ($client->labels->iterate() as $label) {    if ($label['threadCount'] === 0) {        echo $label['name'], ' is on no conversation', PHP_EOL;    }}

Remarques

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

Aussi disponible dans

API
GET /labels
TypeScript
labels.iterate()
Python
labels.iterate()
Ruby
labels.iterate

labels->listColors

List the colours the app offers for labels

Portéeslabels:read
Signature
listColors(?string $apiKey = null): array

Returns the whole label palette as a plain list: the fourteen solid colours and seven gradients the app offers when you make or edit a label, in the order it shows them. It is a fixed catalogue, so there is no paging. Fetch it once and keep it.

value is what to send as color.backgroundColor: a hex such as #3B82F6 for a solid, a token such as gradient:sunset for a gradient. textColor is the ink drawn on it. A gradient also carries from and to, drawn at 135 degrees, and solid, one hex for places a gradient cannot go.

A label may carry a colour outside this list. Any hex set through the API is kept as it is, and the app offers it back as its own swatch.

Paramètres

apiKeystring

Overrides the client's API key for this call only.

Retourne

A list of arrays, each with kind, name, value, solid, from, to and textColor.

Exemple

$colors = $client->labels->listColors(); foreach ($colors as $color) {    echo $color['kind'], ' ', $color['name'], ' ', $color['value'], ' with ', $color['textColor'], ' text', PHP_EOL;}

Remarques

  • kind is solid or gradient. from and to are null on a solid.

Aussi disponible dans

API
GET /labels/colors
TypeScript
labels.listColors()
Python
labels.list_colors()
Ruby
labels.list_colors
CLI
openemail labels list-colors

labels->get

Read one user label by id

Portéeslabels:read
Signature
get(string $id, ?string $apiKey = null): array

Looks up a single user label and returns it in the same shape as a row of labels->list, with its colour, threadCount, createdAt and updatedAt.

Only user labels are served. INBOX, TRASH and the other system ids are a 404 here even though threads carry them. Ids are matched exactly, so user_receipts does not find USER_RECEIPTS.

Paramètres

idstringObligatoire

Label id such as USER_RECEIPTS, matched case sensitively.

apiKeystring

Overrides the client's API key for this call only.

Retourne

An array with id, name, type set to user, color, threadCount, createdAt and updatedAt.

Exemple

use OpenEmail\Exception\NotFoundException; try {    $label = $client->labels->get('USER_RECEIPTS');     echo $label['name'], ' is on ', $label['threadCount'], ' conversations', PHP_EOL;} catch (NotFoundException) {    echo 'No such label', PHP_EOL;}

Remarques

  • A missing label throws a NotFoundException, whose isNotFound() is true and whose errorCode is resource_not_found.

Aussi disponible dans

API
GET /labels/{id}
TypeScript
labels.get()
Python
labels.get()
Ruby
labels.get
CLI
openemail labels get

labels->create

Create a user label

Portéeslabels:write
Signature
create(array $body, ?string $apiKey = null): array

Creates a label and returns it as it is stored. name is trimmed and must then be 1 to 225 characters. The id is derived from the name as USER_ followed by the name upper cased, with each run of whitespace turned into _, so Big Clients becomes USER_BIG_CLIENTS, and it never changes afterwards.

A name another label already has, compared without case, is refused with 409 label_name_taken, and so is a name whose id another label holds because it was created under that name and renamed since. An existing label is never silently overwritten. A workspace holds at most 50 user labels, and the call past that is a 422 label_limit_reached on name.

color is optional. color.backgroundColor is a hex colour (#RGB, #RGBA, #RRGGBB or #RRGGBBAA, stored upper cased) or a gradient token such as gradient:sunset, and anything else is a 422 invalid_parameter on color.backgroundColor. labels->listColors returns the palette the app offers. textColor may be sent but is ignored: the ink is worked out from the background. Leaving color out stores no colour.

Paramètres

namestringObligatoire

Display name, trimmed, 1 to 225 characters. Also decides the id.

colorarray

The colour, an array with backgroundColor. Leave it out for a label with no colour.

color.backgroundColorstring

A hex colour such as #3B82F6 or a gradient token such as gradient:sunset, at most 32 characters. Required once color is given.

color.textColorstring

Accepted and ignored. The ink is worked out from backgroundColor.

apiKeystring

Overrides the client's API key for this call only.

Retourne

An array with the new id, the trimmed name, color, threadCount of 0, createdAt and updatedAt.

Exemple

use OpenEmail\Exception\ConflictException; try {    $label = $client->labels->create([        'name' => 'Big Clients',        'color' => ['backgroundColor' => '#3B82F6'],    ]);     echo 'Created ', $label['id'], PHP_EOL;} catch (ConflictException $error) {    echo 'That name is taken: ', $error->errorCode, PHP_EOL;}

Remarques

  • The SDK does not retry a create after a network failure. If you retry by hand after a lost response, a 409 label_name_taken means the first attempt succeeded.

Aussi disponible dans

API
POST /labels
TypeScript
labels.create()
Python
labels.create()
Ruby
labels.create
CLI
openemail labels create

labels->update

Rename or recolour a user label

Portéeslabels:write
Signature
update(string $id, array $patch, ?string $apiKey = null): array

Renames a label, recolours it, or both, and returns it as it is stored. Send name, color or both: a field left out stays as it is, and a patch with neither is a 422. 'color' => null, or an empty backgroundColor, clears the colour.

The id never changes. A label created as Receipts keeps USER_RECEIPTS after a rename to Invoices, and every thread keeps the label. A new name another label already has, compared without case, is refused with 409 label_name_taken.

Colours follow the rules on labels->create: a hex value or a gradient token, and anything else is a 422 invalid_parameter. Only user labels can be changed, and a system label id is a 404.

Paramètres

idstringObligatoire

Label id such as USER_RECEIPTS.

namestring

New display name, trimmed, 1 to 225 characters. Left out, the name stays.

colorarray|null

New colour, an array with backgroundColor. Null clears it, and leaving it out keeps the stored colour.

color.backgroundColorstring

A hex colour or a gradient token, at most 32 characters. An empty string clears the colour.

color.textColorstring

Accepted and ignored. The ink is worked out from backgroundColor.

apiKeystring

Overrides the client's API key for this call only.

Retourne

An array with the unchanged id and the new name and color.

Exemple

$label = $client->labels->update('USER_RECEIPTS', [    'name' => 'Invoices',    'color' => ['backgroundColor' => 'gradient:sunset'],]); echo $label['id'], ' is now called ', $label['name'], PHP_EOL; $client->labels->update('USER_RECEIPTS', ['color' => null]);

Remarques

  • The SDK retries this call after a network failure, since the same patch sent twice leaves the same label.

Aussi disponible dans

API
PATCH /labels/{id}
TypeScript
labels.update()
Python
labels.update()
Ruby
labels.update
CLI
openemail labels update

labels->delete

Delete a user label and remove it from every thread

Portéeslabels:write
Signature
delete(string $id, ?string $apiKey = null): array

Deletes a user label and, in the same transaction, takes it off every thread that carried it. The threads are otherwise untouched, so a thread that was only filed under this label stays in whatever folder it was in.

There is no undo. Creating a label with the same name again produces the same id, but the threads it was removed from do not get it back. Only user labels can be deleted, and a system label id is a 404.

Paramètres

idstringObligatoire

Label id such as USER_OLD_PROJECT.

apiKeystring

Overrides the client's API key for this call only.

Retourne

An array with object set to label, id and deleted set to true.

Exemple

$label = $client->labels->get('USER_OLD_PROJECT'); $deleted = $client->labels->delete($label['id']); if ($deleted['deleted']) {    echo 'Removed from ', $label['threadCount'], ' conversations', PHP_EOL;}

Remarques

  • The SDK does not retry a delete. A 404 on your own second attempt after a lost response means the first one worked.

  • Call labels->get first if you want to say how many conversations will lose the label: its threadCount is that number.

Aussi disponible dans

API
DELETE /labels/{id}
TypeScript
labels.delete()
Python
labels.delete()
Ruby
labels.delete
CLI
openemail labels delete