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

# Endpoints

> Every horizon-api route of digital contracting, grouped by journey step, with who may call it, its permission and its purpose, plus the domain error codes the wizard handles.

All routes live in horizon-api under `/api/v3`. Request and response bodies
are described on the pages of each step; this page is the index.

## Access

| Access | Meaning |
| - | - |
| **Public** | No session. The request carries its own credential (a one-time token) or is rate-limited and answers neutrally |
| **Session** | An authenticated session (normally the contract session from `POST …/sessions`) on the contract's account whose user takes part in the contract |
| **Holder** | A Session whose user is an active user of the contract's account (`account_user`), in practice the account holder |
| **Seat** | An authenticated session (normally the contract session) whose user owns the signer seat in the path |
| **API key** | The Odoo integration API key holding the permission shown |
| **Staff** | A Maihue back-office token with the permission shown |

Every route also calls `authorize` with its permission. The permissions of
Public, Session, Holder and Seat routes are public in the catalogue because
the route itself checks the one-time token or the contract session. API key
and Staff permissions, `auth:register-contract-restart` included, are not in
the public allowlist.

## Registration

| Method | Path | Access | Permission | Purpose |
| - | - | - | - | - |
| `POST` | `/auth/register/contract` | Public | `auth:register-contract` | Create or reuse the account, the signers, the subscription and a `draft` contract; email the first one-time link |
| `POST` | `/auth/register/contract/restart` | API key or staff | `auth:register-contract-restart` | Start a new contract for an account whose contract is `cancelled`, `rejected` or `expired` |

## Session and recovery

| Method | Path | Access | Permission | Purpose |
| - | - | - | - | - |
| `POST` | `/contract/{id}/sessions` | Public | `contract:session` | Exchange the one-time link for a contract session and the `ContractState` |
| `POST` | `/contract/{id}/resend-access` | Public | `contract:resend-access` | Resend the one-time link to a participant; generic answer |
| `POST` | `/auth/contract/lookup-by-email` | Public | `auth:contract-lookup-by-email` | Given an email and the account's identity document (RUT or passport), resend the portal link to that account's primary user when it has an open contract (from `draft` to `awaiting_enterprise_signature`); every request, a match included, answers the same generic `found: false` with no contract; rate-limited per IP |
| `POST` | `/contract/{id}/resend-portal-magic-link` | Staff | `contract:resend-portal-magic-link` | Resend the link to the primary signer |

## Wizard

| Method | Path | Access | Permission | Purpose |
| - | - | - | - | - |
| `GET` | `/contract/{id}/state` | Session | `contract:state` | Read the full `ContractState` |
| `POST` | `/contract/{id}/start` | Session | `contract:start` | Record that the wizard started |
| `PATCH` | `/contract/{id}/identity` | Session | `contract:identity` | Verify the RUT and identity card with Floid |
| `PATCH` | `/contract/{id}/summary` | Holder | `contract:summary` | Accept and freeze the contract summary |
| `PATCH` | `/contract/{id}/signer-summary` | Session | `contract:summary` | A later company administrator confirms the frozen summary |
| `PATCH` | `/contract/{id}/payment/period` | Holder | `contract:payment` | Store the billing period |
| `PATCH` | `/contract/{id}/payment` | Holder | `contract:payment` | Start a Fintoc card or bank-account enrollment |
| `PATCH` | `/contract/{id}/payment/confirm` | Holder | `contract:payment` | Confirm the method and period; start the signing pipeline |
| `POST` | `/contract/{id}/rewind` | Holder | `contract:rewind` | Move the contract back one step before anyone signs (the portal does not call it) |
| `PATCH` | `/contract/{id}/password` | Session | `contract:password` | Create the portal password and get the sign-in handoff |

## Signing

| Method | Path | Access | Permission | Purpose |
| - | - | - | - | - |
| `POST` | `/contract/{id}/signature/send` | Session | `contract:signature-send` | Start the signing pipeline if it is not running (idempotent in `pending_signature`, `in_signature`, `partially_signed`, `signed` and `active`; `409` in any other status that is not `draft` and while the summary or the payment is not confirmed; `404` when no billing period was stored) |
| `POST` | `/contract/{id}/signature` | Staff | `contract:signature` | Start the signing pipeline from the back office |
| `GET` | `/contract/{id}/preview.pdf` | Session | `contract:summary` | The contract or annex PDF: sealed, else original, else a preliminary one (`kind` query: `contract` or `annex`) |
| `POST` | `/signature/{id}/signer/{signer}/otp` | Seat | `signature:signer-otp` | Email a one-time signing code |
| `POST` | `/signature/{id}/signer/{signer}/sign` | Seat | `signature:signer-sign` | Sign every document, or reject (`action`) |

## Review and back office

| Method | Path | Access | Permission | Purpose |
| - | - | - | - | - |
| `PATCH` | `/contract/{id}/review` | Staff | `contract:review` | Approve a contract in `pending_review`, or reject it from `pending_review` or `awaiting_enterprise_signature` (`state` and `user`; a reject needs a `reason`) |
| `POST` | `/contract/{id}/cancel` | Holder or Staff | `contract:cancel` / `contract:cancel-admin` | Cancel the contract, its signature group and, when it applies, the subscription (`actor`: `client` or `admin`) |
| `POST` | `/admin/contract/{id}/force-status` | Staff | `contract:force-status-admin` | Set a status directly, with a mandatory `reason`; the change is logged |
| `GET` | `/contract/{id}/evidence` | Staff | `contract:evidence` | Export the evidence package of a contract |

> [!NOTE]
>
> `POST /contract/{id}/payment/return` belongs to the previous payment gateway;
> for an account-holder session it answers `410 payment-return-deprecated`.
> `POST /contract/{id}/payment/enrollment-notify` is a local-development
> helper that answers `404` on deployed environments.

## Error codes

Business errors carry a stable code in the error message, so the portal can
react without parsing text. The response envelope is described in
[Errors](https://docs.bbrands.io/documentation/errors.md).

| Code | HTTP | Raised by | Meaning |
| - | - | - | - |
| — | `409` | `…/sessions` | The one-time link was already used |
| — | `410` | `…/sessions` | The one-time link expired |
| `identity-not-validated` | `409` | `…/summary`, `…/signer-summary` | Identity must be verified first |
| `rut-mismatch` | `409` | `…/identity` | The RUT is not the one registered for the signer |
| `identity-rejected` | `422` | `…/identity` | Floid reports the card as not active |
| `invalid-stage` | `409` | Summary, signer summary, payment, rewind, password | The contract is not at the step this call belongs to |
| `summary-not-accepted` | `409` | Payment | The summary step is not done |
| `pac-already-enrolled` | `409` | `…/payment` | The account already has a usable bank-account mandate |
| `payment-method-required` | `409` | `…/payment/confirm` | No enrolled method to confirm |
| `invalid-payment-method` | `409` | `…/payment/confirm` | The method does not belong to the account or cannot be used |
| `signer-tax-id-missing` | `409` | `…/payment` | The account has no tax id |
| `customer-already-signed` | `409` | Payment, `…/rewind` | A customer signed; the earlier steps are locked |
| `unsupported-status` | `409` | Payment, `…/rewind` | The contract is no longer in `draft`, `pending_signature` or `in_signature`; the earlier steps are locked |
| `reentry-serial-required` | `422` | `…/otp`, `…/sign` (sign and reject) | A re-entry session must prove the card serial first |
| `prior-signer-pending` | `409` | `…/otp`, `…/sign` | The previous company administrator has not signed |
| — | `409` | Cancel, recovery | The contract is in a final status |
| — | `429` | Recovery | The resend limit is spent |

## API reference

The contracting routes are not part of the generated API Reference tab yet.
Until they are, this page is the index, and the step pages describe the
bodies.

## Code

| Concern | Path |
| - | - |
| Contract routes | `app/api/v3/contract/[document_id]/` |
| Registration and lookup | `app/api/v3/auth/register/contract/`, `app/api/v3/auth/contract/lookup-by-email/` |
| Signer routes | `app/api/v3/signature/[document_id]/signer/[signer_id]/` |
| Force status | `app/api/v3/admin/contract/[id]/force-status/` |
| Public permission allowlist | `database/database.public-actions.ts` |

Paths are relative to `backend/horizon-api/`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.