{
 "openapi": "3.1.0",
 "info": {
  "title": "Perfekte Gaveideer – Butiks-API",
  "version": "1.1.0",
  "description": "Data-API til butikker i butikspanelet på perfektegaveideer.dk. Kræver Pro eller Premium og en API-nøgle fra Konto & team → Integrationer. Højst 120 kald i minuttet. Dokumentation: https://perfektegaveideer.dk/partner/api/",
  "contact": {
   "email": "info@perfektegaveideer.dk",
   "url": "https://perfektegaveideer.dk/partner/api/"
  }
 },
 "servers": [
  {
   "url": "https://perfektegaveideer.dk/api/partner"
  }
 ],
 "security": [
  {
   "bearer": []
  },
  {
   "noegle": []
  }
 ],
 "paths": {
  "/v1/statistik": {
   "get": {
    "operationId": "statistik",
    "summary": "Klik og visninger pr. dag",
    "parameters": [
     {
      "name": "dage",
      "in": "query",
      "description": "Antal dage bagud (1-365). Standard 30, for feed 90.",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 365
      }
     },
     {
      "name": "format",
      "in": "query",
      "description": "csv giver semikolonsepareret UTF-8 med BOM (åbner direkte i Excel).",
      "schema": {
       "type": "string",
       "enum": [
        "json",
        "csv"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Statistik"
        }
       },
       "text/csv": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "401": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "403": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "429": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     }
    }
   }
  },
  "/v1/produkter": {
   "get": {
    "operationId": "produkter",
    "summary": "Klik, visninger og klikrate pr. produkt",
    "parameters": [
     {
      "name": "dage",
      "in": "query",
      "description": "Antal dage bagud (1-365). Standard 30, for feed 90.",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 365
      }
     },
     {
      "name": "format",
      "in": "query",
      "description": "csv giver semikolonsepareret UTF-8 med BOM (åbner direkte i Excel).",
      "schema": {
       "type": "string",
       "enum": [
        "json",
        "csv"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Produkter"
        }
       },
       "text/csv": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "401": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "403": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "429": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     }
    }
   }
  },
  "/v1/feed": {
   "get": {
    "operationId": "feed",
    "summary": "Dagligt datafeed til Power BI, Excel og Google Sheets: én række pr. dag × vare × kilde × enhed",
    "parameters": [
     {
      "name": "dage",
      "in": "query",
      "description": "Antal dage bagud (1-365). Standard 30, for feed 90.",
      "schema": {
       "type": "integer",
       "minimum": 1,
       "maximum": 365
      }
     },
     {
      "name": "format",
      "in": "query",
      "description": "csv giver semikolonsepareret UTF-8 med BOM (åbner direkte i Excel).",
      "schema": {
       "type": "string",
       "enum": [
        "json",
        "csv"
       ]
      }
     }
    ],
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Feed"
        }
       },
       "text/csv": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "401": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "403": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "429": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     }
    }
   }
  },
  "/v1/roi": {
   "get": {
    "operationId": "roi",
    "summary": "Hvad I får for pengene de sidste 30 dage (omsætning via os, pris pr. klik m.m.)",
    "responses": {
     "200": {
      "description": "OK",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "additionalProperties": true
        }
       }
      }
     },
     "401": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "403": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     }
    }
   }
  },
  "/v1/rabatkoder": {
   "post": {
    "operationId": "nyRabatkode",
    "summary": "Send en rabatkode til godkendelse (vises på jeres butiksside, når redaktionen har godkendt den)",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "$ref": "#/components/schemas/NyRabatkode"
       }
      }
     }
    },
    "responses": {
     "201": {
      "description": "Modtaget",
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "ok": {
           "type": "boolean"
          },
          "status": {
           "type": "string",
           "example": "afventer"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "401": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "403": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     },
     "429": {
      "description": "Fejl",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Fejl"
        }
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "securitySchemes": {
   "bearer": {
    "type": "http",
    "scheme": "bearer",
    "description": "Authorization: Bearer pg_…"
   },
   "noegle": {
    "type": "apiKey",
    "in": "query",
    "name": "key",
    "description": "?key=pg_… (til Power BI, Excel og Google Sheets, der ikke kan sende headere)"
   }
  },
  "schemas": {
   "Fejl": {
    "type": "object",
    "properties": {
     "error": {
      "type": "string"
     }
    }
   },
   "Statistik": {
    "type": "object",
    "properties": {
     "butik": {
      "type": "string"
     },
     "dage": {
      "type": "integer"
     },
     "kpi": {
      "type": "object",
      "additionalProperties": true
     },
     "dagligt": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "dato": {
         "type": "string",
         "format": "date"
        },
        "klik": {
         "type": "integer"
        },
        "visninger": {
         "type": "integer"
        }
       }
      }
     }
    }
   },
   "Produkter": {
    "type": "object",
    "properties": {
     "produkter": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "navn": {
         "type": "string"
        },
        "pris": {
         "type": "number"
        },
        "klik": {
         "type": "integer"
        },
        "visninger": {
         "type": "integer"
        },
        "klikrate": {
         "type": [
          "number",
          "null"
         ]
        },
        "url": {
         "type": "string"
        }
       }
      }
     }
    }
   },
   "Feed": {
    "type": "object",
    "properties": {
     "felter": {
      "type": "array",
      "items": {
       "type": "string"
      },
      "example": [
       "dato",
       "type",
       "vare_id",
       "vare",
       "pris",
       "kilde",
       "enhed",
       "antal"
      ]
     },
     "raekker": {
      "type": "array",
      "items": {
       "type": "object",
       "properties": {
        "dato": {
         "type": "string",
         "format": "date"
        },
        "type": {
         "type": "string",
         "enum": [
          "klik",
          "visning"
         ]
        },
        "vare_id": {
         "type": "string"
        },
        "vare": {
         "type": "string"
        },
        "pris": {
         "type": [
          "number",
          "string"
         ]
        },
        "kilde": {
         "type": "string",
         "description": "Siden hos os, klikket kom fra, fx /gave-til/mor/"
        },
        "enhed": {
         "type": "string",
         "enum": [
          "mobil",
          "computer",
          "tablet",
          ""
         ]
        },
        "antal": {
         "type": "integer"
        }
       }
      }
     }
    }
   },
   "NyRabatkode": {
    "type": "object",
    "required": [
     "code",
     "title"
    ],
    "properties": {
     "code": {
      "type": "string",
      "minLength": 3,
      "maxLength": 30,
      "example": "JUL20"
     },
     "title": {
      "type": "string",
      "maxLength": 80,
      "example": "20 % på alle julegaver"
     },
     "terms": {
      "type": "string",
      "maxLength": 200,
      "example": "Gælder ikke gavekort"
     },
     "ends": {
      "type": "string",
      "format": "date",
      "example": "2026-12-24"
     },
     "eks": {
      "type": "boolean",
      "description": "Eksklusiv kode kun til Perfekte Gaveideer"
     }
    }
   }
  }
 }
}
