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

# Plaid

> Import your customers' external bank account and credit card activity into Layer with Plaid.

Layer uses [Plaid](https://plaid.com/) to connect to your customers' accounts at external financial institutions. Once an account is connected, Layer ingests its transactions and balances and incorporates them into the customer's books.

There are two ways to connect Plaid accounts, depending on whether your platform already has a Plaid integration:

* **Use Layer's Plaid connection** - Layer manages the Plaid relationship on your behalf. Best if you don't already integrate with Plaid.
* **Use your own Plaid connection** - Keep your existing Plaid relationship and grant Layer access to the data.

## Use Layer's Plaid connection

Your customers link their accounts through a Layer-powered flow, and Layer handles credential management, connection health, and data ingestion.

You can present the linking flow in two ways:

<CardGroup cols={2}>
  <Card title="Embedded components" icon="puzzle-piece" href="/embedded-components/components/link-accounts">
    Drop Layer's prebuilt, white-labeled account linking component into your app.
  </Card>

  <Card title="Custom Plaid Link UI" icon="paintbrush" href="/guides/custom-plaid-account-linking">
    Build your own account linking experience on top of Plaid Link, powered by Layer's Plaid connection.
  </Card>
</CardGroup>

Both options grant Layer read-only access to the customer's bank account and credit card activity. Once accounts are connected, transactions begin flowing into Layer automatically.

## Use your own Plaid connection

If your platform already integrates with Plaid, you don't need to ask customers to link their accounts again. Grant Layer access to your existing Plaid data using processor tokens.

<Steps>
  <Step title="Create a processor token">
    [Link](https://plaid.com/docs/link/#link-flow-overview) a customer's bank account with Plaid as usual, obtaining an `access_token`. Then create a processor token for each account via Plaid's [/processor/token/create](https://plaid.com/docs/api/processors/#processortokencreate) endpoint, specifying `layer` as the processor.

    ```bash Request theme={null}
    curl -X POST https://sandbox.plaid.com/processor/token/create \
      -H 'Content-Type: application/json' \
      -d '{
        "client_id": "PLAID_CLIENT_ID",
        "secret": "PLAID_SECRET",
        "access_token": "ACCESS_TOKEN",
        "account_id": "ACCOUNT_ID",
        "processor": "layer"
      }'
    ```
  </Step>

  <Step title="Attach the tokens to a business">
    Pass the processor tokens when [creating a business](/api-reference/v1/create-business), or [update an existing business](/api-reference/v1/update-business) with them. Layer begins ingesting data from the associated accounts immediately.

    ```bash Request theme={null}
    curl -X PUT https://sandbox.layerfi.com/v1/businesses/{businessId} \
      -H "Authorization: Bearer <access_token>" \
      -H "Content-Type: application/json" \
      -d '{
        "plaid_processor_tokens": [
          { "processor_token": "processor-sandbox-0asd1-a92nc" }
        ]
      }'
    ```

    <Warning>
      Updates replace the full list of processor tokens on the business. Include every token you want associated, since any existing tokens omitted from the request are removed.
    </Warning>
  </Step>
</Steps>

If a Plaid account's access token changes, its processor tokens are invalidated. Create a new processor token and update the business with the refreshed list. To see which processor tokens are currently associated with a business, call [List Plaid Accounts](/api-reference/plaid-account/list-plaid-accounts).

## Unlinking bank accounts

When a customer disconnects a Plaid link, Layer removes the connection with Plaid and archives the linked item and all of its accounts. What happens to the account's transactions depends on whether they have been categorized onto the ledger:

<Steps>
  <Step title="Categorized transactions stay on the ledger">
    Transactions that have already been categorized, whether categorized, split, or matched to an existing invoice, bill, payout, transfer, or manual journal entry, are *not* affected. Their ledger entries remain intact, so they continue to appear in the customer's books and reports exactly as before.
  </Step>

  <Step title="Uncategorized transactions are archived">
    Transactions that have not yet been categorized, such as those pending, awaiting Layer review, or ready for input, are archived. Archived transactions are no longer visible to the customer and are excluded from balances and reports, but the underlying records are retained.
  </Step>
</Steps>

The customer's opening balances and any bank-account-level mappings are also archived when the last active external account on that bank account is disconnected.

<Note>
  Categorized transactions are preserved because once a transaction has been posted to the ledger, its source bank transaction must remain in-system: the ledger entry depends on it, and removing it would change the customer's financial reports. Unlinking therefore archives only uncategorized transactions. Users are not allowed to remove transactions from Plaid accounts. Users are only allowed to remove transactions from custom accounts, where transactions are either from an CSV upload or manually recorded expenses or income.

  Unlinking also calls Plaid's `/item/remove`, which invalidates the item's access token. The disconnected Plaid item cannot be reconnected. To resume syncing, the customer must complete a new Plaid Link flow, which creates a new item. Transactions that Plaid had already reported to Layer are retained in the archived state described above.
</Note>

For the full walkthrough, see the [bank data guide](/guides/importing-bank-data).
