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

# Bill / AP data

Bills represent your customers' **accounts payable**: amounts they owe to vendors for goods or services received. Importing bills lets Layer track outstanding payables, recognize expenses, and reconcile the bank transactions that pay those bills.

A typical accounts payable flow has three steps:

1. [Create a vendor](#create-a-vendor), the party the bill is owed to.
2. [Create a bill](#create-a-bill) with its line items, terms, and due date.
3. [Record a bill payment](#record-a-bill-payment) against one or more bills.

<Note>
  Bill / AP support may need to be enabled for your platform. Reach out to your Layer contact for access.
</Note>

## Create a vendor

A bill must be associated with a vendor. Create one with the [Create Vendor](/api-reference/v1/create-vendor) endpoint, supplying your own `external_id` so you can reference it later without storing Layer's IDs.

```bash Request theme={null}
curl -X POST https://sandbox.layerfi.com/v1/businesses/{businessId}/vendors \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "external_id": "vendor-1",
    "company_name": "Acme Supplies Inc.",
    "email": "billing@acmesupplies.com",
    "office_phone": "555-123-4567",
    "address_string": "123 Vendor St, Supply City, CA 90210"
  }'
```

The API responds with a [Vendor](/api-reference/vendor/vendor) object. You can later look up vendors with [List Vendors](/api-reference/v1/list-vendors).

## Create a bill

Create a bill with the [Create Bill](/api-reference/v1/create-bill) endpoint. Each bill references a vendor (by `vendor_id` or `vendor_external_id`), one or more `line_items`, and either a `due_at` date or `bill_terms` (one of `DUE_ON_RECEIPT`, `NET_10`, `NET_15`, `NET_30`, `NET_60`).

Each line item requires a `product_name` and `unit_price` (in cents) and may include a `quantity`, `description`, discounts, sales taxes, and an `account_identifier` to control which expense account the line posts to.

```bash Request theme={null}
curl -X POST https://sandbox.layerfi.com/v1/businesses/{businessId}/bills \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "external_id": "vendor-bill-123",
    "vendor_external_id": "vendor-1",
    "received_at": "2024-06-01T10:11:57Z",
    "bill_terms": "NET_30",
    "reference_number": "VB-123",
    "memo": "Monthly office supplies",
    "line_items": [
      {
        "external_id": "bill-line-item-1",
        "product_name": "Paper reams",
        "description": "Monthly office supplies",
        "unit_price": 1500,
        "quantity": 10,
        "discount_amount": 1000,
        "sales_taxes": [
          {
            "tax_account": {
              "type": "Tax_Name",
              "name": "CA_SALES_TAX"
            },
            "amount": 1120
          }
        ]
      }
    ]
  }'
```

The API responds with a [Bill](/api-reference/bill/bill) object. The bill's `status` reflects how much has been paid (`RECEIVED`, `PARTIALLY_PAID`, `PAID`, or `VOIDED`), and `outstanding_balance` tracks what remains owed.

`external_id` is your idempotency key. Re-posting a bill with the same `external_id` updates the existing bill rather than creating a duplicate. To create many bills at once, use [Batch Create Bills](/api-reference/v1/batch-create-bills).

## Record a bill payment

When a customer pays a bill, record the payment so Layer can mark the bill paid and reconcile it against bank activity.

For a payment made at the same time the bill is created, include a `payments` array directly in the [Create Bill](/api-reference/v1/create-bill) request. To record a payment against an existing bill, or a single payment that covers several bills, use the [Create Bill Payment](/api-reference/v1/create-bill-payment) endpoint and allocate the amount across bills with `bill_payment_allocations`.

```bash Request theme={null}
curl -X POST https://sandbox.layerfi.com/v1/businesses/{businessId}/bills/bill-payments \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -d '{
    "external_id": "bill-payment-1",
    "paid_at": "2024-06-15T00:00:00Z",
    "method": "ACH",
    "amount": 10000,
    "bill_payment_allocations": [
      {
        "bill_external_id": "vendor-bill-123",
        "amount": 10000
      }
    ]
  }'
```

The `method` is one of `CASH`, `CHECK`, `CREDIT_CARD`, `ACH`, `CREDIT_BALANCE`, or `OTHER`. All amounts are in cents.

## Vendor credits and refunds

Layer also supports reducing payables through [vendor credits](/api-reference/vendor-credits/vendor-credit) (credits a vendor issues that can be applied to future bills) and [vendor refunds](/api-reference/vendor-refunds/vendor-refund) (money a vendor returns). See the API reference for details.

## Expenses

An expense is a type of bill for a purchase paid immediately. Use [Create expense](/api-reference/v1/create-expense) when you want to record the purchase and payment together. See the [Expense object](/api-reference/bill/expense) for details.
