# POST /api/v2/customers

Create a customer

- MCP id: customers.store
- Scope: api:write:customers
- Permission: customers::create
- Rate cost: 1 unit, write bucket. A write costs the same whatever `view` you ask for.
- Cache-Control: private, no-store

Creates a customer and returns it in the detail view with a `Location` header. name, code, color, status and `account_manager_id` are required: the first four have no default, and an account manager is mandatory on the customer form in plnnrly. code must be unique. color must be a CSS hex triplet or sextet; any other value would read back as #6b7280.

`tag_ids` replaces the whole tag set and may be omitted. Sending address, zip or city geocodes the address server-side and fills lat and lng, which are not writable. `debtor_code` additionally requires `billing_settings::update`.

## Parameters
- view (string, optional): Which field set to render.
- X-Request-Id (header, optional): A correlation id of your own. It is recorded in our logs next to the server's request id but never returned: the response header always carries the server's id. A value that does not match the pattern is discarded silently, never rejected.
- Idempotency-Key (header, optional): A caller-chosen key that makes this POST safe to retry. Replaying it returns the original response with Idempotency-Replayed: true.

## Request body
- name (string ≤ 255, required): Customer name. This is the default sort key and one of the fields `?q=` searches.
- code (string ≤ 255, required, unique): Short customer code, e.g. ACM. Prefixes every work item's issue key, is enforced unique on write, and is one of the fields `?q=` searches. Must be unique across Customer.
- color (string, required): Chip colour as a CSS hex triplet or sextet, e.g. #1d4ed8. A stored value that is not valid hex reads back as #6b7280.
- status (string, required): Where the customer sits in the sales lifecycle.
- account_manager_id (integer → User.id, required): Responsible account manager. Required on create; unassigned when the user is deleted.
- email (email or null ≤ 255, optional): Primary email address. The third field `?q=` searches; not unique.
- phone (string or null ≤ 255, optional): Phone number.
- address (string or null ≤ 255, optional): Street address. Writing this, zip or city re-geocodes lat and lng.
- zip (string or null ≤ 255, optional): Postal code.
- city (string or null ≤ 255, optional): City.
- country (string or null ≤ 255, optional): Country as an ISO 3166-1 alpha-2 code, e.g. NL, as plnnrly writes it. Older records may hold any string.
- founded_at (date (YYYY-MM-DD) or null, optional): Day the customer's company was founded.
- customer_since (date (YYYY-MM-DD) or null, optional): Day this customer became a customer.
- is_vat_exempt (boolean, optional): Whether invoices to this customer are issued without VAT.
- debtor_code (string or null ≤ 255, optional): Debtor number in the accounting system. Writing it requires `billing_settings::update`.
- customer_category_id (integer or null → CustomerCategory.id, optional): Customer category, or `null`.
- company_branch_id (integer or null → CompanyBranch.id, optional): Industry branch, or `null`.
- company_type_id (integer or null → id, optional): Company type, or `null`. Company types are your organisation's own list, maintained in plnnrly and not exposed as a collection.
- company_size_id (integer or null → id, optional): Company size band, or `null`. Company sizes are your organisation's own list, maintained in plnnrly and not exposed as a collection.
- tag_ids (array of integer → Tag.id ≤ 50, optional): Tags on this customer. A customer takes at most 50 tags, so the include lists them all. `tag_ids` replaces the whole set.

Unknown keys are refused with `422` validation-failed, naming the key.

## Response 201
- id (integer, required): Unique identifier.
- name (string ≤ 255, required): Customer name. This is the default sort key and one of the fields `?q=` searches.
- code (string ≤ 255, required): Short customer code, e.g. ACM. Prefixes every work item's issue key, is enforced unique on write, and is one of the fields `?q=` searches.
- color (string ≤ 255, required): Chip colour as a CSS hex triplet or sextet, e.g. #1d4ed8. A stored value that is not valid hex reads back as #6b7280.
- status (string, required): Where the customer sits in the sales lifecycle.
- email (string or null ≤ 255, required): Primary email address. The third field `?q=` searches; not unique.
- phone (string or null ≤ 255, required): Phone number.
- address (string or null ≤ 255, required): Street address. Writing this, zip or city re-geocodes lat and lng.
- zip (string or null ≤ 255, required): Postal code.
- city (string or null ≤ 255, required): City.
- country (string or null ≤ 255, required): Country as an ISO 3166-1 alpha-2 code, e.g. NL, as plnnrly writes it. Older records may hold any string.
- lat (string or null ≤ 255, required, server-assigned): Latitude, geocoded from the address whenever address, zip or city changes. Not writable.
- lng (string or null ≤ 255, required, server-assigned): Longitude, geocoded from the address whenever address, zip or city changes. Not writable.
- founded_at (date (YYYY-MM-DD) or null, required): Day the customer's company was founded.
- customer_since (date (YYYY-MM-DD) or null, required): Day this customer became a customer.
- is_vat_exempt (boolean, required): Whether invoices to this customer are issued without VAT.
- payment_days (integer or null, required, server-assigned): Payment term in days, as held by the accounting integration. Read by the invoice composer; written only by the Exact sync.
- debtor_code (string or null ≤ 255, required): Debtor number in the accounting system. Writing it requires `billing_settings::update`.
- exact_account_id (string or null ≤ 255, required, server-assigned): Account identifier in Exact Online, written by the sync.
- exact_synced_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required, server-assigned): When the Exact sync last handled this customer, or `null` if never.
- exact_keep_local_address (boolean, required, server-assigned): Whether the Exact sync leaves this customer's local address alone although it differs from the one in Exact. Set when a user accepts the difference on the Exact customers screen in plnnrly; not writable.
- account_manager_id (integer or null, required): Responsible account manager. Required on create; unassigned when the user is deleted.
- customer_category_id (integer or null, required): Customer category, or `null`.
- company_type_id (integer or null, required): Company type, or `null`. Company types are your organisation's own list, maintained in plnnrly and not exposed as a collection.
- company_size_id (integer or null, required): Company size band, or `null`. Company sizes are your organisation's own list, maintained in plnnrly and not exposed as a collection.
- company_branch_id (integer or null, required): Industry branch, or `null`.
- created_at (timestamp (YYYY-MM-DDThh:mm:ssZ), required): Creation timestamp.
- updated_at (timestamp (YYYY-MM-DDThh:mm:ssZ), required): Last-write timestamp; use for incremental sync.
- deleted_at (timestamp (YYYY-MM-DDThh:mm:ssZ) or null, required): Soft-delete timestamp, `null` while live.
- customer_category (Ref or CustomerCategorySummary or null, required): The customer's category. Rendered as {"id": N} until named in `?include=customer_category`, and `null` where none is assigned.
- company_branch (Ref or CompanyBranchSummary or null, required): The customer's industry branch. Rendered as {"id": N} until named in `?include=company_branch`, and `null` where none is assigned.
- projects_count (integer ≥ 0, required): Number of live projects for this customer. Soft-deleted projects are not counted.
- contacts_count (integer ≥ 0, required): Number of contacts on this customer.
- tags_count (integer ≥ 0, required): Number of tags on this customer.
- links (CustomerLinks, required)
  - self (url, required): The canonical URI of this record.
  - projects (url, required): Projects for this customer.
  - contacts (url, required): Contacts on this customer.
- tags (array of TagSummary ≤ 50, optional, only with include): Tags on this customer. A customer takes at most 50 tags, so the include lists them all. `tag_ids` replaces the whole set. Wrapped in `{ data, meta }`; `meta.truncated` says whether the cap was hit and `meta.count` is the full count.
  - id (integer, required): Unique identifier.
  - title (string ≤ 255, required): Tag title as shown in the UI.

## Errors
- 403 forbidden-by-policy | insufficient-permission | insufficient-token-scope: Forbidden.
- 409 idempotency-key-in-flight | idempotency-key-reused: Conflict.
- 415 unsupported-media-type: Unsupported media type.
- 422 unprocessable-relationship | validation-failed: Unprocessable content.
- 400 idempotency-key-required | invalid-cursor | invalid-query-parameter | malformed-request | unsupported-parameter: Bad request.
- 401 token-expired | unauthenticated: Unauthenticated.
- 404 endpoint-not-found | resource-not-found: Not found.
- 406 not-acceptable: Not acceptable.
- 429 rate-limit-exceeded: Too many requests.
- 500 internal-error: Server error.
- 503 tenant-unavailable: Service unavailable.

## Example
```bash
curl -X POST \
  'https://<your-url>/api/v2/customers' \
  -H 'Authorization: Bearer <token>' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: <key>' \
  -d '{
    "name": "Acme Industries",
    "code": "ACM",
    "color": "#1d4ed8",
    "status": "active",
    "email": "hello@acme.test",
    "address": "Keizersgracht 1",
    "zip": "1015 CJ",
    "city": "Amsterdam",
    "country": "NL",
    "customer_since": "2026-01-15",
    "account_manager_id": 1
  }'
```
