# Onboarding customers

Create customers from your systems, follow their KYB case and react to customer events with an operator key.

An operator key can bring customers onto the platform from the operator's CRM or onboarding funnel. The key creates the customer and invites its primary owner; the owner then completes onboarding (KYB for businesses, KYC for individuals) in the web app. Decisions on KYB, access and closure stay with operator staff.

```sh
export WIREBLOOM_API_URL=https://api.staging.banking.wirebloom.com/v1
export WIREBLOOM_OPERATOR_ID=<your operator id>
auth=(-H "Authorization: Bearer $WIREBLOOM_API_KEY" -H "X-Tenant-Id: $WIREBLOOM_OPERATOR_ID")
json=(-H "Content-Type: application/json")
```

Scopes: `customers:write` to create, `customers:read` to list and read, `onboarding:read` for the KYB case, `webhooks:manage` for events, `customers:manage` for notes, limits and pricing.

## Before the first customer

An operator owner sets the e-mail domains that keys may invite in the operator settings (`settings.apiKeyInvitationDomains`, changed in the console only). The list protects against a leaked key inviting arbitrary addresses:

- no domains configured: `422` with `errors[].code` `invitation_domains_required`;
- the primary owner's address on another domain: `422` `domain_not_approved`;
- both are checked before anything is written.

Each key may create 10 customers a minute; above that the answer is `429` [`rate-limited`](/errors#rate-limited) with `Retry-After`.

## Create a customer

[createCustomer](/operator/reference/tenants#createCustomer) creates a `draft` customer and, with `primaryOwner`, emails the owner an invitation that names the operator. Send an `Idempotency-Key` so a retry never creates two customers ([Idempotency](/docs/idempotency)).

```sh
curl -X POST "$WIREBLOOM_API_URL/customers" "${auth[@]}" "${json[@]}" \
  -H "Idempotency-Key: crm-account-88231" \
  -d '{ "legalName": "Northwind Trading Ltd", "tradingName": "Northwind",
        "customerType": "business", "incorporationCountry": "GB",
        "registrationNumber": "09876543",
        "primaryOwner": { "email": "owner@northwind.example", "firstName": "Ada", "lastName": "Moss" },
        "metadata": { "crmId": "88231" } }'
```

| Field               | Notes                                                                                      |
| ------------------- | ------------------------------------------------------------------------------------------ |
| `customerType`      | `business` (KYB: company, persons, company documents), `sole_trader` or `individual` (KYC) |
| `pricingTemplateId` | optional; otherwise the operator's default pricing applies                                 |
| `metadata`          | up to 20 string keys of your own, for example your CRM id                                  |

Use `metadata` to find the customer later: `GET /customers?filter[metadata.crmId]=88231` ([listCustomers](/operator/reference/tenants#listCustomers), exact match, up to 5 metadata filters).

```python
import os, uuid, requests

base = os.environ["WIREBLOOM_API_URL"]
headers = {"Authorization": f"Bearer {os.environ['WIREBLOOM_API_KEY']}",
           "X-Tenant-Id": os.environ["WIREBLOOM_OPERATOR_ID"]}
r = requests.post(f"{base}/customers", headers={**headers, "Idempotency-Key": str(uuid.uuid4())},
                  json={"legalName": "Northwind Trading Ltd", "incorporationCountry": "GB",
                        "primaryOwner": {"email": "owner@northwind.example",
                                         "firstName": "Ada", "lastName": "Moss"}})
r.raise_for_status()
customer_id = r.json()["id"]
```

## Follow the KYB case

Read the onboarding case with [getKybCase](/operator/reference/onboarding#getKybCase) (`onboarding:read`). It carries the case `status` (`draft`, `submitted`, `in_review`, `info_requested`, `approved`, `declined`, `on_hold`), the steps the applicant has completed, what was requested and when it was submitted and reviewed. Send `If-None-Match` with the last `ETag` to get `304` when nothing changed.

```sh
curl "$WIREBLOOM_API_URL/customers/<customer id>/kyb" "${auth[@]}"
```

The console view of the same customer, with KYB status and open work items, is [getOpsCustomer](/operator/reference/operator-ops#getOpsCustomer); [listOpsCustomers](/operator/reference/operator-ops#listOpsCustomers) searches by name, customer number or registration number (`q`).

Reviewing, requesting information, approving or declining a case is done by operator staff in the console. A key never decides KYB.

## React to customer events

Rather than polling, subscribe an operator endpoint to the customer events ([Operator webhooks](/docs/operator-webhooks)):

| Event                            | When                                                               |
| -------------------------------- | ------------------------------------------------------------------ |
| `customer.created`               | a customer was created                                             |
| `customer.status_changed`        | the customer changed status, for example `submitted` to `approved` |
| `customer.provisioning_blocked`  | an approved customer waits for an active banking connection        |
| `customer.provisioning_released` | the customer was provisioned after the connection became active    |

Each payload is thin (`data.object: customer`, the id and status); re-read the customer with [getCustomer](/reference/tenants#getCustomer) before you act.

## After approval

- Set the customer's limits and pricing ([replaceCustomerLimits](/operator/reference/limits#replaceCustomerLimits), [replaceCustomerPricing](/operator/reference/fees#replaceCustomerPricing), scope `customers:manage`); see [Account and staff management](/docs/operator-account-management).
- Keep context for staff with notes ([createCustomerNote](/operator/reference/operator-ops#createCustomerNote), `customers:manage`), audited as `customer_note.created`.
- The customer's own team creates its customer-level keys in the web app (**Developers**). An operator key cannot call the customer's balances, payments or recipients, and cannot open balances on the customer's behalf.
