{
  "openapi": "3.1.0",
  "info": {
    "title": "SignSimple Agent API",
    "version": "1.0.0",
    "description": "Send documents for legally binding electronic signature via SignSimple (free, unlimited). Authenticate with an API key created at https://signsimple.app/profile, passed as 'X-Api-Key' or 'Authorization: Bearer ss_live_...'. An MCP server wrapping this API is hosted at https://signsimple.app/mcp. Docs: https://signsimple.app/developers",
    "contact": { "url": "https://signsimple.app/contact" }
  },
  "servers": [{ "url": "https://us-central1-signsimple-app.cloudfunctions.net" }],
  "components": {
    "securitySchemes": {
      "ApiKeyHeader": { "type": "apiKey", "in": "header", "name": "X-Api-Key" },
      "BearerKey": { "type": "http", "scheme": "bearer", "description": "The ss_live_... API key as a bearer token" }
    },
    "schemas": {
      "Recipient": {
        "type": "object",
        "required": ["name", "email"],
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string", "format": "email" }
        }
      },
      "Field": {
        "type": "object",
        "description": "Optional custom field placement. Geometry is percentages (0-100) of the page.",
        "properties": {
          "type": { "type": "string", "enum": ["signature", "initial", "stamp", "date", "name", "email", "company", "title", "checkbox"] },
          "page": { "type": "integer", "minimum": 1 },
          "x": { "type": "number" },
          "y": { "type": "number" },
          "width": { "type": "number" },
          "height": { "type": "number" },
          "recipientIndex": { "type": "integer", "description": "Index into the recipients array this field belongs to" }
        }
      }
    }
  },
  "security": [{ "ApiKeyHeader": [] }, { "BearerKey": [] }],
  "paths": {
    "/agentSend": {
      "post": {
        "operationId": "sendForSignature",
        "summary": "Send a PDF for electronic signature",
        "description": "Uploads the PDF, creates the envelope, and emails every recipient a secure signing link. If no fields are given, a signature + date row is placed per recipient on the last page.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["documentName", "recipients"],
                "properties": {
                  "documentUrl": { "type": "string", "description": "Publicly fetchable URL of the PDF (alternative to documentBase64)" },
                  "documentBase64": { "type": "string", "description": "Base64-encoded PDF (max 15 MB)" },
                  "documentName": { "type": "string" },
                  "recipients": { "type": "array", "minItems": 1, "maxItems": 10, "items": { "$ref": "#/components/schemas/Recipient" } },
                  "subject": { "type": "string" },
                  "message": { "type": "string" },
                  "fields": { "type": "array", "items": { "$ref": "#/components/schemas/Field" } },
                  "expiresInDays": { "type": "number", "minimum": 1, "maximum": 365 },
                  "remindersEnabled": { "type": "boolean", "default": true }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Document sent",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "envelopeId": { "type": "string" },
                    "pageCount": { "type": "integer" },
                    "recipients": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": { "type": "string" },
                          "email": { "type": "string" },
                          "url": { "type": "string", "description": "The recipient's signing link" }
                        }
                      }
                    },
                    "emailFailures": { "type": "array", "items": { "type": "string" } }
                  }
                }
              }
            }
          },
          "400": { "description": "Validation error (bad email, non-PDF, missing document)" },
          "401": { "description": "Missing or invalid API key" }
        }
      }
    },
    "/agentStatus": {
      "post": {
        "operationId": "getDocumentStatus",
        "summary": "Get the status of a sent document",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["envelopeId"],
                "properties": { "envelopeId": { "type": "string" } }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Envelope status with per-recipient progress and the signed PDF URL once complete"
          },
          "401": { "description": "Missing or invalid API key" },
          "404": { "description": "Envelope not found for this account" }
        }
      }
    },
    "/agentDocuments": {
      "post": {
        "operationId": "listDocuments",
        "summary": "List the 25 most recent documents sent from this account",
        "requestBody": { "required": false, "content": { "application/json": { "schema": { "type": "object" } } } },
        "responses": {
          "200": { "description": "Recent documents with status and signed-PDF URLs" },
          "401": { "description": "Missing or invalid API key" }
        }
      }
    }
  }
}
