# Invoice routes: create, get, list

URL: /code/api/invoice/records · Id: `page:code/api/invoice/records`

> The Invoice Verbs create, get, list as api.sb routes, with inputs, result, refusals and an example.

Reference for [Invoice](/business/nouns/invoice), one group of [Invoice routes](/code/api/invoice).

### Invoice.create
Creates an Invoice. [Verb page](/business/nouns/invoice/create?interface=api).

```text
POST /{namespace}/invoices
```

Body, as JSON: the inputs. Emits `Invoice.created`.

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `total` | `money` | Yes | The amount due. |
| `due` | `date` | Yes | When payment is due. |
| `paidAt` | `datetime` | No | When it was paid. |
| `collection` | `string` | No | `charge` charges the saved payment method; `send` sends the Invoice and waits for a transfer. `charge` by default. |
| `terms` | `integer` | No | Days from issue until a `send` Invoice is due, such as 30; sets `due`. |
| `purchaseOrder` | `string` | No | The Customer’s purchase order number, printed on the Invoice. |
| `refunded` | `money` | No | The total returned to the Customer, from zero up to the amount paid. |
| `number` | `string` | No | The Invoice number, sequential per Startup and never reused, voided Invoices included. |
| `lines` | `json` | No | Each Offer billed: its quantity, Period and amount, with any Coupon or Credit Grant applied. |
| `pdf` | `url` | No | The Invoice, or its receipt once paid, as a PDF on the Startup’s Domain that names the seller of record. |
| `payUrl` | `url` | No | The page on the Startup’s Domain where the Customer pays it by card or bank transfer. |
| `subscription` | [Subscription](/business/nouns/subscription) | No | The Invoices the Subscription issues, one for each period it renews. |
| `customer` | [Customer](/business/nouns/customer) | No | Each Invoice is owed by one Customer. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `invoice` | [Invoice](/business/nouns/invoice) | Yes | The Invoice. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/invoices \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"total":{"amount":29,"currency":"USD"},"due":"2026-10-22"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "invoice": {
    "$id": "https://api.sb/leaseline.app/invoices/inv_Ez0sMX4WOW",
    "$type": "Invoice",
    "total": {
      "amount": 29,
      "currency": "USD"
    },
    "due": "2026-10-22"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Invoice.create",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### Invoice.get
Returns one Invoice by id. [Verb page](/business/nouns/invoice/get?interface=api).

```text
GET /{namespace}/invoices/{id}
```

Path: `id`. Query: the other inputs. Reads only: it emits no Event.

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | The id of the Invoice. |
| `at` | `string` | No | A time or Version name: the record as it stood then. Unset: as it stands now. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `invoice` | [Invoice](/business/nouns/invoice) | Yes | The Invoice. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl https://api.sb/leaseline.app/invoices/inv_9sfvgeRT7L \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY"
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "$type": "Invoice",
  "$id": "https://api.sb/leaseline.app/invoices/inv_9sfvgeRT7L",
  "invoice": {
    "$id": "https://api.sb/leaseline.app/invoices/inv_9sfvgeRT7L",
    "$type": "Invoice",
    "total": {
      "amount": 99,
      "currency": "USD"
    },
    "due": "2026-10-01"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/invoices/inv_9sfvgeRT7L",
    "up": "https://api.sb/leaseline.app/invoices"
  },
  "actions": {
    "bill": "https://api.sb/leaseline.app/invoices/inv_9sfvgeRT7L/bill",
    "collect": "https://api.sb/leaseline.app/invoices/inv_9sfvgeRT7L/collect",
    "refund": "https://api.sb/leaseline.app/invoices/inv_9sfvgeRT7L/refund"
  }
}
```

### Invoice.list
Returns Invoices, newest first, one page at a time. [Verb page](/business/nouns/invoice/list?interface=api).

```text
GET /{namespace}/invoices
```

Query: the inputs. Reads only: it emits no Event.

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `limit` | `integer` | No | At most this many records, up to 100. The default is 20. |
| `after` | `string` | No | The cursor from the previous page. |
| `where` | `string` | No | A filter over the properties, such as `paidAt = null and total.amount > 500`. |
| `sort` | `string` | No | Properties to sort by, comma-separated; a leading minus sorts descending. |
| `total` | `boolean` | No | True adds the match count as `meta.total`, exact up to 10,000 matches and estimated above. |
| `facets` | `string` | No | Properties to count by value, comma-separated, returned as `meta.facets`. |
| `fields` | `string` | No | Properties to return on each record, comma-separated; `$id` and `$type` always return. |
| `include` | `string` | No | Related records to embed in place of their URLs, comma-separated. |
| `depth` | `integer` | No | How many levels of related records to embed. The default is 1. |
| `q` | `string` | No | Words to match across the text properties, ranked by relevance. |
| `match` | `string` | No | Ranks the search by `words`, or `meaning`; words is the default. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `invoices` | list of [Invoice](/business/nouns/invoice) | Yes | One page of Invoices. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl "https://api.sb/leaseline.app/invoices?limit=20" \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY"
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "$type": "Invoice",
  "invoices": [
    {
      "$id": "https://api.sb/leaseline.app/invoices/inv_9sfvgeRT7L",
      "$type": "Invoice",
      "total": {
        "amount": 99,
        "currency": "USD"
      },
      "due": "2026-10-01"
    }
  ],
  "meta": {
    "limit": 20,
    "after": "inv_9sfvgeRT7L"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/invoices?limit=20",
    "next": "https://api.sb/leaseline.app/invoices?after=inv_9sfvgeRT7L"
  }
}
```