{
  "openapi": "3.1.0",
  "info": {
    "title": "Prisjakten API",
    "version": "1.0.0",
    "summary": "Åpne lese-endepunkter for prissammenligning i Norge.",
    "description": "Prisjakten.no sammenligner priser fra norske nettbutikker. Disse endepunktene er åpne, uten autentisering og uten registrering. Prisene endrer seg flere ganger i døgnet — oppgi alltid dato og lenk til produktsiden når du gjengir en pris.",
    "contact": {
      "name": "Prisjakten.no",
      "url": "https://prisjakten.no/for-agenter",
      "email": "hei@prisjakten.no"
    },
    "termsOfService": "https://prisjakten.no/vilkar",
    "license": {
      "name": "Kun bruk med attribusjon og lenke til kilden",
      "url": "https://prisjakten.no/vilkar"
    }
  },
  "servers": [
    {
      "url": "https://prisjakten.no"
    }
  ],
  "externalDocs": {
    "description": "For AI-agenter og utviklere",
    "url": "https://prisjakten.no/for-agenter"
  },
  "paths": {
    "/api/status": {
      "get": {
        "operationId": "hentStatus",
        "summary": "Driftsstatus og datafriskhet",
        "description": "Antall produkter og butikker i katalogen, og når dataene sist ble oppdatert. Bruk denne til å avgjøre om dataene er ferske nok før du siterer en pris.",
        "responses": {
          "200": {
            "description": "Status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          }
        }
      }
    },
    "/api/search": {
      "get": {
        "operationId": "sokProdukter",
        "summary": "Søk i produktkatalogen",
        "description": "Fritekstsøk på merke og modell. Returnerer laveste pris og antall butikker per treff. Maks 100 forespørsler per minutt per IP.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "description": "Søkeord, minst 2 tegn. Kortere søk gir tom liste.",
            "schema": {
              "type": "string",
              "minLength": 2
            },
            "example": "iphone 17"
          }
        ],
        "responses": {
          "200": {
            "description": "Inntil 10 treff",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Soketreff"
                      }
                    }
                  },
                  "required": [
                    "results"
                  ]
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/ForMangeForesporsler"
          }
        }
      }
    },
    "/api/products/{id}": {
      "get": {
        "operationId": "hentProdukt",
        "summary": "Ett produkt med alle butikktilbud",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Produktets UUID, som returnert av /api/search.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Produkt med tilbud",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Produkt"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/IkkeFunnet"
          }
        }
      }
    },
    "/api/grocery/products": {
      "get": {
        "operationId": "hentDagligvarer",
        "summary": "Dagligvarer med priser per kjede",
        "description": "Dugnadsbaserte dagligvarepriser (Brød & Melk). Prisene er rapportert av brukere og verifisert av fellesskapet, i tillegg til skrapte priser fra Oda og Meny.",
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "required": false,
            "description": "Filtrer på dagligvarekategori. Ugyldig verdi gir 400.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Dagligvarer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "products": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  },
                  "required": [
                    "products"
                  ]
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/UgyldigForesporsel"
          },
          "429": {
            "$ref": "#/components/responses/ForMangeForesporsler"
          }
        }
      }
    },
    "/api/grocery/products/{slug}": {
      "get": {
        "operationId": "hentDagligvare",
        "summary": "Én dagligvare",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "melk-helmelk-1l"
          }
        ],
        "responses": {
          "200": {
            "description": "Dagligvare",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "product": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/IkkeFunnet"
          }
        }
      }
    },
    "/api/grocery/prices/recent": {
      "get": {
        "operationId": "hentNyeDagligvarepriser",
        "summary": "Sist rapporterte dagligvarepriser",
        "parameters": [
          {
            "name": "productId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "chainId",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "1–50, standard 20.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Prisrapporter",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "prices": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  },
                  "required": [
                    "prices"
                  ]
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/ForMangeForesporsler"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "IkkeFunnet": {
        "description": "Ressursen finnes ikke",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Feil"
            }
          }
        }
      },
      "UgyldigForesporsel": {
        "description": "Ugyldige parametere",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Feil"
            }
          }
        }
      },
      "ForMangeForesporsler": {
        "description": "Over 100 forespørsler per minutt fra samme IP",
        "headers": {
          "Retry-After": {
            "schema": {
              "type": "integer"
            },
            "description": "Sekunder til kvoten nullstilles"
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Feil"
            }
          }
        }
      }
    },
    "schemas": {
      "Feil": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "Status": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degradert"
            ]
          },
          "produkter": {
            "type": "integer",
            "description": "Produkter med minst ett aktivt tilbud"
          },
          "butikker": {
            "type": "integer"
          },
          "sistOppdatert": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "Siste fullførte skraping"
          }
        },
        "required": [
          "status"
        ]
      },
      "Soketreff": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "brand": {
            "type": [
              "string",
              "null"
            ]
          },
          "lowest_price": {
            "type": [
              "number",
              "null"
            ],
            "description": "Laveste pris i NOK"
          },
          "offer_count": {
            "type": "integer",
            "description": "Antall butikker som fører varen"
          }
        }
      },
      "Produkt": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "slug": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "brand": {
            "type": [
              "string",
              "null"
            ]
          },
          "offers": {
            "type": "array",
            "description": "Rangert: nylig sjekkede priser på lager først, priser som avviker mye sist.",
            "items": {
              "type": "object",
              "properties": {
                "price": {
                  "type": "number"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                },
                "store_name": {
                  "type": "string"
                },
                "in_stock": {
                  "type": "boolean"
                },
                "checked_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time",
                  "description": "Sist sjekket hos butikken."
                },
                "current": {
                  "type": "boolean",
                  "description": "Ferskt, på lager og troverdig. Bare slike priser kan kalles laveste pris."
                },
                "note": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "description": "Forklaring når prisen avviker mye."
                },
                "shipping": {
                  "type": "string",
                  "description": "Kort frakttekst. Frakt er ikke med i prisen."
                }
              }
            }
          }
        }
      }
    }
  }
}