{
  "openapi": "3.1.0",
  "info": {
    "title": "SendPage API",
    "version": "1.0.0",
    "description": "Publish HTML as a hosted, shareable link that opens in one tap and previews as a card in chat apps — and export it to PNG, PDF or Word. Authenticate with a Bearer API key (sp_live_...). Free tier: 3 documents/month; Pro removes the limit and unlocks Word export.",
    "contact": { "name": "SendPage", "url": "https://sendpageapp.com/docs/api" }
  },
  "servers": [{ "url": "https://sendpageapp.com/api/v1" }],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/documents": {
      "post": {
        "summary": "Publish a document",
        "operationId": "createDocument",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreateDocument" }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Document" } } }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "413": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" },
          "429": { "$ref": "#/components/responses/Error" }
        }
      },
      "get": {
        "summary": "List your documents",
        "operationId": "listDocuments",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "documents": { "type": "array", "items": { "$ref": "#/components/schemas/DocumentSummary" } }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/documents/{id}": {
      "parameters": [{ "$ref": "#/components/parameters/Id" }],
      "get": {
        "summary": "Get a document",
        "operationId": "getDocument",
        "parameters": [
          { "name": "include", "in": "query", "schema": { "type": "string", "enum": ["html"] }, "description": "Set to `html` to include the source." }
        ],
        "responses": {
          "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/DocumentSummary" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      },
      "patch": {
        "summary": "Update a document (the link is unchanged)",
        "operationId": "updateDocument",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "html": { "type": "string" },
                  "title": { "type": "string" },
                  "edit_token": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Updated", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Document" } } } },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "413": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/documents/{id}/export": {
      "parameters": [{ "$ref": "#/components/parameters/Id" }],
      "post": {
        "summary": "Export a document to an image, PDF or Word file",
        "operationId": "exportDocument",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["format"],
                "properties": {
                  "format": { "type": "string", "enum": ["png", "pdf", "docx"] },
                  "edit_token": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A URL to fetch the file",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": { "type": "string" },
                    "format": { "type": "string" },
                    "url": { "type": "string", "format": "uri" },
                    "pro": { "type": "boolean" }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "402": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" },
          "422": { "$ref": "#/components/responses/Error" }
        }
      }
    },
    "/documents/{id}/comments": {
      "parameters": [{ "$ref": "#/components/parameters/Id" }],
      "get": {
        "summary": "List reader comments on a document",
        "operationId": "listComments",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "comments": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "string" },
                          "author": { "type": ["string", "null"] },
                          "body": { "type": "string" },
                          "created_at": { "type": "string" }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Error" },
          "404": { "$ref": "#/components/responses/Error" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": { "type": "http", "scheme": "bearer", "description": "Your API key, e.g. sp_live_..." }
    },
    "parameters": {
      "Id": { "name": "id", "in": "path", "required": true, "schema": { "type": "string" }, "description": "The document id." }
    },
    "schemas": {
      "CreateDocument": {
        "type": "object",
        "required": ["html"],
        "properties": {
          "html": { "type": "string", "description": "The full HTML document (up to 2 MB)." },
          "title": { "type": "string", "description": "Optional; auto-detected from the HTML if omitted." },
          "sender_name": { "type": "string", "description": "Optional; shown on the shared page and card." }
        }
      },
      "Document": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "edit_token": { "type": "string", "description": "Keep this secret; it authorizes updates." },
          "is_pro": { "type": "boolean" }
        }
      },
      "DocumentSummary": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "title": { "type": "string" },
          "is_pro": { "type": "boolean" },
          "view_count": { "type": "integer" },
          "created_at": { "type": "string" }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" }
            }
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    }
  }
}
