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

# Autopilot

> How to display and manage recurring investment automations

The Autopilot screen allows users to view and manage their recurring investment/savings automations. Users can see their active automations and toggle them on or off.

<Info>
  Automations set up direct debit payments from a linked bank account on a specified day each month.
  For top-up automations, funds are automatically invested proportionally across the user's existing holdings.
</Info>

## Data sources

<CardGroup cols={2}>
  <Card title="Get Automations" icon="list" href="/api-reference/automations/get-automations">
    Retrieve all recurring investment automations for the user.
  </Card>

  <Card title="Cancel Automation" icon="toggle-off" href="/api-reference/automations/cancel-automation">
    Cancel an active automation when user toggles it off.
  </Card>
</CardGroup>

## Prerequisites

* Backend access to the M2M endpoints
* Bearer token with required scopes
* User must have at least one bank account set up

## What to fetch

<AccordionGroup>
  <Accordion title="List automations">
    Use [Get automations](/api-reference/automations/get-automations) to retrieve all automations for a user.

    Returns:

    * Automation ID, status, and category
    * Monthly investment amount and currency
    * Day of month for collection (-1 for last day of month, 0-28 for specific day)
    * Linked mandate information (status, bank account)
  </Accordion>

  <Accordion title="Cancel automation">
    Use [Cancel automation](/api-reference/automations/cancel-automation) when the user toggles off an automation.

    * Sends a `POST` request to `/automations/{id}/cancel`
    * Returns `202 Accepted` on success
    * Pending deposits not yet submitted will be cancelled
  </Accordion>
</AccordionGroup>

## Example: fetch automations

<CodeGroup>
  ```javascript Node.js theme={null}
  const BASE = 'https://api.wealthyhood.com';

  async function fetchAutopilotScreen({ token, userId }) {
    const headers = {
      'Authorization': `Bearer ${token}`,
      'x-user-id': userId,
      'Accept': 'application/json'
    };

    const response = await fetch(`${BASE}/automations`, { headers });

    if (!response.ok) {
      throw new Error(`Failed to fetch automations: ${response.status}`);
    }

    const { data: automations } = await response.json();

    return {
      automations: automations.map(automation => ({
        id: automation.id,
        isActive: automation.status === 'Active',
        amount: automation.amount,
        currency: automation.currency,
        dayOfMonth: automation.dayOfMonth,
        mandateStatus: automation.mandate.status,
        bankAccountId: automation.mandate.bankAccountId
      }))
    };
  }
  ```

  ```bash cURL theme={null}
  curl -X GET 'https://api.wealthyhood.com/automations' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    -H 'x-user-id: 64f0c51e7fb3fc001234abcd'
  ```
</CodeGroup>

## Example: toggle automation off

When a user toggles off an automation, call the cancel endpoint:

<CodeGroup>
  ```javascript Node.js theme={null}
  async function cancelAutomation({ token, userId, automationId }) {
    const headers = {
      'Authorization': `Bearer ${token}`,
      'x-user-id': userId,
      'Accept': 'application/json'
    };

    const response = await fetch(
      `${BASE}/automations/${automationId}/cancel`,
      { method: 'POST', headers }
    );

    if (response.status === 202) {
      // Automation cancelled successfully
      return { success: true };
    }

    throw new Error(`Failed to cancel automation: ${response.status}`);
  }
  ```

  ```bash cURL theme={null}
  curl -X POST 'https://api.wealthyhood.com/automations/64f0c51e7fb3fc001234abcd/cancel' \
    -H 'Accept: application/json' \
    -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
    -H 'x-user-id: 64f0c51e7fb3fc001234a111'
  ```
</CodeGroup>

## Example: enable new automation

To create (enable) a new automation, use the [Create automation](/api-reference/automations/create-automation) endpoint:

```javascript theme={null}
async function createAutomation({ token, userId, bankAccountId, amount, dayOfMonth }) {
  const headers = {
    'Authorization': `Bearer ${token}`,
    'x-user-id': userId,
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  };

  const response = await fetch(`${BASE}/automations`, {
    method: 'POST',
    headers,
    body: JSON.stringify({
      category: 'TopUpAutomation',
      bankAccountId,
      orderAmount: amount,
      dayOfMonth
    })
  });

  if (!response.ok) {
    const error = await response.json();
    throw new Error(error.error?.message || 'Failed to create automation');
  }

  return response.json();
}
```

<Tip>
  When creating an automation, a direct debit mandate will be automatically created for the specified
  bank account if one doesn't already exist. The mandate status will initially be `Pending` until
  confirmed by the payment provider.
</Tip>

## See also

* [API Reference → Get Automations](/api-reference/automations/get-automations)
* [API Reference → Create Automation](/api-reference/automations/create-automation)
* [API Reference → Cancel Automation](/api-reference/automations/cancel-automation)
* [API Reference → Bank Accounts](/api-reference/bank-accounts/get-bank-accounts)
