Skip to Content

Create a new custom label.

Creates a new user folder or label with a fresh UID validity epoch.

openemail.labels.create(
  mailboxId: string,
  body: LabelsCreateBody,
  options?: CallOptions,
): ApiPromise<CreatedLabel>

It calls POST /mailboxes/{mailboxId}/labels: Create a new custom label in the API reference.

Example

const createdLabel = await openemail.labels.create(mailboxId, { name: 'Ada' })

Arguments

ArgumentTypeDescription
mailboxIdstringMailbox ULID identifier. The path's {mailboxId}.
bodyLabelsCreateBodyThe request's body.

Options

It takes no options of its own. Every call also takes signal, timeout, retry and headers, which say how that one call is sent (call options).

Answer

Awaited, it is the API's JSON, CreatedLabel. It is an ApiPromise: .withResponse() gives the same with the Response it came in, for its headers.

Errors

StatusWhat it means
400validation_failed — malformed name or color
401unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a WWW-Authenticate: Bearer challenge
404Mailbox not found or not accessible to this principal
409label_exists — a label with this name already exists; or too_many_labels — the mailbox is at its ceiling of 500 labels (system labels are not counted), and a retry under another name cannot help. Delete one first
413too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing
503temporary_failure: the mailbox or account is in transition while its store is being adopted; retry after Retry-After

A failed call rejects with a RequestError: its status, and its code, the API's error. Decide on the code: one status covers several.

Types

LabelsCreateBody

/** The body of `labels.create`. */
type LabelsCreateBody = {
  /** Hex color code for the label badge/chip, or null */
  color?: string | null
  /** Name for the new label. May not start with `*`, which clients reserve for their own views */
  name: string
}

It names these types of the API, each on a page of its own: CreatedLabel.