# WanaShop API

> WanaShop is a lightweight headless e-commerce back office. A merchant manages products from a phone app; any website reads the catalogue through this public API. All amounts are integers in cents. Responses are JSON.

Base URL: https://api.wanashop.fr/v1
Version: v1 (fields are only ever added within v1)

## Authentication

Send the shop's public key in every request:

    Authorization: Bearer pk_live_...

- A public key (pk_live_... or pk_test_...) only reads published products. It is safe in browser code.
- Never use a secret key (sk_...) in a website. Secret keys are for the merchant's scripts and the MCP server.
- CORS is open to every origin by default, so calls from the browser and from preview tools work.

## Routes

### GET /products

Published products, newest first.

Query parameters (all optional):
- category: a category slug from GET /categories. Includes its sub-categories.
- q: text search in title and description.
- sort: newest (default), price_asc, price_desc.
- limit: 1 to 100, default 20.
- cursor: the next_cursor value from the previous page.

Response:

    { "data": [Product, ...], "next_cursor": "..." | null }

When next_cursor is null, there are no more pages.

### GET /products/{slug}

One published product, by its slug (not its title or id). Response: a Product.

### GET /categories

    { "data": [{ "slug": "deco", "name": "Déco", "parent": null, "product_count": 12 }, ...] }

Categories have two levels at most. parent is the slug of the parent category, or null.

### POST /checkout

Not available yet. Show prices and availability without a buy button for now.

## Product

    {
      "id": "prod_8f2k...",
      "slug": "veste-en-jean-vintage",
      "title": "Veste en jean vintage, coupe droite",
      "description": "Veste en jean des années 90...",
      "price": 4500,
      "compare_at_price": null,
      "currency": "EUR",
      "category": { "slug": "mode", "name": "Mode" },
      "images": ["https://api.wanashop.fr/i/shop_.../abc.jpg"],
      "attributes": { "Couleur": "Bleu délavé", "Taille": "M" },
      "variants": [{ "id": "var_3c9d...", "options": {}, "price": 4500, "available": true }],
      "available": true
    }

- price and compare_at_price are in cents: 4500 means 45.00. Format them with the currency.
- compare_at_price, when set, is the former price: show it struck through.
- available is false when every variant is sold out: show "Épuisé" (sold out). The exact stock is never exposed.
- variants: every product has at least one. A product without options has one variant with options {}. Otherwise options holds e.g. { "Taille": "M" }: show one choice per variant.
- images: the first one is the main photo. Add ?w=400, ?w=800 or ?w=1600 to any image URL for a resized copy.

## Errors

Every error has the same shape:

    { "error": { "code": "not_found", "message": "...", "doc_url": "..." } }

The message says what is wrong and how to fix it. Codes:

<a id="error-invalid-request"></a>
- invalid_request (400): a parameter is missing or malformed. Read the message and fix the parameter.

<a id="error-unauthorized"></a>
- unauthorized (401): the key is missing, unknown or revoked. Send Authorization: Bearer pk_live_... with the key from the WanaShop app (Mon site).

<a id="error-origin-not-allowed"></a>
- origin_not_allowed (403): the merchant restricted the key to some domains. Call from an allowed domain or from the server.

<a id="error-not-found"></a>
- not_found (404): the product, category or route does not exist. Use slugs from GET /products and GET /categories.

<a id="error-out-of-stock"></a>
- out_of_stock (409): a variant in the cart is no longer available (checkout, coming soon).

<a id="error-rate-limited"></a>
- rate_limited (429): too many calls. Wait for the number of seconds in the Retry-After header.

<a id="error-internal-error"></a>
- internal_error (500): a problem on WanaShop's side. Retry after a few seconds.

## Caching

Responses are never stored by shared caches; the visitor's browser may keep them for 30 seconds. A product the merchant publishes shows up within a minute. If you cache on your own server (static site, ISR), keep it to a few minutes and key it per shop.

## Building a site

1. Catalogue page: GET /products, paginate with next_cursor.
2. Category filter: GET /categories, then GET /products?category={slug}.
3. Product page: GET /products/{slug}, rendered on the server when the framework allows it, for search engines.
4. Images: ?w=400 in grids, ?w=1600 on the product page.
5. Keep the site's own design. Prices in cents, formatted in the shop's currency.

## For the merchant's AI assistant (MCP)

The merchant can connect an AI assistant to manage the shop through MCP: https://api.wanashop.fr/mcp (Streamable HTTP, Authorization: Bearer sk_live_...). Tools: get_integration_guide, list_products, get_product, list_categories.
