{
  "openapi": "3.0.3",
  "info": {
    "title": "MagicInvoice API",
    "version": "1.0.0",
    "description": "Max PDF 10 MiB. create requires PDF/A-1 or PDF/A-3. check is a partial text comparison, not visual assurance."
  },
  "servers": [
    {
      "url": "https://magicinvoice.se"
    }
  ],
  "paths": {
    "/api/magic-invoice/v1/create": {
      "post": {
        "operationId": "create",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "pdf",
                  "invoice"
                ],
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary"
                  },
                  "invoice": {
                    "$ref": "#/components/schemas/Invoice"
                  }
                }
              },
              "encoding": {
                "invoice": {
                  "contentType": "application/json"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Inspect status in JSON responses. VERIFIED is the only trusted result.",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "API key missing or unknown"
          },
          "404": {
            "description": "Embedded invoice missing"
          },
          "413": {
            "description": "File too large"
          },
          "422": {
            "description": "Invalid invoice or signature"
          },
          "429": {
            "description": "Client limit exceeded; honor Retry-After"
          },
          "503": {
            "description": "Capacity exceeded or signing unavailable; honor Retry-After when supplied"
          }
        }
      }
    },
    "/api/magic-invoice/v1/extract": {
      "post": {
        "operationId": "extract",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "pdf"
                ],
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              },
              "encoding": {}
            }
          }
        },
        "responses": {
          "200": {
            "description": "Inspect status in JSON responses. VERIFIED is the only trusted result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExtractedInvoice"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "API key missing or unknown"
          },
          "404": {
            "description": "Embedded invoice missing"
          },
          "413": {
            "description": "File too large"
          },
          "422": {
            "description": "Invalid invoice or signature"
          },
          "429": {
            "description": "Client limit exceeded; honor Retry-After"
          },
          "503": {
            "description": "Capacity exceeded or signing unavailable; honor Retry-After when supplied"
          }
        }
      }
    },
    "/api/magic-invoice/v1/verify": {
      "post": {
        "operationId": "verify",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "pdf"
                ],
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary"
                  }
                }
              },
              "encoding": {}
            }
          }
        },
        "responses": {
          "200": {
            "description": "Inspect status in JSON responses. VERIFIED is the only trusted result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Verification"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "API key missing or unknown"
          },
          "404": {
            "description": "Embedded invoice missing"
          },
          "413": {
            "description": "File too large"
          },
          "422": {
            "description": "Invalid invoice or signature"
          },
          "429": {
            "description": "Client limit exceeded; honor Retry-After"
          },
          "503": {
            "description": "Capacity exceeded or signing unavailable; honor Retry-After when supplied"
          }
        }
      }
    },
    "/api/magic-invoice/v1/check": {
      "post": {
        "operationId": "check",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "pdf",
                  "invoice"
                ],
                "properties": {
                  "pdf": {
                    "type": "string",
                    "format": "binary"
                  },
                  "invoice": {
                    "$ref": "#/components/schemas/Invoice"
                  }
                }
              },
              "encoding": {
                "invoice": {
                  "contentType": "application/json"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Inspect status in JSON responses. VERIFIED is the only trusted result.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "PARTIAL_MATCH",
                        "REVIEW_REQUIRED"
                      ]
                    },
                    "findings": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid input"
          },
          "401": {
            "description": "API key missing or unknown"
          },
          "404": {
            "description": "Embedded invoice missing"
          },
          "413": {
            "description": "File too large"
          },
          "422": {
            "description": "Invalid invoice or signature"
          },
          "429": {
            "description": "Client limit exceeded; honor Retry-After"
          },
          "503": {
            "description": "Capacity exceeded or signing unavailable; honor Retry-After when supplied"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    },
    "schemas": {
      "Invoice": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "number",
          "issueDate",
          "dueDate",
          "currency",
          "seller",
          "buyer",
          "lines"
        ],
        "properties": {
          "number": {
            "type": "string"
          },
          "issueDate": {
            "type": "string",
            "format": "date"
          },
          "dueDate": {
            "type": "string",
            "format": "date"
          },
          "currency": {
            "type": "string",
            "pattern": "^[A-Z]{3}$"
          },
          "seller": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "name",
              "street",
              "postalCode",
              "city",
              "country"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "street": {
                "type": "string"
              },
              "postalCode": {
                "type": "string"
              },
              "city": {
                "type": "string"
              },
              "country": {
                "type": "string"
              },
              "vatNumber": {
                "type": "string"
              }
            }
          },
          "buyer": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "name",
              "street",
              "postalCode",
              "city",
              "country"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "street": {
                "type": "string"
              },
              "postalCode": {
                "type": "string"
              },
              "city": {
                "type": "string"
              },
              "country": {
                "type": "string"
              },
              "vatNumber": {
                "type": "string"
              }
            }
          },
          "paymentReference": {
            "type": "string"
          },
          "payment": {
            "type": "object",
            "properties": {
              "account": {
                "type": "string"
              },
              "bic": {
                "type": "string"
              }
            },
            "required": [
              "account"
            ]
          },
          "lines": {
            "type": "array",
            "minItems": 1,
            "maxItems": 1000,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "description",
                "unit",
                "quantity",
                "unitPrice",
                "vatRate"
              ],
              "properties": {
                "description": {
                  "type": "string"
                },
                "unit": {
                  "type": "string"
                },
                "quantity": {
                  "type": "number",
                  "exclusiveMinimum": 0
                },
                "unitPrice": {
                  "type": "number",
                  "minimum": 0
                },
                "vatRate": {
                  "type": "number",
                  "minimum": 0
                }
              }
            }
          }
        }
      },
      "Verification": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "VERIFIED",
              "UNSIGNED",
              "UNKNOWN_SIGNER",
              "INVALID"
            ]
          },
          "certificateSha256": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "ExtractedInvoice": {
        "type": "object",
        "properties": {
          "invoice": {
            "$ref": "#/components/schemas/Invoice"
          },
          "documentType": {
            "type": "string"
          },
          "netTotal": {
            "type": "number"
          },
          "vatTotal": {
            "type": "number"
          },
          "grossTotal": {
            "type": "number"
          },
          "amountDue": {
            "type": "number"
          },
          "sourceXml": {
            "type": "string"
          },
          "verification": {
            "$ref": "#/components/schemas/Verification"
          }
        }
      }
    }
  }
}
