{
  "openapi": "3.0.0",
  "info": {
    "title": "Doxbox API",
    "version": "v1",
    "description": "Public REST API for Doxbox accounts — read documents & suppliers, fetch files, generate exports, and upload documents. Authenticate with a per-account API key: `Authorization: Bearer dbx_...`."
  },
  "servers": [
    {
      "url": "https://app.doxbox.io"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Per-account API key. Send as `Authorization: Bearer dbx_<prefix>_<secret>`."
      }
    }
  },
  "paths": {
    "/api/v1/documents/{id}/file": {
      "get": {
        "summary": "Redirect (302) to a short-lived signed URL for the document file",
        "tags": [
          "Public API v1"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "in": "query",
            "name": "image",
            "schema": {
              "type": "integer"
            },
            "description": "A specific image id belonging to the document (defaults to the first)."
          }
        ],
        "responses": {
          "302": {
            "description": "Redirect to a fresh, short-lived GCS signed URL."
          },
          "401": {
            "description": "Missing, invalid, expired, or revoked API key."
          },
          "404": {
            "description": "Document or file not found, or not in your account."
          }
        }
      }
    },
    "/api/v1/documents/{id}": {
      "get": {
        "summary": "Get a single document with metadata and image ids",
        "tags": [
          "Public API v1"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "path",
            "name": "id",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The document."
          },
          "401": {
            "description": "Missing, invalid, expired, or revoked API key."
          },
          "404": {
            "description": "Not found, or not in your account."
          }
        }
      }
    },
    "/api/v1/documents": {
      "get": {
        "summary": "List the account's documents (cursor-paginated)",
        "tags": [
          "Public API v1"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "in": "query",
            "name": "limit",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "in": "query",
            "name": "cursor",
            "schema": {
              "type": "integer"
            },
            "description": "The last document id from the previous page."
          }
        ],
        "responses": {
          "200": {
            "description": "A page of documents plus the next cursor."
          },
          "401": {
            "description": "Missing, invalid, expired, or revoked API key."
          },
          "429": {
            "description": "Rate limit exceeded."
          }
        }
      },
      "post": {
        "summary": "Upload one or more documents (requires a write-enabled key)",
        "tags": [
          "Public API v1"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "files": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Per-file results (created / duplicate / failed) plus a summary."
          },
          "400": {
            "description": "No files provided."
          },
          "401": {
            "description": "Missing, invalid, expired, or revoked API key."
          },
          "403": {
            "description": "Read-only key (missing 'write' scope), or plan quota reached (PLAN_LIMIT_EXCEEDED)."
          },
          "429": {
            "description": "Rate limit exceeded."
          }
        }
      }
    },
    "/api/v1/exports": {
      "post": {
        "summary": "Generate an export file (excel/csv/pdf/zip) for the account",
        "tags": [
          "Public API v1"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "exportType",
                  "filters"
                ],
                "properties": {
                  "exportType": {
                    "type": "string",
                    "enum": [
                      "excel_monthly",
                      "csv",
                      "pdf_merged",
                      "zip"
                    ]
                  },
                  "scope": {
                    "type": "string",
                    "enum": [
                      "all_results",
                      "selected"
                    ],
                    "default": "all_results"
                  },
                  "selectedDocumentIds": {
                    "type": "array",
                    "items": {
                      "type": "integer"
                    }
                  },
                  "filters": {
                    "type": "object",
                    "required": [
                      "year",
                      "month"
                    ],
                    "properties": {
                      "year": {
                        "type": "integer"
                      },
                      "month": {
                        "type": "integer",
                        "minimum": 1,
                        "maximum": 12
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Export created; `fileUrl` is a signed URL valid ~12h."
          },
          "400": {
            "description": "Invalid request (bad type, missing filters, or selected without ids)."
          },
          "401": {
            "description": "Missing, invalid, expired, or revoked API key."
          },
          "429": {
            "description": "Rate limit exceeded."
          }
        }
      }
    },
    "/api/v1/health": {
      "get": {
        "summary": "API health & version (no auth)",
        "tags": [
          "Public API v1"
        ],
        "responses": {
          "200": {
            "description": "Service is up"
          }
        }
      }
    },
    "/api/v1/suppliers": {
      "get": {
        "summary": "List the account's suppliers with per-supplier aggregates",
        "tags": [
          "Public API v1"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Suppliers with documentCount and totalAmount, sorted by total."
          },
          "401": {
            "description": "Missing, invalid, expired, or revoked API key."
          },
          "429": {
            "description": "Rate limit exceeded."
          }
        }
      }
    }
  },
  "tags": []
}
