---
title: Invoicing objects
description: The customers, contracts, proposals, invoices and payments behind the billing API, how they connect, and who changes each one.
---

Hydda One builds invoices. It does not issue them. An operator approves each invoice, and an integration then issues it in the organization's ERP or invoicing platform, delivers it and collects the payment. This page explains the objects that carry that work, so the fields in the [billing API](/guides/surfaces/billing) make sense before you call it.

## Who does what

```mermaid
flowchart LR
  subgraph H["Hydda One"]
    C["Charges<br/>rent, bookings, extras"] --> R["Invoice run"]
    R -- "with review" --> P["Proposal"]
    R -- "without review" --> I["Invoice<br/><i>created</i>"]
    P -- "you pass it" --> I
    I -- "operator approves" --> A["Invoice<br/><i>approved</i>"]
  end
  subgraph E["Your integration and ERP"]
    S["Issue and deliver"] --> PAY["Collect payment"]
  end
  A -- "send queue" --> S
  S -. "report sent" .-> A
  PAY -. "report payment" .-> A
```

| Step | Who | What happens |
| --- | --- | --- |
| Charges build up | Hydda One | A contract's recurring fees, bookings and other purchases become charges. |
| Invoice run | An operator | The operator starts a run. It gathers the charges of each contract into a document. |
| Review, if switched on | Your integration | The document is first a **proposal**. Your integration checks it and passes or rejects it. |
| Approval | An operator | The operator approves the invoice. This is the last thing Hydda One decides. |
| Issue and deliver | Your integration | Your ERP gives the invoice its legal number, date and total. You report them back. |
| Payment | Your integration | You report each payment, reversal and write-off. Hydda One derives the status from them. |

The split matters for how you read the data. Before the invoice is sent, Hydda One's values are a **request**: issue this, with these lines, on this date. After it is sent, your ERP's values are the **record**: the number the customer sees, the total they owe.

## The objects

```mermaid
erDiagram
  BUSINESS_CONTEXT ||--o{ CONTRACT : owns
  CUSTOMER ||--o{ CONTRACT : signs
  CUSTOMER ||--o{ BILLING_ACCOUNT : has
  CONTRACT }o--|| BILLING_ACCOUNT : "is invoiced to"
  CONTRACT ||--o{ CHARGE : raises
  CONTRACT ||--o{ INVOICE : "is billed by"
  PROPOSAL |o--o| INVOICE : becomes
  INVOICE ||--|{ INVOICE_LINE : has
  INVOICE_LINE }o--o| CHARGE : bills
  INVOICE ||--o{ PAYMENT : "is settled by"
  INVOICE ||--o{ WRITE_OFF : "is settled by"
  INVOICE ||--o{ CREDIT_NOTE : "is credited by"
```

| Object | Field in the API | What it is |
| --- | --- | --- |
| Customer | `recipientAgentId`, `recipient` | The party that is invoiced: a `company`, or a `private` household. |
| Contract | `contractId` | The agreement between the organization and a customer. One business context owns it. |
| Billing account | `billingAccountId` | Where and how a customer receives invoices: the address, and e-invoice, email or post. A contract names the account it is invoiced to. |
| Business context | `businessContextId` | The line of business that owns the contract. See [Organizations and contexts](/guides/concepts/organizations-and-contexts#business-contexts). |
| Charge | `chargeLineId` on a line | One thing to be paid for: a month of rent, a meeting room booking, a coffee order. |
| Invoice run | `invoiceRunId` | One time an operator built documents from the charges. |
| Proposal | `proposal` | An invoice that waits for your integration's review. It exists only when review is switched on. |
| Invoice | `invoice` | The document your integration issues. `documentKind` is `invoice` or `credit-note`. |
| Invoice line | `lines` | One row of the document, with quantity, price, VAT and booking codes. |
| Payment, write-off | `platformPaymentId`, `platformWriteOffId` | What your payment platform received, or gave up collecting. You report them. |

### One invoice bills one contract

A run makes **one document per contract and billing stream**. Two contracts of the same customer get two invoices, even when both go to the same billing account.

A contract has two billing streams, and each gets its own document:

| `billingStream` | What it bills |
| --- | --- |
| `contractual` | What the contract itself sells, such as monthly rent or a membership fee. |
| `running` | What the customer bought beside it, such as bookings and add-ons. |

### The customer details are a snapshot

The `recipient` block on a queue item holds the customer's name, identifiers, address and delivery method as they were when the document was written. A later change to the customer or the billing account does not reach a document that already exists. Two reads of the same item always agree, so you can retry safely.

## The company an invoice belongs to

A queue item names two contexts. They answer different questions.

| Field | Answers | Use it for |
| --- | --- | --- |
| `businessContextId` | Which line of business owns the contract? | Choosing the ERP account, the number series and the sender details. |
| `operationalContextId` | Where did the operator run the invoicing? | Nothing in your routing. It is the context the document was created in. |

Route by `businessContextId`. When it is `null`, Hydda One does not know the owner. Do not guess a company. Report the invoice failed, so an operator can fix the contract.

## Four ids for one invoice

An invoice collects several identifiers on its way through. Each has one job.

| Field | Set by | What it is |
| --- | --- | --- |
| `id` | Hydda One | The UUID you address every report to. |
| `invoiceNumber` | Hydda One | An internal running number. It is never printed on the legal invoice, and the series can have gaps. |
| `externalReference` | You | Your own id for the invoice in your system. You attach it when you pass the proposal or report the invoice sent. It is unique in the organization. |
| `issuedInvoiceNumber` | Your ERP | The legal invoice number the customer sees and quotes. You report it with the send. |

The same split applies to dates and totals:

| Hydda One asks for | Your ERP issued |
| --- | --- |
| `requestedInvoiceDate` | `issuedInvoiceDate` |
| `requestedDueDate` | `dueDate` |
| `totalGrossMinorUnits` | `issuedTotalGrossMinorUnits` |

Issue the invoice with the requested dates as they stand. The issued total can differ from Hydda One's by a rounding unit. Payments are measured against the issued total.

## The life of an invoice

```mermaid
stateDiagram-v2
  [*] --> created: an invoice run, or a passed proposal
  created --> approved: an operator approves
  approved --> sent: you report it sent
  approved --> failed: you report it failed
  sent --> paid: payments cover the total
  sent --> written_off: a write-off settles it
  paid --> sent: a payment is reversed
  written_off --> sent: a payment is reversed
  failed --> [*]: an operator deletes it and runs again
```

| `status` | Changed by | On your queues |
| --- | --- | --- |
| `created` | Hydda One | No. An operator can still delete it. |
| `approved` | An operator | On the send queue from its `requestedInvoiceDate`. |
| `sent` | You, with a sent report | No. It waits for payments. |
| `failed` | You, with a failed report | No. An operator corrects the material and builds a new invoice. |
| `paid` | Derived from your payment reports | No. |
| `written-off` | Derived from your payment and write-off reports | No. |

You never set `paid` or `written-off` yourself. You report each payment and write-off, and Hydda One works out the balance: the issued total, less every payment that was not reversed, less every write-off. The invoice is settled when the balance reaches zero or passes it.

A proposal has its own short life: `proposed` until you `pass` or `reject` it, or an operator cancels it. A passed proposal becomes an invoice in the same call.

## Credit notes

A credit note is an invoice with `documentKind` `credit-note`. It names the invoice it credits in `creditedInvoiceId`, and its totals are negative. It travels the same queues and takes the same reports as an invoice. The refund that settles it is a negative payment.

## How amounts are written

- Money is an integer in **minor units** of `currency`. `12500` in `SEK` is 125.00 kronor.
- A VAT rate is in **basis points**. `2500` is 25%.
- A line's `amountMinorUnits` excludes VAT and already has its discount taken off.
- `vatSubtotals` gives the net and VAT per VAT rate, so you do not have to add the lines up yourself.
- `quantity` is a decimal string, such as `"2.5"`, so a fraction stays exact.

## Next

**[Billing API guide](/guides/surfaces/billing)**

The queues to poll and the reports to send, call by call.

**[Build your own integration](/guides/integrations/build-your-own)**

Connect your own system to deliver an organization's invoices.
