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

# On Automate.ax account unhealthy

> Run an automation when a connected integration account stops working.

`automate.onAccountUnhealthy` fires when Automate.ax can't refresh a connected account's credential or the account fails a health check. Use it to send account failures to your own alerting, because triggers that depend on a broken account stop producing events without failing a run.

```ts automations/alert-on-broken-account.automation.ts theme={null}
import { automation, t } from "automate.ax"
import { automate } from "automate.ax/automate"
import { slack } from "automate.ax/slack"

export default automation("Alert on broken account", () => {
  const event = automate.onAccountUnhealthy()

  slack.sendMessage({
    conversation: "C01234567",
    text: t`${event.account.serviceId} account ${event.account.label} stopped working: ${event.error.message}`,
  })
})
```

The trigger watches every account linked to the deploying project's organization. It fires once when an account goes from healthy to unhealthy. It won't fire again for repeated failures until the account recovers, for example after you reconnect it. Revoking an account doesn't fire this trigger.

Provider outages, rate limits, timeouts, and network errors don't fire it. Automate.ax records them with the `PROVIDER_UNAVAILABLE` code and checks the account again within 10 minutes.

To watch another organization, pass a static Automate.ax binding with `account`. That organization API key needs `account:read`.

## Trigger data

| Field | Type | Description |
| - | - | - |
| `account.id` | `string` | Integration account ID, as shown by `automate accounts list`. |
| `account.serviceId` | `string` | Integration service, such as `google` or `slack`. |
| `account.connectionMethodId` | `string` | Connection method, such as `oauth`. |
| `account.label` | `string` | Account display name, such as the provider email address. |
| `error.code` | `string` | Failure code recorded for the account. |
| `error.message` | `string` | Provider failure, such as `OAuth token refresh failed (invalid_grant): Bad Request`. |
| `organization` | `{ id: string; name: string }` | Linked organization that owns the affected automations. |
| `transitionedAt` | `Date` | When Automate.ax marked the account unhealthy. |

Organization admins also get an email that lists the affected automations and links to **Connected Accounts**. See [Integration accounts](https://docs.automate.ax/concepts/integration-accounts.md) for account status and how to reconnect.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.