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

# Fetch transaction categories

> Retrieves the list of usable transaction categories based on the business' chart of accounts. This endpoint is used by Layer's `<BankTransactions>` embedded component, and can be used to build your own transaction categorization user interface.

<Warning>If you are primarily using Layer's embedded components, you likely won't need to use this API endpoint directly.</Warning>

## Filtering by mode

Use the [mode](/api-reference/v1/fetch-transaction-categories#parameter-mode) query parameter to control which subset of categories is returned:

| Mode       | Categories returned                                                                                                                                                                                 |
| ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DEFAULT`  | The business's configured category list (see `category_list_type` on the [accounting configuration](/api-reference/v1/fetch-accounting-configuration)). This is the default when `mode` is omitted. |
| `ALL`      | All accounts and optional categories from the chart of accounts.                                                                                                                                    |
| `EXPENSES` | Expense categories only.                                                                                                                                                                            |
| `REVENUE`  | Revenue categories only.                                                                                                                                                                            |

## Types

There are three types of categories you'll find in the category list: `AccountNested`, `OptionalAccountNested`, and `ExclusionNested`.

### AccountNested

`AccountNested` represents a [required template account](/api-reference/ledger/required-vs-optional-template-accounts#required-template-accounts) in the business's chart of accounts.

### OptionalAccountNested

`OptionalAccountNested` represents an [optional template account](/api-reference/ledger/required-vs-optional-template-accounts#optional-template-accounts) in the business's chart of accounts.

### ExclusionNested

`ExclusionNested` represents an [exclusion](/api-reference/v1/categorize-bank-transaction#param-type-4) type that can be used to exclude a transaction from the business's accounting.

## Interpreting the category list

In all cases, use `display_name` to present the category to the user. Use the columns below to choose a stable identifier.

| Category type               | `AccountId`         | `StableName` | Identify with                                        | Notes                                                                                                                |
| --------------------------- | ------------------- | ------------ | ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| Optional template account   | After instantiation | Yes          | `StableName` (always); `AccountId` once instantiated | Optional accounts only have an `AccountId` after first use. Use `StableName` to reference them before instantiation. |
| User-defined custom account | Yes                 | No           | `AccountId` only                                     | A new `AccountId` is created when the account is added; no stable name is assigned.                                  |
| Required template account   | Yes                 | Yes          | `AccountId` or `StableName`                          | The stable name is the same as the account name.                                                                     |
| Exclusion                   | No                  | Yes          | `StableName`                                         | The exclusion type acts as the stable name; exclusions have no `AccountId`.                                          |


## OpenAPI

````yaml get /v1/businesses/{businessId}/categories
openapi: 3.0.1
info:
  title: API
  version: latest
servers: []
security:
  - BearerAuth: []
tags: []
externalDocs:
  url: /
paths:
  /v1/businesses/{businessId}/categories:
    get:
      tags: []
      summary: Fetch transaction categories
      description: >-
        Retrieves the list of usable transaction categories based on the
        business' chart of accounts. This endpoint is used by Layer's
        `<BankTransactions>` embedded component, and can be used to build your
        own transaction categorization user interface.
      operationId: business.categories.get
      parameters:
        - name: businessId
          in: path
          description: >-
            The UUID of the business to fetch the tree of available categories
            for.
          required: true
          schema:
            type: string
        - name: mode
          in: query
          description: >-
            Controls which subset of categories is returned. `DEFAULT` uses the
            business's configured category list (see `category_list_type` on the
            accounting configuration). `ALL` returns all accounts and optional
            categories. `EXPENSES` returns expense categories only. `REVENUE`
            returns revenue categories only.
          required: false
          schema:
            type: string
            enum:
              - DEFAULT
              - ALL
              - EXPENSES
              - REVENUE
            default: DEFAULT
        - name: Content-Type
          in: header
          description: Content-Type must be set to application/json.
          schema:
            type: string
      responses:
        '200':
          description: ''
          headers: {}
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/CategoryList'
                required:
                  - data
      deprecated: false
components:
  schemas:
    CategoryList:
      type: object
      description: List of the categories available for a business.
      properties:
        type:
          type: string
          description: Resource type. Value will be 'Category_List'.
          example: Category_List
        categories:
          description: >-
            Array of categories in a business, where each category is a
            polymorphic type that can be an Account, OptionalAccount, or an
            Exclusion. For more details, see [Account
            Identifiers](/api-reference/ledger/account-identifier) and
            [Categorization](/api-reference/v1/categorize-bank-transaction#request-body-single-category-or-split).
          type: array
          items:
            $ref: '#/components/schemas/NestedApiCategorization'
    NestedApiCategorization:
      type: object
      oneOf:
        - $ref: '#/components/schemas/NestedAccountCategorization'
          title: AccountNested
        - $ref: '#/components/schemas/NestedOptionalCatetoryCategorization'
          title: OptionalAccountNested
        - $ref: '#/components/schemas/NestedExclusionCategorization'
          title: ExclusionNested
    NestedAccountCategorization:
      type: object
      description: >-
        A category that represents a required template account in the business's
        chart of accounts.
      properties:
        type:
          type: string
          description: Resource type. Value will always be `AccountNested`.
          example: AccountNested
        id:
          type: string
          format: uuid
          description: The ID of the account.
          example: e95c8640-f87b-43bf-a9c6-cabc7ebfdec6
        stable_name:
          type: string
          nullable: true
          description: The stable name of the account.
          example: EXPENSES
        display_name:
          type: string
          description: The display name of the account.
          example: Expenses
        subCategories:
          $ref: '#/components/schemas/NestedApiSubCategories'
          description: >-
            The subcategories of the account, in case there are more specific
            sub-categories of the account.
    NestedOptionalCatetoryCategorization:
      type: object
      description: >-
        A category that represents an optional template account in the
        business's chart of accounts.
      properties:
        type:
          type: string
          description: Resource type. Value will always be `OptionalAccountNested`.
          example: OptionalAccountNested
        stable_name:
          type: string
          description: The stable name of the optional account.
        display_name:
          type: string
          description: The display name of the optional account.
        subCategories:
          $ref: '#/components/schemas/NestedApiSubCategories'
          description: The subcategories of the account.
    NestedExclusionCategorization:
      type: object
      description: >-
        A category that represents an exclusion type in the business's chart of
        accounts.
      properties:
        type:
          type: string
          description: Resource type. Value will always be `ExclusionNested`.
          example: ExclusionNested
        id:
          type: string
          description: >-
            The ID of the exclusion type. This is not a UUID and is equivalent
            to the `category` field.
          enum:
            - PERSONAL_EXPENSES
            - PERSONAL_INFLOWS
            - DUPLICATE_TRANSACTION
            - OTHER_EXCLUSION
        category:
          type: string
          description: >-
            The category of the exclusion type. This is equivalent to the `id`
            field.
          enum:
            - PERSONAL_EXPENSES
            - PERSONAL_INFLOWS
            - DUPLICATE_TRANSACTION
            - OTHER_EXCLUSION
        display_name:
          type: string
          description: The display name of the exclusion type.
          enum:
            - Personal spending
            - Personal income sources
            - Duplicate transaction
            - Other exclusion
    NestedApiSubCategories:
      type: array
      items:
        $ref: '#/components/schemas/NestedApiCategorization'
      nullable: true
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````