# Nintendo Cards Supply Partner API — v1 integration specification

Canonical URL: https://nintendocards.supply/partner-api.md
Human guide: https://nintendocards.supply/partners/api/
Base URL: https://nintendocards.supply/api/partner/v1
Version: v1
Currency: USD
Updated: 2026-11-23

This file is the complete, self-contained technical contract for integrating the
Nintendo Cards Supply partner API. It is written for a developer or an AI agent
implementing the partner side. It defines the only supported interface: a small
REST API over HTTPS for catalog, quotes, orders, code delivery, balance and
top-ups.

Commercial terms, access decisions and pricing beyond the published entry rule
are governed by the partner agreement. This document covers the technical
interface only and creates no obligation beyond that agreement.

## 1. Scope

The API lets an activated partner:

- read the current product catalog with USD sale prices and available quantity;
- create a time-limited quote for a basket of products;
- create an idempotent order that reserves its total from the USD balance;
- poll order and item statuses;
- read delivered redemption codes per item;
- read balance, ledger entries and top-up history;
- create hosted top-up invoices for the USD balance;
- rehearse the entire flow against a synthetic sandbox with a test key.

There are no webhooks, callbacks, event streams, bulk code exports, subscription
management endpoints or public price lists. Polling is the only delivery signal.

## 2. Rules for an integrating AI agent

1. Work only through the documented HTTPS endpoints and fields. This file is the
   complete integration surface; undocumented behavior is not part of the
   contract and must not be relied on.
2. Do not scan, fuzz, enumerate or probe the dashboard, source code,
   configuration, database, internal files or non-partner paths. Do not attempt
   to bypass authentication, rate limits or the sandbox boundary.
3. Treat the API key as a secret. Keep it on the server, never in browser code,
   mobile binaries, public repositories, chat messages or logs.
4. Start with a test key in the sandbox. Do not create real orders until the
   sandbox acceptance checks in section 17 pass and the partner account is
   activated for the live mode.
5. Never invent an endpoint, field, status, webhook or delivery guarantee. If a
   requirement is not covered here, it is not part of the API.
6. Use one `operation_key` per logical purchase and one per logical top-up.
   Reuse it on every retry of the same operation. Never create a second key to
   "check" whether the first request succeeded.
7. Treat delivered codes as payment-adjacent secrets: store them encrypted,
   restrict access and never log them.

## 3. Base URL and environments

All requests use one base URL:

```
https://nintendocards.supply/api/partner/v1
```

Sandbox is not a separate host. The key mode selects the data domain:

| Key mode | Catalog | Balance | Orders | Top-ups |
|---|---|---|---|---|
| `live` | Current offered products | Real USD balance | Real fulfillment | Available |
| `test` | 8 fixed synthetic products | Separate synthetic USD balance | Synthetic only | Not available |

Paths and response shapes are identical in both modes. Mode-specific differences
are listed in the relevant sections. A key is bound to one mode at creation.

## 4. Authentication

Every endpoint except `GET /` requires:

```
Authorization: Bearer ncs_pk_<16 lowercase hex key id>_<64 lowercase hex secret>
```

- A key is created in the partner dashboard after API access is activated.
- The full token is shown once at creation. The server stores only a SHA-256
  hash of the secret and cannot reveal it again.
- Up to 10 active keys are allowed per mode per account.
- Each key has independent rate limits and its own `last_used_at` record.
- Revocation is immediate. A revoked, unknown or malformed key returns
  `401 invalid_api_key`.
- If API access is not active or is suspended, a valid key returns
  `403 access_inactive`.
- Send the key only over HTTPS. Do not put it in URLs, query strings, browser
  storage or client-side code.

Authentication failures do not reveal whether the key id exists.

## 5. Access and entry billing

API access is invitation-only and uses the existing private partner account.

1. An approved partner receives a partner account; public sign-up does not
   exist.
2. The account adds USD balance by paid top-ups. Verified paid top-ups totaling
   at least USD 2,500.00 (minor units `250000`) qualify the account for API
   access.
3. The entry amount is not a fee. It is credited to the same USD balance that
   pays for orders and remains fully spendable.
4. API access is activated after the entry top-ups are verified. It is not
   switched on automatically by a payment.
5. The threshold is one-time. If the balance later falls below USD 2,500.00,
   API access remains active; the next order only requires enough available
   balance for its quote.
6. Access can be suspended and keys revoked under the partner agreement. A
   suspended account receives `403 access_inactive` on every authenticated
   call.

Top-ups may be created through `POST /topups` with a live key. The minimum
top-up is USD 20.00 (minor units `2000`). A top-up is credited only after the
payment provider confirms payment.

## 6. Data conventions

- Protocol: HTTPS, JSON request and response bodies, UTF-8.
- `POST` bodies must send `Content-Type: application/json` and a non-empty JSON
  object. Maximum body size is 16 KB.
- Success responses have `"ok": true`. Failure responses have `"ok": false` and
  an `error` code.
- Identifiers are UUID strings. `operation_key` must be a UUID; prefer a
  randomly generated UUIDv4.
- Timestamps are ISO 8601 UTC strings.
- Money is always an integer amount of minor units encoded as a JSON string,
  for example `"1800"` means USD 18.00. Never send or expect floating-point
  money.
- Prices and totals are in USD. A product also carries its face-value currency
  in `denomination_currency`; that is not the purchase currency.
- Totals obey `total = sum(quantity * unit_price)` per line. Validate this on
  every response.
- Unknown extra fields may appear in responses. Ignore fields you do not need;
  do not fail on additive changes.
- Do not infer stock, price or delivery state from anything except a successful
  API response.

## 7. Quickstart

The sequence below uses a test key. Set `NCS_KEY` in the server environment; do
not paste the token into a command history you will share.

### 7.1 Confirm the key and mode

```bash
curl -s https://nintendocards.supply/api/partner/v1/account \
  -H "Authorization: Bearer $NCS_KEY"
```

A test key returns `"mode": "test"`, `"access": "active"` and
`"sandbox": { "available": "1000000" }` on first use.

### 7.2 Read the catalog

```bash
curl -s https://nintendocards.supply/api/partner/v1/catalog \
  -H "Authorization: Bearer $NCS_KEY"
```

Use a product `id` from this response. Do not use the SKU as an identifier.

### 7.3 Create a quote

```bash
curl -s https://nintendocards.supply/api/partner/v1/quotes \
  -H "Authorization: Bearer $NCS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"items":[{"product_id":"<product id>","quantity":2}]}'
```

The response contains `quote.id`, `quote.total`, `quote.expires_at` and priced
lines. A quote does not reserve stock or balance.

### 7.4 Create the order

```bash
curl -s https://nintendocards.supply/api/partner/v1/orders \
  -H "Authorization: Bearer $NCS_KEY" \
  -H "Content-Type: application/json" \
  -d '{"quote_id":"<quote id>","operation_key":"<new UUIDv4>"}'
```

Store the returned `order.id` with your own order before doing anything else.
The total is reserved from the available balance.

### 7.5 Poll the order

```bash
curl -s https://nintendocards.supply/api/partner/v1/orders/<order id> \
  -H "Authorization: Bearer $NCS_KEY"
```

Poll every 2 to 5 seconds. Stop at `delivered`, `partial` or `failed`. In the
sandbox, items become `delivered` about 5 seconds after purchase and the
transition is applied when you read the order.

### 7.6 Read codes per delivered item

```bash
curl -s https://nintendocards.supply/api/partner/v1/orders/<order id>/items/<item id>/codes \
  -H "Authorization: Bearer $NCS_KEY"
```

The number of code entries equals the item quantity. Codes are readable only
after that item is `delivered`.

A complete server-side polling helper:

```js
const base = 'https://nintendocards.supply/api/partner/v1';
const headers = {
  Authorization: 'Bearer ' + process.env.NCS_PARTNER_KEY,
  'Content-Type': 'application/json',
};

async function call(path, init = {}) {
  const response = await fetch(base + path, { ...init, headers });
  const body = await response.json();
  if (!response.ok) throw new Error(response.status + ' ' + body.error);
  return body;
}

async function waitForOrder(orderId) {
  for (let attempt = 0; attempt < 120; attempt++) {
    const { order } = await call('/orders/' + orderId);
    if (['delivered', 'partial', 'failed'].includes(order.status)) return order;
    await new Promise(done => setTimeout(done, 2000));
  }
  throw new Error('order still processing');
}
```

## 8. Endpoint reference

All paths below are relative to
`https://nintendocards.supply/api/partner/v1`.

### 8.1 GET /

Public service descriptor. No authentication and no rate limit.

Response:

```json
{
  "ok": true,
  "service": "nintendocards.supply partner API",
  "version": "v1",
  "currency": "USD",
  "docs": "https://nintendocards.supply/partners/api/",
  "spec": "https://nintendocards.supply/partner-api.md"
}
```

### 8.2 GET /account

Returns the key mode, access state, entry total, limits and, for test keys, the
sandbox balance.

| Field | Type | Meaning |
|---|---|---|
| `mode` | string | `live` or `test`. |
| `key_id` | string | 16-hex key identifier; not the secret. |
| `label` | string | Label given to the key at creation. |
| `access` | string | `active` for a usable key. |
| `entry_amount` | string | Verified entry total in USD minor units. |
| `limits` | object | Per-minute limits for this account. |
| `sandbox` | object or null | `{ "available": "<minor>" }` for test keys, otherwise `null`. |

Example for a test key:

```json
{
  "ok": true,
  "mode": "test",
  "key_id": "0123456789abcdef",
  "label": "Shop sandbox",
  "access": "active",
  "entry_amount": "250000",
  "limits": {
    "requests_per_minute": 240,
    "order_operations_per_minute": 120,
    "topups_per_minute": 12
  },
  "sandbox": { "available": "1000000" }
}
```

### 8.3 GET /catalog

Returns every currently offered product. Live keys read the current catalog;
test keys read the eight fixed sandbox products.

| Product field | Type | Meaning |
|---|---|---|
| `id` | UUID string | Product identifier used in quotes. |
| `sku` | string | Stable product SKU. |
| `name` | string | Product name. |
| `region` | string | Activation region label. |
| `region_code` | string | Short region code, for example `US`. |
| `region_type` | string | `country_or_territory` or `multi_country_region`. |
| `denomination` | number | Face value. |
| `denomination_currency` | string | ISO code of the face value, for example `USD`. |
| `currency` | string | Purchase currency; always `USD`. |
| `fulfillment_type` | string | `code` or `pin`. |
| `available_quantity` | integer | Quantity currently available. |
| `unit_price` | string | Sale price per unit in USD minor units. |

Response also has `checked_at` (server read time) and `sandbox` (boolean).

```json
{
  "ok": true,
  "checked_at": "2026-11-23T12:00:00.000Z",
  "sandbox": true,
  "products": [
    {
      "id": "11111111-1111-4111-8111-111111111111",
      "sku": "NCS-SANDBOX-US-10",
      "name": "Nintendo eShop card 10 USD (sandbox)",
      "region": "United States",
      "region_code": "US",
      "region_type": "country_or_territory",
      "denomination": 10,
      "denomination_currency": "USD",
      "currency": "USD",
      "fulfillment_type": "code",
      "available_quantity": 1000,
      "unit_price": "900"
    }
  ]
}
```

Product IDs in live mode differ from sandbox IDs. Always re-read the catalog
for the mode in use.

### 8.4 POST /quotes

Prices a basket and stores a time-limited quote.

Request:

| Field | Type | Rules |
|---|---|---|
| `items` | array | 1 to 20 entries. |
| `items[].product_id` | UUID string | A product `id` from `/catalog`. |
| `items[].quantity` | integer | 1 to 500. |
| `items[].product_id` | unique | The same product may not appear twice in one quote. |

```json
{
  "items": [
    { "product_id": "11111111-1111-4111-8111-111111111111", "quantity": 2 }
  ]
}
```

Response:

```json
{
  "ok": true,
  "quote": {
    "id": "22222222-2222-4222-8222-222222222222",
    "total": "1800",
    "currency": "USD",
    "expires_at": "2026-11-23T12:02:30.000Z",
    "sandbox": true,
    "items": [
      {
        "product": { "sku": "NCS-SANDBOX-US-10", "denomination": 10, "region_code": "US" },
        "quantity": 2,
        "unit_price": "900",
        "total": "1800"
      }
    ]
  }
}
```

Rules:

- The request total must not exceed USD 9,999,999,999.99 (minor units
  `999999999999`).
- A quote expires at `expires_at`. The sandbox lifetime is 150 seconds; live
  quotes follow the returned value, which is derived from supplier price
  validity and is normally a few minutes.
- A quote does not reserve stock or money. Stock is validated again when code
  fulfillment starts; a failed item releases its value.
- If a product is unavailable or the requested quantity exceeds available
  stock, the response is `404 product_not_available` or `409 stock_changed`.
- Quotes are not idempotent. Create a new quote for a new purchase attempt or
  after expiry.

### 8.5 POST /orders

Creates an order from a quote and reserves the total from available balance.

Request:

| Field | Type | Rules |
|---|---|---|
| `quote_id` | UUID string | An unexpired quote owned by this account. |
| `operation_key` | UUID string | Your idempotency key for this logical purchase. |

```json
{
  "quote_id": "22222222-2222-4222-8222-222222222222",
  "operation_key": "44444444-4444-4444-8444-444444444444"
}
```

Response:

```json
{
  "ok": true,
  "order": {
    "id": "55555555-5555-4555-8555-555555555555",
    "total": "1800",
    "created_at": "2026-11-23T12:00:10.000Z",
    "status": "processing",
    "charged": "1800",
    "reserved": "0",
    "released": "0",
    "items": [
      {
        "id": "66666666-6666-4666-8666-666666666666",
        "product": { "sku": "NCS-SANDBOX-US-10", "denomination": 10, "region_code": "US" },
        "quantity": 2,
        "unit_price": "900",
        "total": "1800",
        "status": "processing",
        "delivered_at": null
      }
    ]
  }
}
```

Order fields:

| Field | Type | Meaning |
|---|---|---|
| `id` | UUID string | Order identifier; use it for polling. |
| `total` | string | Order total in USD minor units. |
| `created_at` | timestamp | Order creation time. |
| `status` | string | `processing`, `delivered`, `partial`, `failed` or `review`. |
| `charged` | string | Value already charged for delivered items. |
| `reserved` | string | Value currently held for items that are not final. |
| `released` | string | Value released for failed items. |
| `items` | array | Item lines with their own identifiers and statuses. |

Item fields: `id`, `product`, `quantity`, `unit_price`, `total`, `status`,
`delivered_at`, and for live failed items `failure_code` with one of
`quote_expired`, `supplier_rejected` or `delivery_failed`.

Behavior:

- The total is checked against available balance. Insufficient balance returns
  `409 insufficient_balance` and creates no order.
- An expired quote returns `409 quote_expired` and creates no order.
- The same `operation_key` with the same `quote_id` returns the existing order
  with HTTP 200, even after delivery. This is the safe retry path.
- The same `operation_key` with a different quote returns
  `400 invalid_request`.
- A quote can produce only one order. Repeating the request without an
  `operation_key` match is not a second purchase.
- Live fulfillment is asynchronous per item. Sandbox items become delivered
  about 5 seconds after purchase.
- In sandbox orders, `charged` shows the synthetic total and `reserved` is `0`
  for the whole lifecycle. In live orders, `charged` starts at `0` and
  `reserved` holds the undelivered value.

### 8.6 GET /orders

Returns up to 100 most recent orders for the account, newest first.

```json
{ "ok": true, "orders": [ { "id": "55555555-5555-4555-8555-555555555555", "status": "processing" } ] }
```

Entries use the same order shape as `POST /orders`. In sandbox mode, statuses
are refreshed with the server clock when the list is read.

### 8.7 GET /orders/{order_id}

Returns one order in the same shape. This is the polling endpoint.

- An unknown or foreign order id returns `404 not_found`.
- Poll every 2 to 5 seconds; stop at `delivered`, `partial` or `failed`.

### 8.8 GET /orders/{order_id}/items/{item_id}/codes

Returns the delivered redemption values for one item.

```json
{
  "ok": true,
  "item": {
    "id": "66666666-6666-4666-8666-666666666666",
    "quantity": 2,
    "codes": [
      { "code": "NCS-SANDBOX-US-10-A1B2C3D4E5F6", "pin": null, "expires_at": null }
    ],
    "sandbox": true
  }
}
```

- The `codes` array length equals the item quantity.
- Each entry has `code`, `pin` and `expires_at`. Either `code` or `pin` may be
  the redeemable value; both are sensitive.
- The endpoint returns `404 not_found` until the item is delivered.
- Reads are recorded in the access audit. Do not poll this endpoint; poll the
  order first.
- There is no bulk export of codes.

### 8.9 GET /balance

Returns the USD balance for the key's account.

```json
{
  "ok": true,
  "balance": {
    "currency": "USD",
    "available": "998200",
    "reserved": "0",
    "revision": "4",
    "sandbox": true
  }
}
```

| Field | Meaning |
|---|---|
| `available` | Spendable USD minor units. |
| `reserved` | Held by processing orders. |
| `revision` | Increases on each balance change; useful for detecting a stale cache. |
| `sandbox` | Present only for a test key. |

For a test key the values come from the sandbox wallet; live and sandbox
balances are independent.

### 8.10 GET /ledger

Returns up to 100 most recent balance entries, newest first.

```json
{
  "ok": true,
  "entries": [
    {
      "id": "77777777-7777-4777-8777-777777777777",
      "kind": "order_reserve",
      "available_delta": "-1800",
      "reserved_delta": "1800",
      "available_after": "998200",
      "reserved_after": "1800",
      "description": "Order reservation",
      "created_at": "2026-11-23T12:00:10.000Z"
    }
  ]
}
```

Entry kinds include `topup_credit`, `order_reserve`, `order_capture` and
`order_release`. Deltas are signed USD minor-unit strings; `*_after` fields are
the balance state after the entry. A test key returns an empty list with
`"sandbox": true`.

### 8.11 GET /topups

Returns up to 30 most recent top-ups for a live key, newest first.

```json
{
  "ok": true,
  "topups": [
    {
      "id": "88888888-8888-4888-8888-888888888888",
      "amount": "250000",
      "currency": "USD",
      "invoice_id": "INV-XXXXXXXXXXXX",
      "status": "pending",
      "expires_at": "2026-11-23T12:30:00.000Z",
      "paid_at": null,
      "created_at": "2026-11-23T12:00:00.000Z",
      "last_checked_at": null
    }
  ]
}
```

The list does not include a payment link. Use `GET /topups/{topup_id}` for the
current link. A test key returns an empty list with `"sandbox": true`.

### 8.12 POST /topups

Creates a hosted top-up invoice for a live key.

Request:

| Field | Type | Rules |
|---|---|---|
| `amount` | decimal string | USD 20.00 to USD 9,999,999,999.99, up to 2 decimal places. |
| `operation_key` | UUID string | Your idempotency key for this logical top-up. |

```json
{ "amount": "2500.00", "operation_key": "99999999-9999-4999-8999-999999999999" }
```

Response:

```json
{
  "ok": true,
  "topup": {
    "id": "88888888-8888-4888-8888-888888888888",
    "amount": "250000",
    "currency": "USD",
    "invoice_id": "INV-XXXXXXXXXXXX",
    "status": "pending",
    "expires_at": "2026-11-23T12:30:00.000Z",
    "paid_at": null,
    "created_at": "2026-11-23T12:00:00.000Z",
    "last_checked_at": null,
    "payment_url": "https://<hosted payment page>"
  }
}
```

- Open `payment_url` in a browser to pay. It is present only while the invoice
  is payable.
- The same `operation_key` with the same amount returns the same top-up with
  HTTP 200. A different amount returns `400 invalid_request`.
- Payment is credited only after provider confirmation. Returning from the
  payment page is not confirmation.
- A test key receives `400 sandbox_topups_not_available`.
- If invoicing is temporarily unavailable, the response is
  `503 payments_not_available`.

Top-up statuses: `pending`, `paid`, `expired`, `failed`. Only `paid` increases
the balance. `expired` and `failed` top-ups never credit; create a new top-up
with a new `operation_key` to retry.

### 8.13 GET /topups/{topup_id}

Returns one top-up for a live key, including `payment_url` while payable.

- An unknown top-up id returns `404 not_found`.
- A test key returns `404 not_found`.
- Poll this endpoint after payment if the balance has not changed yet; do not
  create a second invoice for the same payment.

### 8.14 POST /sandbox/reset

Deletes the account's sandbox quotes and orders and restores the sandbox
balance. Requires a test key and an empty JSON object body.

```bash
curl -s -X POST https://nintendocards.supply/api/partner/v1/sandbox/reset \
  -H "Authorization: Bearer $NCS_KEY" \
  -H "Content-Type: application/json" \
  -d '{}'
```

```json
{ "ok": true, "sandbox": { "available": "1000000" } }
```

- Limited to 6 calls per minute per key.
- A live key receives `400 sandbox_key_required`.
- Reset never touches live balance, live orders or real codes.

## 9. Order lifecycle

A live order starts in `processing` and moves per item. Order status is derived
from its items:

| Status | Meaning |
|---|---|
| `processing` | At least one item is queued, submitting or pending. Keep polling. |
| `delivered` | Every item is delivered; codes can be read. |
| `partial` | Some items delivered and some failed; delivered codes are readable and failed value is released. |
| `failed` | Every item failed; the reserved value is released. |
| `review` | At least one item needs server-side review; the value stays reserved. Keep polling. |

Item statuses:

| Status | Meaning |
|---|---|
| `queued` | Saved, not yet sent for fulfillment. |
| `submitting` | Fulfillment request in progress. |
| `pending` | Accepted, waiting for delivered codes. |
| `delivered` | Codes are stored and readable through the codes endpoint. |
| `failed` | Not delivered; `failure_code` explains why and the value is released. |
| `review` | Under server-side review; the value stays reserved. |

Balance effects:

- On order creation the total is reserved: `available` decreases and
  `reserved` increases.
- A delivered item is charged: its value leaves `reserved` and appears in
  `charged`.
- A failed item is released: its value returns to `available` and appears in
  `released`.
- A `partial` order has both a charge and a release.

In the sandbox, items are `processing` for about 5 seconds and then
`delivered`. Sandbox order totals are synthetic; `charged` shows the order
total from creation and `reserved` stays `0`.

## 10. Polling and retry

There are no webhooks or push notifications.

Recommended loop:

1. After `POST /orders`, store `order.id` with your own order.
2. Poll `GET /orders/{order_id}` every 2 to 5 seconds with a bounded backoff.
3. Stop at `delivered`, `partial` or `failed`.
4. On `partial`, read codes for delivered items and handle failed items
   according to your own customer policy.
5. On `review`, keep polling with a longer interval; do not create a
   replacement order.
6. Read codes per delivered item and store them securely.

Retry rules by failure:

| Failure | Action |
|---|---|
| Network error or timeout on `POST /orders` | Retry the same request with the same `operation_key`. |
| `429 rate_limited` | Wait for `Retry-After` seconds, then retry. |
| `503` codes marked retryable | Retry with backoff; no order was created. |
| `409 quote_expired` | Create a new quote, then create a new order with a new `operation_key`. |
| `409 balance_changed_refresh` | Retry the same order request with the same `operation_key`. |
| `409 insufficient_balance` | Add balance, then create a new quote and a new order. |
| `400 invalid_request` | Fix the request. Do not retry unchanged. |

Never delete or replace a stored `operation_key` because a request timed out.
The original request may have succeeded.

## 11. Idempotency

`operation_key` is the only idempotency mechanism. It is required on
`POST /orders` and `POST /topups`.

- One key per logical purchase or top-up; reuse it for every retry.
- The server stores the key and the original result.
- Same key and same operation: HTTP 200 with the original order or top-up.
- Same order key with a different quote: `400 invalid_request`.
- Same top-up key with a different amount: `400 invalid_request`.
- A new purchase needs a new quote and a new `operation_key`; never reuse a key
  from a completed order.
- Quotes themselves are not idempotent. A retried quote creates a new quote,
  which is harmless because a quote reserves nothing.

Recommended mapping: generate one UUIDv4 when you create your own order row and
persist it next to that row before calling the API.

## 12. Rate limits

Limits are fixed one-minute windows per key, not sliding windows or monthly
quotas.

| Scope | Per minute | Applies to |
|---|---|---|
| All authenticated requests | 240 | Every endpoint called with one key. |
| Order operations | 120 | Quote creation and order creation. |
| Top-up creation | 12 | Live keys only. |
| Sandbox reset | 6 | Test keys only. |

A throttled call returns HTTP 429:

```json
{ "ok": false, "error": "rate_limited", "retry_after": 60 }
```

The `Retry-After` header carries the same number of seconds. The window resets
at the next minute boundary. `GET /` is public and not throttled.

Additional transport limits: JSON bodies are limited to 16 KB, `POST` requires
`Content-Type: application/json`, and unknown paths return `404 not_found`.

## 13. Errors

Failure responses use HTTP status plus a stable lowercase `error` code. A
message is not part of the contract; branch on the status and code.

| HTTP | Code | Retry | Meaning |
|---|---|---|---|
| 400 | `invalid_request` | No | Malformed body, invalid field values, or a reused operation key with different order content. |
| 400 | `invalid_items` | No | Quote basket outside 1-20 unique lines or quantity outside 1-500. |
| 400 | `sandbox_key_required` | No | Sandbox reset called with a live key. |
| 400 | `sandbox_topups_not_available` | No | A test key tried to create a top-up. |
| 400 | `topup_amount_invalid` | No | Top-up amount outside USD 20.00-9,999,999,999.99, or not a decimal string. |
| 401 | `invalid_api_key` | No | Authorization header missing, malformed, unknown or revoked. |
| 403 | `access_inactive` | No | Key valid, but API access is not activated or is suspended. |
| 404 | `not_found` | No | Unknown path or unknown record for this account. |
| 404 | `product_not_available` | No | Requested product is not in the current catalog. |
| 409 | `stock_changed` | No | Requested quantity exceeds available quantity; re-quote. |
| 409 | `quote_expired` | Yes | Quote is past `expires_at`; create a new quote. |
| 409 | `insufficient_balance` | No | Available balance is below the quote total. |
| 409 | `balance_changed_refresh` | Yes | Concurrent balance change; retry the same order request. |
| 409 | `conflict` | No | Uniqueness conflict; read the current state instead of repeating blindly. |
| 413 | `request_too_large` | No | Body exceeds 16 KB. |
| 415 | `json_required` | No | `POST` body is not `application/json`. |
| 429 | `rate_limited` | Yes | Current minute limit exhausted; wait for `Retry-After`. |
| 503 | `catalog_not_available` | Yes | Live catalog or pricing is temporarily unavailable. |
| 503 | `payments_not_available` | Yes | Top-up invoicing is temporarily unavailable. |
| 503 | `supplier_response_invalid` | Yes | A fulfillment response failed server-side validation; no order was created. |
| 503 | `delivery_not_available` | Yes | A stored delivery failed validation; retry the read later. |
| 503 | `service_unavailable` | Yes | Unexpected server failure; retry with backoff. |

Do not parse human-readable text for control flow and do not retry a
non-retryable error unchanged.

## 14. Sandbox

The sandbox is the same application with a separate, synthetic data domain.

| Property | Value |
|---|---|
| Key mode | `test` |
| Starting balance | USD 10,000.00 (`"1000000"`) |
| Delivery delay | About 5 seconds, applied lazily when the order is read |
| Quote lifetime | 150 seconds |
| Codes | Synthetic, never redeemable |
| Top-ups | Not available |
| Real money or stock | Never touched |

Sandbox catalog:

| SKU | Region | Denomination | Unit price (USD) | Stock |
|---|---|---|---|---|
| `NCS-SANDBOX-US-10` | United States (US) | USD 10 | 9.00 | 1000 |
| `NCS-SANDBOX-US-25` | United States (US) | USD 25 | 22.50 | 1000 |
| `NCS-SANDBOX-US-50` | United States (US) | USD 50 | 45.00 | 1000 |
| `NCS-SANDBOX-CA-20` | Canada (CA) | CAD 20 | 15.00 | 1000 |
| `NCS-SANDBOX-GB-15` | United Kingdom (GB) | GBP 15 | 18.00 | 1000 |
| `NCS-SANDBOX-DE-25` | Germany (DE) | EUR 25 | 29.00 | 1000 |
| `NCS-SANDBOX-JP-3000` | Japan (JP) | JPY 3,000 | 20.00 | 1000 |
| `NCS-SANDBOX-FR-15` | France (FR) | EUR 15 | 18.00 | 1000 |

Sandbox codes match `NCS-SANDBOX-<REGION>-<DENOMINATION>-<12 HEX>`. They are
fake by design. Never test them against a Nintendo account or a real store.

Reset with `POST /sandbox/reset` between scenarios to delete sandbox quotes and
orders and restore USD 10,000.00. Test and live keys see different catalogs,
balances, orders and top-ups even for the same partner account.

## 15. Platform patterns

### 15.1 Online store

- Sync `/catalog` into your own product catalog; price your retail offer
  independently from the USD wholesale price.
- At checkout confirmation, create a quote for the exact basket.
- Create one order with an `operation_key` stored next to your order ID.
- Poll the order in a background job, then show codes on the customer's order
  page only after `delivered`.
- Never let the browser call the partner API directly.

### 15.2 Marketplace

- Map each marketplace order to one persisted `operation_key`.
- Run quote and order creation in a queue, not inside the marketplace webhook
  handler.
- Store delivered codes encrypted in your own database and restrict access.
- Use item status and `failure_code` to drive replacement or refund handling.
- Keep wholesale price, margin and partner credentials out of seller-facing
  interfaces.

### 15.3 Telegram bot

- Confirm payment in your own flow first, then enqueue a fulfillment job.
- Create the order once and persist `order.id` with the chat ID.
- Poll with backoff and send each code privately when the item is delivered.
- Keep the partner key on the bot server; never in client code or message logs.

### 15.4 Own panel

- Use the API as a server-side fulfillment backend behind your own staff UI.
- Cache catalog and order lists; refresh balance after each order and
  reconcile with `/ledger`.
- Use a test key in staging and a live key in production; never share one key
  across environments.
- Expose only your own authenticated interface to browsers.

## 16. Security requirements

- Send the key only in the `Authorization` header over HTTPS.
- Store the key in a server-side secret store. Do not log it, commit it or
  embed it in client applications.
- Do not log delivered codes or full response bodies containing codes.
- Store codes encrypted at rest and restrict access to the fulfillment service
  and the smallest necessary staff group.
- Rotate a key by creating a new one, deploying it, verifying traffic, then
  revoking the old one.
- Use the sandbox for integration and load tests. Do not load-test live keys.
- Do not probe undocumented paths, the dashboard, source, configuration or the
  database. Access outside the documented surface is not authorized.
- Treat a compromised key as an incident: revoke it, create a replacement and
  review your logs for unauthorized calls. The server records code reads in its
  access audit, but your own logs remain your responsibility.

## 17. Integration acceptance criteria

An integration is ready for live traffic when all of the following pass with a
test key:

1. `GET /` returns `version: "v1"` without a key.
2. `GET /account` returns `mode: "test"`, `access: "active"` and a
   `sandbox.available` value of `"1000000"` on first use.
3. `GET /catalog` returns 8 sandbox products whose `unit_price` values match
   section 14.
4. A quote for any catalog line returns a `total` equal to
   `quantity * unit_price`, a future `expires_at`, and only documented fields.
5. `POST /orders` twice with the same quote and `operation_key` returns the
   same `order.id` and HTTP 200 both times.
6. `POST /orders` with the same `operation_key` and a different quote returns
   `400 invalid_request`.
7. Polling `GET /orders/{order_id}` reaches `delivered` within about 10 seconds
   in the sandbox.
8. `GET /orders/{order_id}/items/{item_id}/codes` returns exactly `quantity`
   code entries with the documented sandbox pattern.
9. `GET /balance` decreases by the quote total, and `GET /ledger` contains the
   reservation and capture entries.
10. `POST /sandbox/reset` restores `sandbox.available` to `"1000000"` and clears
    sandbox orders.
11. A revoked or invalid key returns `401 invalid_api_key`; a test key blocked
    by the account state returns `403 access_inactive` when applicable.
12. The partner key and delivered codes never appear in application logs or
    browser traffic.

After live activation, run one minimal live smoke test:

1. Create a small live quote and record its total.
2. Create the order with a persisted `operation_key`; retry once with the same
   key and confirm the same order id.
3. Poll to a final status and read codes only for delivered items.
4. Confirm the balance decreased exactly once and the ledger shows one
   reservation and one capture for the delivered value.
5. Confirm no second order exists for the same `operation_key`.

Stop and escalate through the partner agreement if any check fails. Do not
compensate by creating additional orders.

## 18. Versioning

- The major version is part of the path: `/api/partner/v1`.
- Additive fields and new endpoints may appear without a version change; ignore
  unknown fields.
- Breaking changes require a new path version. No webhook or callback contract
  exists to version.
- The descriptor `GET /` reports the current version.

Published documentation:

- Human guide: https://nintendocards.supply/partners/api/
- Machine specification: https://nintendocards.supply/partner-api.md
