> ## 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.

# Search drafts

> Find Gmail drafts with standard Gmail search syntax.

`searchDrafts` finds drafts in the connected Gmail account and returns their
stable draft and message identifiers. Use the same query syntax as Gmail's
search box.

## Example

```ts automations/find-review-drafts.automation.ts theme={null}
import { automation, onHttpRequest } from "automate.ax"
import { searchDrafts } from "automate.ax/gmail"

export default automation("Find drafts awaiting review", () => {
  onHttpRequest({ scope: "automation" })

  searchDrafts({
    query: "to:customer@example.com subject:proposal",
    limit: 25,
  })
})
```

## Inputs

| Input              | Type                                              | Required | Default         | Description                                                      |
| ------------------ | ------------------------------------------------- | -------- | --------------- | ---------------------------------------------------------------- |
| `query`            | `string`                                          | No       | All drafts      | Standard Gmail search-box query.                                 |
| `limit`            | `number`                                          | No       | `100`           | Maximum total results. Must be an integer from 1 through 10,000. |
| `includeSpamTrash` | `boolean`                                         | No       | `false`         | Allow drafts in Spam and Trash to match.                         |
| `account`          | `string \| IntegrationAccountReference<"google">` | No       | Project default | Connected Google account to search.                              |

Every input, including `account`, also accepts a compatible `Signal`.

Automate.ax fetches additional Gmail pages internally until it reaches `limit`
or Gmail has no more results.

## Output

The action returns a `Signal<DraftIdentifier[]>`. Each item contains:

| Property    | Type                  | Description                                                               |
| ----------- | --------------------- | ------------------------------------------------------------------------- |
| `draftId`   | `string`              | Immutable Gmail draft ID. Use this with draft actions.                    |
| `messageId` | `string`              | Immutable ID of the message stored inside the draft.                      |
| `threadId`  | `string`              | Gmail thread containing the draft.                                        |
| `historyId` | `string \| undefined` | Latest mailbox history record affecting the draft message, when supplied. |
| `labelIds`  | `string[]`            | Labels applied to the draft message.                                      |

Use `draftId`, not `messageId`, with `getDraft`, `updateDraft`, `sendDraft`, and
`deleteDraft`.
