{
  "openapi": "3.1.0",
  "info": {
    "title": "Grocery Stats",
    "version": "1.0.0",
    "description": "Independent UK supermarket data. Prices are dated online observations, not live quotes or stock guarantees. The public website includes a free CSV sample. API accounts receive 100 free credits each UTC calendar month.",
    "contact": {
      "name": "Joe Keene",
      "email": "joe@keene.dev",
      "url": "https://grocerystats.com/docs"
    }
  },
  "servers": [
    {
      "url": "https://grocerystats.com/api/v1"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/products": {
      "get": {
        "summary": "Search recorded UK supermarket products",
        "description": "One credit per successful page, including an empty result. At most 20 results. Keep your API key on your server.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "At least three consecutive letters or digits; maximum 100 characters",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "description": "Use the returned next_offset",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 10000
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful lookup",
            "headers": {
              "X-Credits-Used": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-Credits-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Product"
                      }
                    },
                    "next_offset": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key"
          },
          "402": {
            "description": "Credits exhausted"
          },
          "429": {
            "description": "Rate limited; inspect Retry-After"
          }
        }
      }
    },
    "/products/{id}/prices": {
      "get": {
        "summary": "Compare a listing with conservative pack matches",
        "description": "One credit. Matching uses brand, name and structured pack size; some listings have one shop.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Listing ID returned by search",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful lookup",
            "headers": {
              "X-Credits-Used": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-Credits-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "product_id": {
                      "type": "integer"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Product"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key"
          },
          "402": {
            "description": "Credits exhausted"
          },
          "429": {
            "description": "Rate limited; inspect Retry-After"
          }
        }
      }
    },
    "/products/barcode/{gtin}": {
      "get": {
        "summary": "Look up a barcode across matched retailers",
        "description": "One credit per successful lookup. Preserve leading zeroes. Inspect pack_size_check and each observed_on date. Barcode rows include additional metadata when available.",
        "parameters": [
          {
            "name": "gtin",
            "in": "path",
            "required": true,
            "description": "GTIN-8, UPC-A, EAN-13 or GTIN-14, with check digit",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "retailer",
            "in": "query",
            "required": false,
            "description": "Issuing retailer for shop-specific codes, e.g. sainsburys",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Successful lookup",
            "headers": {
              "X-Credits-Used": {
                "schema": {
                  "type": "integer"
                }
              },
              "X-Credits-Remaining": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "gtin": {
                      "type": "string"
                    },
                    "pack_size_check": {
                      "enum": [
                        "agree",
                        "conflict",
                        "unknown",
                        "single_shop"
                      ]
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Product"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Invalid API key"
          },
          "402": {
            "description": "Credits exhausted"
          },
          "429": {
            "description": "Rate limited; inspect Retry-After"
          }
        }
      }
    },
    "/credits": {
      "get": {
        "summary": "Check shared credit balance",
        "description": "Free. Does not spend a lookup credit.",
        "responses": {
          "200": {
            "description": "Account credit balance"
          },
          "401": {
            "description": "Invalid API key"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Named Grocery Stats API key"
      }
    },
    "schemas": {
      "Product": {
        "type": "object",
        "required": [
          "id",
          "name",
          "retailer",
          "price_gbp",
          "observed_on"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "retailer": {
            "type": "string"
          },
          "pack_size": {
            "type": [
              "string",
              "null"
            ]
          },
          "pack_unit": {
            "type": [
              "string",
              "null"
            ]
          },
          "price_gbp": {
            "type": "number",
            "description": "Recorded shelf price in GBP"
          },
          "offer_price_gbp": {
            "type": [
              "number",
              "null"
            ]
          },
          "observed_on": {
            "type": "string",
            "format": "date"
          },
          "source_url": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    }
  },
  "externalDocs": {
    "url": "https://grocerystats.com/docs",
    "description": "Endpoint examples and data coverage"
  }
}
