{
  "openapi": "3.0.3",
  "info": {
    "title": "Syncto API for salgssporing",
    "version": "1.0.0",
    "description": "Synctos API for å hente rabattkoder, kontrollere butikkens API-nøkkel og rapportere salg fra en tilkoblet butikk. See the API Deprecation Policy at https://www.syncto.no/docs/deprecation for notices, sunset dates, and migration guidance."
  },
  "externalDocs": {
    "description": "Syncto API-dokumentasjon",
    "url": "https://www.syncto.no/docs"
  },
  "servers": [
    {
      "url": "https://api.syncto.no",
      "description": "Syncto produksjon"
    }
  ],
  "security": [
    {
      "CompanyApiKey": []
    }
  ],
  "paths": {
    "/api/v1/integrations/discount-codes": {
      "get": {
        "operationId": "listActiveDiscountCodes",
        "summary": "Hent aktive rabattkoder",
        "description": "Returnerer de aktive Syncto-rabattkodene for selskapet som eier API-nøkkelen.",
        "responses": {
          "200": {
            "description": "Aktive rabattkoder",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "API-nøkkel mangler eller er ugyldig",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "default": {
            "description": "Forespørselen feilet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/integrations/test": {
      "post": {
        "operationId": "testSalesIntegration",
        "summary": "Kontroller butikkens API-nøkkel",
        "description": "Bekrefter tilgang og returnerer informasjon om salgshendelsen API-et forventer.",
        "responses": {
          "200": {
            "description": "Integrasjonen svarte",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "ok": {
                          "type": "boolean"
                        },
                        "company_id": {
                          "type": "string"
                        },
                        "active_codes_count": {
                          "type": "integer",
                          "minimum": 0
                        },
                        "expected_sales_event_shape": {
                          "type": "object",
                          "additionalProperties": true
                        },
                        "notes": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "API-nøkkel mangler eller er ugyldig",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "default": {
            "description": "Forespørselen feilet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/integrations/sales": {
      "post": {
        "operationId": "recordSale",
        "summary": "Registrer et salg",
        "description": "Rapporter et salg med rabattkoden kunden brukte. Bruk samme external_id ved gjentatte leveringsforsøk.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Sale"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Salgshendelsen ble behandlet",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "success",
                    "data"
                  ],
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "enum": [
                        true
                      ]
                    },
                    "data": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "API-nøkkel mangler eller er ugyldig",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          },
          "default": {
            "description": "Forespørselen feilet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiError"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "CompanyApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "Selskapets butikk-API-nøkkel opprettet i Syncto."
      }
    },
    "schemas": {
      "ApiError": {
        "type": "object",
        "required": [
          "success",
          "error"
        ],
        "properties": {
          "success": {
            "type": "boolean",
            "enum": [
              false
            ]
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "Sale": {
        "type": "object",
        "required": [
          "sale_amount_nok"
        ],
        "properties": {
          "discount_code": {
            "type": "string",
            "description": "Rabattkoden kunden brukte."
          },
          "sale_amount_nok": {
            "type": "number",
            "description": "Brutto salgsbeløp i kroner inklusiv merverdiavgift, før rabatt."
          },
          "quantity": {
            "type": "number",
            "default": 1
          },
          "external_id": {
            "type": "string",
            "description": "Butikkens ordre-ID brukt ved gjentatte leveringsforsøk."
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "views": {
            "type": "number",
            "minimum": 0
          },
          "likes": {
            "type": "number",
            "minimum": 0
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true
          }
        }
      }
    }
  }
}
