{
  "openapi": "3.1.0",
  "info": {
    "title": "RetroSwap API",
    "version": "1.1.0",
    "summary": "Read and add to one retro game store's inventory, orders, customers and sales.",
    "description": "Every request is scoped to the store that owns the API key. Store owners and admins create keys in RetroSwap under Settings > API access, choosing permissions per key. Send the key as `X-API-Key: rs_...` or `Authorization: Bearer rs_...`. Order money fields are integer cents. Inventory prices come as dollars (`sellPrice`) with integer-cent mirrors (`sellPriceCents`). Customer email, phone, notes and order shipping addresses are returned only when the store owner turns on customer contact sharing. AI assistants should use the MCP endpoint at `/mcp` (Model Context Protocol, Streamable HTTP, same API key) instead of these routes."
  },
  "servers": [
    {
      "url": "https://flippant-roadrunner-817.convex.site",
      "description": "Production"
    }
  ],
  "security": [
    {
      "apiKeyHeader": []
    },
    {
      "bearer": []
    }
  ],
  "paths": {
    "/api/v1/inventory": {
      "get": {
        "operationId": "listInventory",
        "summary": "List inventory items, newest first",
        "description": "Requires inventory:read. offset + limit may not exceed 1000; narrow with status or console.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "e.g. In Stock, Sold, Trade-In Pending"
          },
          {
            "name": "console",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact console name, e.g. N64"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Inventory items",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/InventoryItem"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, revoked or expired key, or the store is closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required permission",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createInventoryItem",
        "summary": "Add an inventory item",
        "description": "Requires inventory:write. Unknown fields, including storeId, are ignored.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/InventoryCreate"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InventoryItem"
                }
              }
            }
          },
          "400": {
            "description": "Missing title, console or itemType, or a field breaks its length, quantity or price limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, revoked or expired key, or the store is closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required permission, or the store is at its plan's item limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/inventory/{id}": {
      "get": {
        "operationId": "getInventoryItem",
        "summary": "Get one inventory item",
        "description": "Requires inventory:read.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The item",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InventoryItem"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, revoked or expired key, or the store is closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required permission",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such item in this store",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/orders": {
      "get": {
        "operationId": "listOrders",
        "summary": "List orders",
        "description": "Requires orders:read.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "pending, processing, shipped, delivered, cancelled or refunded"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Orders",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Order"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, revoked or expired key, or the store is closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required permission",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/customers": {
      "get": {
        "operationId": "listCustomers",
        "summary": "List customers",
        "description": "Requires customers:read.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Customers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Customer"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, revoked or expired key, or the store is closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required permission",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/analytics/kpis": {
      "get": {
        "operationId": "getKpis",
        "summary": "Key performance indicators for a period",
        "description": "Requires analytics:read.",
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["today", "week", "month", "quarter", "year"],
              "default": "month"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "KPIs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, revoked or expired key, or the store is closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required permission",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/stats": {
      "get": {
        "operationId": "getQuickStats",
        "summary": "Sales, stock and open work at a glance",
        "description": "Requires analytics:read or inventory:read. Amounts are dollars.",
        "responses": {
          "200": {
            "description": "Quick stats",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, revoked or expired key, or the store is closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key lacks the required permission",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded; see Retry-After",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKeyHeader": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "The same API key, rs_..."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": ["error"]
      },
      "InventoryItem": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "console": {
            "type": "string"
          },
          "region": {
            "type": "string"
          },
          "itemType": {
            "type": "string"
          },
          "productCategory": {
            "type": "string"
          },
          "condition": {
            "type": "string"
          },
          "hasBox": {
            "type": "boolean"
          },
          "hasManual": {
            "type": "boolean"
          },
          "quantity": {
            "type": "integer"
          },
          "status": {
            "type": "string"
          },
          "sellPrice": {
            "type": "number",
            "description": "Dollars"
          },
          "sellPriceCents": {
            "type": "integer"
          },
          "buyPrice": {
            "type": "number",
            "description": "Dollars the store paid"
          },
          "buyPriceCents": {
            "type": "integer"
          },
          "marketPrice": {
            "type": "number",
            "description": "Dollars"
          },
          "marketPriceCents": {
            "type": "integer"
          },
          "dateAdded": {
            "type": "string",
            "format": "date"
          },
          "upc": {
            "type": "string"
          },
          "imageUrl": {
            "type": "string"
          },
          "notes": {
            "type": "string"
          }
        }
      },
      "InventoryCreate": {
        "type": "object",
        "required": ["title", "console", "itemType"],
        "properties": {
          "title": {
            "type": "string"
          },
          "console": {
            "type": "string"
          },
          "itemType": {
            "type": "string"
          },
          "productCategory": {
            "type": "string"
          },
          "condition": {
            "type": "string"
          },
          "region": {
            "type": "string"
          },
          "sellPrice": {
            "type": "number",
            "minimum": 0,
            "description": "Dollars"
          },
          "sellPriceCents": {
            "type": "integer",
            "minimum": 0,
            "description": "Wins over sellPrice"
          },
          "buyPrice": {
            "type": "number",
            "minimum": 0,
            "description": "Dollars"
          },
          "buyPriceCents": {
            "type": "integer",
            "minimum": 0,
            "description": "Wins over buyPrice"
          },
          "quantity": {
            "type": "integer",
            "minimum": 0
          },
          "hasBox": {
            "type": "boolean"
          },
          "hasManual": {
            "type": "boolean"
          },
          "notes": {
            "type": "string"
          },
          "imageUrl": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "upc": {
            "type": "string"
          }
        }
      },
      "OrderItem": {
        "type": "object",
        "properties": {
          "inventoryId": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "console": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "price": {
            "type": "integer",
            "description": "Cents per unit"
          },
          "condition": {
            "type": "string"
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "customerId": {
            "type": "string"
          },
          "orderType": {
            "type": "string"
          },
          "orderNumber": {
            "type": "string"
          },
          "externalOrderId": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderItem"
            }
          },
          "subtotal": {
            "type": "integer",
            "description": "Cents"
          },
          "tax": {
            "type": "integer",
            "description": "Cents"
          },
          "shipping": {
            "type": "integer",
            "description": "Cents"
          },
          "discount": {
            "type": "integer",
            "description": "Cents"
          },
          "total": {
            "type": "integer",
            "description": "Cents"
          },
          "paymentStatus": {
            "type": "string"
          },
          "paymentMethod": {
            "type": "string"
          },
          "paidAt": {
            "type": "string"
          },
          "couponCode": {
            "type": "string"
          },
          "trackingNumber": {
            "type": "string"
          },
          "carrier": {
            "type": "string"
          },
          "shippedAt": {
            "type": "string"
          },
          "deliveredAt": {
            "type": "string"
          },
          "createdAt": {
            "type": "string"
          },
          "updatedAt": {
            "type": "string"
          },
          "shippingAddress": {
            "type": "object",
            "description": "Only with customer contact sharing on"
          },
          "customerNotes": {
            "type": "string",
            "description": "Only with customer contact sharing on"
          },
          "internalNotes": {
            "type": "string",
            "description": "Only with customer contact sharing on"
          }
        }
      },
      "Customer": {
        "type": "object",
        "properties": {
          "_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "createdAt": {
            "type": "string"
          },
          "isGuest": {
            "type": "boolean"
          },
          "totalTradeIns": {
            "type": "integer"
          },
          "totalValue": {
            "type": "number"
          },
          "email": {
            "type": "string",
            "description": "Only with customer contact sharing on"
          },
          "phone": {
            "type": "string",
            "description": "Only with customer contact sharing on"
          },
          "notes": {
            "type": "string",
            "description": "Only with customer contact sharing on"
          }
        }
      }
    }
  }
}
