Skip to Content

Update flags, labels and keywords for every message in a folder, by label id.

Keyed on the label's numeric id — as GET /labels and POST /labels report it — rather than on its name. The id survives a rename (it is what JMAP Mailbox/set and folder-scoped shares key on), so a client that renames folders should hold it: the by-name route's key changes as the operation succeeds. It also never contains a /, so a folder name that does need not be encoded into a path segment. Otherwise identical to the by-name operation.

This is the spelling a browser client needs: a nested folder IS the label called Work/Projects, and a name carrying a / cannot be a path segment.

openemail.labels.updateMessagesById(
  mailboxId: string,
  labelId: number,
  body?: LabelsUpdateMessagesByIdBody,
  options?: CallOptions,
): ApiPromise<LabelMessagesUpdateResult>

It calls PATCH /mailboxes/{mailboxId}/labels/by-id/{labelId}/messages: Update flags, labels and keywords for every message in a folder, by label id in the API reference.

Example

const labelMessagesUpdateResult = await openemail.labels.updateMessagesById(mailboxId, labelId, {})

Arguments

ArgumentTypeDescription
mailboxIdstringMailbox ULID identifier. The path's {mailboxId}.
labelIdnumberThe label's numeric id, as GET /labels and POST /labels report it. The path's {labelId}.
bodyLabelsUpdateMessagesByIdBodyOptional. The 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, LabelMessagesUpdateResult. It is an ApiPromise: .withResponse() gives the same with the Response it came in, for its headers.

Errors

StatusWhat it means
400As the by-name route
401unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a WWW-Authenticate: Bearer challenge
404Mailbox or label not found, or outside this principal's folder grant
409uid_validity_mismatch — the label's UIDVALIDITY is not the one given
413too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing
503temporary_failure: the platform's storage could not answer just now; retry after the Retry-After window. Any operation can answer this. A write that got it may have been applied, so retry it with the same idempotency key where it takes one, or read the state back first (see Transient failures in the API description)

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

LabelsUpdateMessagesByIdBody

/** The body of `labels.updateMessagesById`. */
type LabelsUpdateMessagesByIdBody = {
  /** Continuation cursor: resume above this UID. Pass the previous call's `nextAfter`. */
  after?: number
  /** Flags to remove */
  flagsClear?: ('seen' | 'answered' | 'flagged' | 'draft' | 'deleted')[]
  /** Flags to set */
  flagsSet?: ('seen' | 'answered' | 'flagged' | 'draft' | 'deleted')[]
  /** Narrow the selection to messages with ALL of these flags set */
  hasFlags?: ('seen' | 'answered' | 'flagged' | 'draft' | 'deleted')[]
  /** Custom keywords to remove */
  keywordsClear?: string[]
  /** Exact replacement list of custom keywords */
  keywordsExact?: string[]
  /** Custom keywords to add */
  keywordsSet?: string[]
  /** Labels to add */
  labelsAdd?: string[]
  /** Exact replacement list of labels */
  labelsExact?: string[]
  /** Labels to remove */
  labelsRemove?: string[]
  /** Lower the per-call update budget, for a client that wants finer progress than the server's own bound gives. Never raises it. */
  limit?: number
  /** Narrow the selection to messages with NONE of these set — `["seen"]` for the unread-only gesture a folder's unread badge implies */
  notFlags?: ('seen' | 'answered' | 'flagged' | 'draft' | 'deleted')[]
  /** What to do if this write would leave the message with no label. 'expunge' (the default) sends the message to Recently deleted. 'archive' keeps the message live by attaching the Archive system label (attaching Archive needs no right beyond the grant's 't' for a scoped viewer). If the write removes Archive itself and would leave no labels, Archive is kept without error. A SCOPED viewer whose write lands the message in Archive has moved it out of their own scope: the answer is still `updated`, and the hydrated message carries an EMPTY `labels` list rather than naming a label the grant never included. `labelsAdded` omits Archive for the same reason. */
  orphans?: ('expunge' | 'archive')
  /** Inclusive UID ceiling — the selection is every member with uid <= this. Omitted on a FIRST call, the label's current highest UID is used and echoed back. REQUIRED once `after` is given, so a continuation cannot move its own ceiling and sweep in mail that arrived mid-gesture. */
  uidMax?: number
  /** Precondition: refuse with 409 uid_validity_mismatch unless the label still carries this epoch. A bump means the UIDs this selection was taken over no longer name the same messages. */
  uidValidity?: number
}

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