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

# Odoo: customer onboarding

> How Odoo creates a Maihue customer in Horizon (account, logins and onboarding) and sends the onboarding email, with an API key, idempotent retries and progress tracking.

> [!NOTE]
>
> Two calls take a customer from Odoo to the Maihue customer portal:
> **create** provisions the account, its logins (without a password) and an
> open onboarding; **invite** sends the email with the link that starts the
> onboarding. Creating never sends an email, so Odoo decides when the
> customer is contacted.

## Flow

**1. Create the customer**

`POST /maihue/onboarding` with the customer data. Horizon creates or
updates the account and its users and opens the onboarding of the
business unit (`home`, `horeca` or `business`). Store
`data.account` and `data.onboarding.document_id` on the Odoo record.

**2. Send the invitation**

`POST /maihue/onboarding/{document_id}/invite`. Horizon emails the
recipient "Activa tu cuenta Maihue" with a link valid for 24 hours.

**3. The customer completes the onboarding**

In the portal the customer accepts the terms, validates their identity,
confirms a payment method and sets a password. The onboarding moves
`created` → `invited` → `in_progress` → `completed`.

**4. Follow the progress (optional)**

`GET /maihue/onboarding/{document_id}` returns the status and the
steps.

## Before you start

| Requirement | Detail |
| - | - |
| API key | One per environment, issued by the Horizon platform team. Development and certification keys read `hzk_test_…`, production keys `hzk_live_…`. The plaintext key is shown once; store it in `ir.config_parameter` (e.g. `bbrands.api_key`), never in code. |
| Permissions of the key | `maihue-onboarding:create` and `maihue-onboarding:invite`. Add `maihue-onboarding:find-one` to follow the progress. Nothing else is needed. |
| Header | `x-api-key: <key>` on every call. No OAuth and no user session: this is a machine-to-machine integration. |
| Flag | `portal-customer-onboarding` must be on in the environment. While it is off, invitations answer `403` and the create answers `onboarding.eligible: false` with `reason: flag-off`. |
| Documents | Only Chilean RUT (`CHL_RUT`) customers onboard. |

| Environment | Base URL |
| - | - |
| Development | `https://development.api.bbrands.io/api/v3` |
| Certification | `https://certification.api.bbrands.io/api/v3` |
| Production | `https://api.bbrands.io/api/v3` |

> [!NOTE]
>
> The key is created with [`POST /permission/api-key`](https://docs.bbrands.io/api-reference/permission/api-key/create)
> and its permissions with [`POST /permission/api-key-permission`](https://docs.bbrands.io/api-reference/permission/api-key-permission/create).
> Both require platform permissions, so the platform team runs them and
> hands the key to the Odoo team through a secret channel. Rotation
> ([`rotate`](https://docs.bbrands.io/api-reference/permission/api-key/rotate)) invalidates the old
> key at once: update Odoo in the same window.

## 1. Create the customer

`POST /maihue/onboarding` ([reference](https://docs.bbrands.io/api-reference/maihue/onboarding/create.md)).
Catalog fields take stable codes, so the same payload works in every
environment.

### Field mapping

| Field | Required | Value |
| - | - | - |
| `dni` | yes | RUT of the customer with check digit, e.g. `12345678-5` (dots accepted). |
| `type_dni` | yes | `CHL_RUT`. |
| `country` | yes | `CL` (ISO 3166-1 alpha-2). |
| `type` | yes | Business unit: `home` (person account), `horeca` or `business` (company account). |
| `name` | yes | Full name of the person or legal name of the company (max 250). |
| `name_fantasy` | company | Trade name (max 250). |
| `commercial_activity` | company | Commercial activity (max 250). |
| `external_id` | recommended | Id of the customer in Odoo (e.g. the `res.partner` id), max 255. |
| `tier` | no | `free` (default), `premium` or `enterprise`. |
| `gloss` | no | Free note about the origin (max 150). |
| `users[]` | yes | At least one login, see below. |

| `users[]` field | Required | Value |
| - | - | - |
| `email` | yes | Login of the user; stored lowercased. |
| `firstname`, `lastname` | yes | Max 250 each. |
| `language` | yes | `ES`, `EN`, `FR`, `IT` or `PT`. An unknown code answers `404`. |
| `sex` | no | `MALE` or `FEMALE`; an unknown value is stored empty instead of failing. |
| `role` | no | `primary_user` (default), `legal_representative`, `billing_contact`, `service_contact`, `key_contact`, `administrator`. |
| `dni`, `type_dni` | legal representative | RUT of the person and `CHL_RUT`; required for the `legal_representative` of a company. |

> [!WARNING]
>
> The onboarding email goes to the **recipient**: the `primary_user` of a
> person account or the `legal_representative` of a company. Send that user
> in `users[]`, otherwise the onboarding cannot be opened
> (`onboarding.document_id: null`, `reason: no-eligible-recipient`).

### Request

```bash Person (home) theme={null}
curl -X POST "$HORIZON_URL/maihue/onboarding" \
  -H "x-api-key: $HORIZON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "country": "CL",
    "dni": "12345678-5",
    "external_id": "res.partner:84213",
    "name": "Juan Andrés Pérez Soto",
    "type": "home",
    "type_dni": "CHL_RUT",
    "users": [
      {
        "email": "juan.perez@example.com",
        "firstname": "Juan Andrés",
        "language": "ES",
        "lastname": "Pérez Soto",
        "role": "primary_user",
        "sex": "MALE"
      }
    ]
  }'
```

```bash Company (business) theme={null}
curl -X POST "$HORIZON_URL/maihue/onboarding" \
  -H "x-api-key: $HORIZON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "commercial_activity": "Software development",
    "country": "CL",
    "dni": "76543210-3",
    "external_id": "res.partner:91007",
    "name": "TechCorp Solutions SpA",
    "name_fantasy": "TechCorp",
    "type": "business",
    "type_dni": "CHL_RUT",
    "users": [
      {
        "dni": "11111111-1",
        "email": "maria.gonzalez@techcorp.example",
        "firstname": "María",
        "language": "ES",
        "lastname": "González",
        "role": "legal_representative",
        "type_dni": "CHL_RUT"
      },
      {
        "email": "pagos@techcorp.example",
        "firstname": "Luis",
        "language": "ES",
        "lastname": "Martínez",
        "role": "billing_contact"
      }
    ]
  }'
```

### Response

`201` when the account was created, `200` when it already existed and was
updated. Both carry the same body:

```json theme={null}
{
  "data": {
    "account": "e1d2c3b4-a596-4765-8321-0987fedcba87",
    "business_units": [
      { "business_unit": "5b8c1d2e-3f4a-4b6c-8d7e-9f0a1b2c3d4e", "created": true, "internal": "maihue_home" }
    ],
    "created": true,
    "onboarding": {
      "already_open": false,
      "business_unit": "maihue_home",
      "document_id": "3c9e7a10-2b4d-4f6a-8c1e-5d7f9a0b2c4e",
      "eligible": true,
      "pending": true,
      "reason": null,
      "status": "created"
    }
  },
  "message": "Created",
  "meta": { "correlation": "29146752-ef3a-4569-b397-ff2144412c4a", "status": 201, "timestamp": "2026-11-03T15:30:45Z" }
}
```

| Field | What Odoo does with it |
| - | - |
| `data.account` | Store it: the customer id in Horizon. |
| `data.onboarding.document_id` | Store it: the id the invitation and the progress calls use. `null` means no onboarding could be opened; read `reason`. |
| `data.onboarding.already_open` | `true` when the business unit already had an open onboarding: the id is that one and nothing new was opened. Invite it as usual. |
| `data.onboarding.eligible` | `false` means an invitation cannot be sent now; `reason` says why (`flag-off`, `no-eligible-recipient`, `onboarding-not-pending`). |
| `data.members` | Company accounts only: the person account and membership created for each login. |

## 2. Send the invitation

### By onboarding id (recommended)

`POST /maihue/onboarding/{document_id}/invite`, no body
([reference](https://docs.bbrands.io/api-reference/maihue/onboarding/invite.md)).

```bash theme={null}
curl -X POST "$HORIZON_URL/maihue/onboarding/3c9e7a10-2b4d-4f6a-8c1e-5d7f9a0b2c4e/invite" \
  -H "x-api-key: $HORIZON_API_KEY"
```

### By RUT

When Odoo did not keep the onboarding id, `POST /maihue/onboarding/send-email`
finds the account by RUT ([reference](https://docs.bbrands.io/api-reference/maihue/onboarding/send-email.md)).
Here `type` is the **account type**, not the business unit: `home` →
`person`, `horeca` and `business` → `company`. The business unit goes in
`business_unit`.

```bash theme={null}
curl -X POST "$HORIZON_URL/maihue/onboarding/send-email" \
  -H "x-api-key: $HORIZON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "business_unit": "home", "dni": "12345678-5", "type": "person", "type_dni": "CHL_RUT" }'
```

`email` (optional) picks the recipient and must be the `primary_user` or
`legal_representative`; `force: true` sends again even when an invitation is
live, at most once per minute.

### Result

| HTTP | `data.status` | Meaning | Odoo action |
| - | - | - | - |
| `202` | `enqueued` | The email is on its way. `data.notification` is its id. | Mark the record as invited. |
| `200` | `already_sent` | An invitation is already on its way or delivered. | Nothing; do not retry. |
| `200` | `skipped` | Not sent; `data.reason` says why (`type-dni-not-supported`, `no-eligible-recipient`, `onboarding-not-pending`, `notification-skipped`). | Fix the data or stop. |
| `503` | — | `invitation-not-enqueued`: Horizon could not queue it. | Retry later; it is safe. |

The email link is valid for 24 hours. To send a new one, call
[`POST /maihue/onboarding/{document_id}/resend`](https://docs.bbrands.io/api-reference/maihue/onboarding/resend)
(at most once per minute).

## 3. Follow the progress

`GET /maihue/onboarding/{document_id}` ([reference](https://docs.bbrands.io/api-reference/maihue/onboarding/find-one.md))
returns the onboarding with its `status.internal` and its `steps`.

| Status | Meaning |
| - | - |
| `created` | Opened, no invitation sent yet. |
| `invited` | Invitation sent. |
| `in_progress` | The customer opened the link or finished a step. |
| `completed` | Every required step is done. Terminal. |
| `expired` | The onboarding type's expiry passed (hourly check). Terminal. |
| `cancelled` | Cancelled by an operator. Terminal. |

A terminal status frees the business unit: the next create opens a new
onboarding.

> [!NOTE]
>
> Horizon has no "onboarding completed" event an external system can
> subscribe to yet. Poll the open onboardings (for example once a day, well
> within the rate limit) until they reach a terminal status.
> [Outbound webhooks](https://docs.bbrands.io/webhooks/introduction.md) publish `maihue-onboarding.*`
> events for the onboarding API calls (create, invite, send-email, resend,
> cancel), not for the customer's progress in the portal.

## Errors and retries

Every error answers `error.errors` with the reason and `meta.correlation`;
quote the correlation when reporting an issue to the platform team.

| HTTP | Reason | Cause | Retry? |
| - | - | - | - |
| `400` | Validation messages | Missing or invalid field, invalid RUT, company without `name_fantasy` or `commercial_activity`, legal representative without `dni`. | No; fix the payload. |
| `401` | — | Missing, invalid, inactive, revoked or expired key. | No; check the key. |
| `403` | — | The key lacks the permission, or `portal-customer-onboarding` is off. | No; ask the platform team. |
| `404` | `account-not-found`, `onboarding-not-found`, catalog value | Unknown RUT on `send-email`, unknown id, or an unknown `language`/`country` code. | No; fix the data. |
| `409` | `onboarding-closed` | The onboarding is already `completed`, `expired` or `cancelled`. | No; create again to open a new one. |
| `422` | `type-dni-not-supported`, `no-eligible-recipient`, `recipient-not-linked` | Not a RUT, no recipient user, or `email` is not the recipient. | No; fix the data. |
| `429` | — | More than the key's requests per minute (600 by default). | Yes, after `Retry-After` seconds. |
| `503` | `invitation-not-enqueued` | The invitation could not be queued. | Yes, with backoff. |
| `5xx` / timeout | — | Transient failure. | Yes, with backoff. |

**Retrying is safe.** The create is idempotent by `dni + type + type_dni`:
the same customer sent twice answers `200 Updated` and the same onboarding,
never a duplicate. The invite answers `already_sent` while an invitation is
live. A create that fails midway rolls back what it created.

## Example: Odoo server action

```python theme={null}
import requests

TIMEOUT = 20


def _horizon(env):
    params = env['ir.config_parameter'].sudo()
    return params.get_param('bbrands.api_url'), {
        'x-api-key': params.get_param('bbrands.api_key'),
    }


def onboard_partner(env, partner, payload):
    """Creates the customer in Horizon and sends the onboarding email."""
    url, headers = _horizon(env)

    created = requests.post(
        f'{url}/maihue/onboarding', json=payload, headers=headers, timeout=TIMEOUT
    )
    created.raise_for_status()
    data = created.json()['data']
    onboarding = data['onboarding']
    partner.write({
        'x_horizon_account': data['account'],
        'x_horizon_onboarding': onboarding['document_id'],
    })
    if not onboarding['document_id'] or not onboarding['eligible']:
        return onboarding['reason']

    invited = requests.post(
        f"{url}/maihue/onboarding/{onboarding['document_id']}/invite",
        headers=headers,
        timeout=TIMEOUT,
    )
    invited.raise_for_status()
    return invited.json()['data']['status']
```

`x_horizon_account` and `x_horizon_onboarding` are example custom fields on
`res.partner`; use whatever fields the Odoo module defines.

## Go-live checklist

* [ ] API key per environment with `maihue-onboarding:create`,
  `maihue-onboarding:invite` (and `maihue-onboarding:find-one`), stored
  in Odoo's system parameters.
* [ ] `portal-customer-onboarding` on in the target environment.
* [ ] One home and one company customer created and invited in
  certification; both emails received and both onboardings completed in
  the portal.
* [ ] Odoo stores `data.account` and `data.onboarding.document_id`, and
  retries `429`, `503` and `5xx` with backoff.
* [ ] A re-sent customer answers `200` with the same onboarding.

## Related

* [Maihue Onboarding API reference](https://docs.bbrands.io/api-reference/maihue/onboarding/create.md)
* [API keys](https://docs.bbrands.io/api-reference/permission/api-key/create.md)
* [Outbound webhooks](https://docs.bbrands.io/webhooks/introduction.md)


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