> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Mark as unread

> Mark one or many Gmail messages as unread.

`markAsUnread` adds Gmail's `UNREAD` system label to one or many messages. Use it to return processed mail to a person's review queue or preserve a reminder in Gmail.

## Example

Mark up to 100 read messages with the `Needs review` label as unread:

```ts theme={null}
import { automation, branch } from "automate.ax"
import { markAsUnread, searchMessages } from "automate.ax/gmail"

export default automation("Return Gmail messages for review", () => {
  const messages = searchMessages({
    limit: 100,
    query: 'label:"Needs review" is:read',
  })

  branch(
    messages.length.transform((length) => length > 0),
    () => {
      markAsUnread({
        messageIds: messages.transform((results) =>
          results.map((message) => message.messageId),
        ),
      })
    },
  )
})
```

## Inputs

| Name         | Type                                 | Required | Description                                                                      |
| ------------ | ------------------------------------ | -------- | -------------------------------------------------------------------------------- |
| `messageIds` | `string \| string[]`                 | Yes      | One or up to 1,000 immutable Gmail message IDs.                                  |
| `account`    | `string \| Google account reference` | No       | Google account binding to use. Defaults to the project's default Google account. |

Every input field also accepts a compatible `Signal`; the example derives message IDs from `searchMessages`.

## Output

The action returns a `Signal<string[]>` containing the modified message IDs in input order.

Gmail stores unread state per message. Adding `UNREAD` to one message can make its conversation appear unread in Gmail even though other messages in the thread remain read.
