{
  "openapi": "3.0.3",
  "info": {
    "title": "Minuteform API",
    "version": "1.1.0",
    "description": "Form backend that stores website leads and pushes alerts to ntfy, Slack, Microsoft Teams, Discord, Google Chat, or HMAC-signed HTTPS webhooks. Base URL: https://minuteform.pages.dev. Authenticated routes use `Authorization: Bearer mf_...`. The API key is shown once; only a SHA-256 hash is stored.",
    "contact": {
      "email": "timwvedco+minuteform@gmail.com",
      "name": "Minuteform support"
    },
    "license": {
      "name": "MIT",
      "url": "https://github.com/vedetile-code/minuteform"
    },
    "x-logo": {
      "url": "https://minuteform.pages.dev/favicon.svg",
      "backgroundColor": "#0A0908"
    }
  },
  "servers": [
    {
      "url": "https://minuteform.pages.dev",
      "description": "Production"
    }
  ],
  "tags": [
    {
      "name": "Public",
      "description": "No authentication"
    },
    {
      "name": "Intake",
      "description": "Form endpoints that receive leads"
    },
    {
      "name": "Account",
      "description": "Signup, billing, export, deletion"
    },
    {
      "name": "Forms",
      "description": "Authenticated form management"
    },
    {
      "name": "Submissions",
      "description": "Read, export and delete leads"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "mf_",
        "description": "API key issued at signup, claim, or rotation."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "PlanLimits": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "forms": {
            "type": "integer"
          },
          "monthly": {
            "type": "integer"
          },
          "retentionMax": {
            "type": "integer"
          },
          "targets": {
            "type": "integer"
          }
        }
      },
      "Account": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "company": {
            "type": "string",
            "nullable": true
          },
          "plan": {
            "type": "string",
            "enum": [
              "free",
              "pro",
              "agency"
            ]
          },
          "status": {
            "type": "string"
          },
          "key_prefix": {
            "type": "string"
          },
          "limits": {
            "$ref": "#/components/schemas/PlanLimits"
          },
          "usage": {
            "type": "object",
            "properties": {
              "month": {
                "type": "string",
                "nullable": true
              },
              "count": {
                "type": "integer"
              }
            }
          },
          "created_at": {
            "type": "integer"
          },
          "billing": {
            "type": "boolean"
          }
        }
      },
      "Form": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "public_id": {
            "type": "string"
          },
          "endpoint": {
            "type": "string",
            "format": "uri"
          },
          "name": {
            "type": "string"
          },
          "redirect_url": {
            "type": "string",
            "nullable": true
          },
          "notify": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "ntfy_topic": {
            "type": "string",
            "nullable": true
          },
          "retention_days": {
            "type": "integer"
          },
          "allowed_origins": {
            "type": "string",
            "nullable": true
          },
          "reply_message": {
            "type": "string",
            "nullable": true
          },
          "enabled": {
            "type": "boolean"
          },
          "signing_secret": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          }
        }
      },
      "FormInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "redirect_url": {
            "type": "string"
          },
          "notify": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "ntfy_topic": {
            "type": "string"
          },
          "retention_days": {
            "type": "integer"
          },
          "allowed_origins": {
            "type": "string"
          },
          "reply_message": {
            "type": "string"
          },
          "enabled": {
            "type": "boolean"
          }
        }
      },
      "Submission": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "created_at": {
            "type": "integer"
          },
          "notified": {
            "type": "integer"
          },
          "data": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "Status": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "components": {
            "type": "object",
            "properties": {
              "api": {
                "type": "string"
              },
              "database": {
                "type": "string"
              },
              "payments": {
                "type": "string"
              }
            }
          },
          "db_ms": {
            "type": "integer"
          },
          "time": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "checks": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "note": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/healthz": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Liveness and component health",
        "operationId": "healthz",
        "responses": {
          "200": {
            "description": "Healthy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          },
          "503": {
            "description": "Database down"
          }
        },
        "security": []
      }
    },
    "/api/health": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Same as /healthz",
        "operationId": "apiHealth",
        "responses": {
          "200": {
            "description": "Healthy"
          },
          "503": {
            "description": "Database down"
          }
        },
        "security": []
      }
    },
    "/api/status": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Live health plus recent check snapshots",
        "description": "Returns the current component check and the last 60 snapshots written by this endpoint and by the daily operations job. No uptime percentage and no SLA.",
        "operationId": "apiStatus",
        "responses": {
          "200": {
            "description": "Status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Status"
                }
              }
            }
          },
          "503": {
            "description": "Database down"
          }
        },
        "security": []
      }
    },
    "/api/plans": {
      "get": {
        "tags": [
          "Public"
        ],
        "summary": "Plan limits and whether paid checkout is enabled",
        "operationId": "listPlans",
        "responses": {
          "200": {
            "description": "Plans"
          }
        },
        "security": []
      }
    },
    "/api/signup": {
      "post": {
        "tags": [
          "Account"
        ],
        "summary": "Create a free account",
        "description": "Returns an API key once. A non-empty `website` field is treated as a honeypot and returns `{ok:true}` without creating an account. Requires accept_terms: true.",
        "operationId": "signup",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email",
                  "accept_terms"
                ],
                "properties": {
                  "email": {
                    "type": "string"
                  },
                  "company": {
                    "type": "string"
                  },
                  "accept_terms": {
                    "type": "boolean"
                  },
                  "website": {
                    "type": "string",
                    "description": "Honeypot; leave empty."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Account created, api_key shown once"
          },
          "400": {
            "description": "Validation"
          },
          "422": {
            "description": "Invalid email"
          },
          "429": {
            "description": "Rate limited"
          }
        },
        "security": []
      }
    },
    "/api/checkout": {
      "post": {
        "tags": [
          "Account"
        ],
        "summary": "Start Stripe checkout for Pro or Agency",
        "operationId": "checkout",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "plan": {
                    "type": "string",
                    "enum": [
                      "pro",
                      "agency"
                    ]
                  },
                  "email": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout URL and claim token"
          },
          "400": {
            "description": "Bad plan"
          },
          "429": {
            "description": "Rate limited"
          }
        },
        "security": []
      }
    },
    "/api/claim": {
      "post": {
        "tags": [
          "Account"
        ],
        "summary": "Redeem a checkout claim for an API key",
        "operationId": "claim",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "claim"
                ],
                "properties": {
                  "claim": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "ready or upgraded"
          },
          "202": {
            "description": "Payment not yet fulfilled"
          },
          "409": {
            "description": "Already redeemed"
          },
          "404": {
            "description": "Unknown claim"
          }
        },
        "security": []
      }
    },
    "/api/enterprise": {
      "post": {
        "tags": [
          "Public"
        ],
        "summary": "Enterprise inquiry",
        "description": "Stores a contact request so the operator can reply by email. Not a 24/7 inbox and not an SLA. Honeypot field: website.",
        "operationId": "enterpriseInquiry",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "email",
                  "message"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string"
                  },
                  "company": {
                    "type": "string"
                  },
                  "message": {
                    "type": "string"
                  },
                  "website": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Stored"
          },
          "400": {
            "description": "Validation"
          },
          "422": {
            "description": "Invalid email"
          },
          "429": {
            "description": "Rate limited"
          }
        },
        "security": []
      }
    },
    "/api/stripe/webhook": {
      "post": {
        "tags": [
          "Account"
        ],
        "summary": "Stripe webhook (signature required)",
        "description": "Verifies Stripe-Signature (HMAC-SHA256, 5-minute tolerance) and fulfils checkout or plan changes idempotently. Not a customer API.",
        "operationId": "stripeWebhook",
        "responses": {
          "200": {
            "description": "Received"
          },
          "400": {
            "description": "Invalid signature"
          }
        },
        "security": []
      }
    },
    "/f/{public_id}": {
      "post": {
        "tags": [
          "Intake"
        ],
        "summary": "Submit a lead to a form",
        "description": "Accepts application/x-www-form-urlencoded, multipart/form-data (no files) or application/json. A non-empty `_gotcha` is accepted silently and not stored. Browsers are redirected (303); JSON clients receive `{ok:true,message}`. Rate limits: 10/minute per IP per form, 300/hour per form. 429 includes Retry-After.",
        "operationId": "intake",
        "parameters": [
          {
            "name": "public_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[a-f0-9]{16}$"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              },
              "example": {
                "name": "Jane",
                "phone": "555-0100",
                "message": "Leaking water heater"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "additionalProperties": {
                  "type": "string"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON OK"
          },
          "303": {
            "description": "Redirect to thank-you or custom URL"
          },
          "400": {
            "description": "Invalid input"
          },
          "402": {
            "description": "Monthly plan quota reached"
          },
          "403": {
            "description": "Origin not allowed"
          },
          "404": {
            "description": "Unknown or disabled form"
          },
          "413": {
            "description": "Too large"
          },
          "415": {
            "description": "Unsupported type"
          },
          "422": {
            "description": "Invalid email field"
          },
          "429": {
            "description": "Rate limited",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "security": []
      }
    },
    "/api/me": {
      "get": {
        "tags": [
          "Account"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Current account, plan, usage",
        "operationId": "me",
        "responses": {
          "200": {
            "description": "Account",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "account": {
                      "$ref": "#/components/schemas/Account"
                    },
                    "billing_portal": {
                      "type": "string",
                      "nullable": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/api/keys/rotate": {
      "post": {
        "tags": [
          "Account"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Rotate the API key (old key stops working immediately)",
        "operationId": "rotateKey",
        "responses": {
          "200": {
            "description": "New api_key shown once"
          }
        }
      }
    },
    "/api/audit": {
      "get": {
        "tags": [
          "Account"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Last 200 audit events",
        "operationId": "audit",
        "responses": {
          "200": {
            "description": "Events"
          }
        }
      }
    },
    "/api/export": {
      "get": {
        "tags": [
          "Account"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Full account export (JSON)",
        "description": "Returns account profile, forms, submissions and audit log. Does not include the raw API key.",
        "operationId": "exportAccount",
        "responses": {
          "200": {
            "description": "Export JSON"
          }
        }
      }
    },
    "/api/account": {
      "delete": {
        "tags": [
          "Account"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Delete the account and all stored data",
        "description": "Body must be {\"confirm\":\"DELETE\"}. Forms and submissions are removed from the live database immediately. Cancel any Stripe subscription in the billing portal to stop future charges.",
        "operationId": "deleteAccount",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "confirm"
                ],
                "properties": {
                  "confirm": {
                    "type": "string",
                    "enum": [
                      "DELETE"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "400": {
            "description": "Missing confirm"
          }
        }
      }
    },
    "/api/forms": {
      "get": {
        "tags": [
          "Forms"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "List forms",
        "operationId": "listForms",
        "responses": {
          "200": {
            "description": "Forms"
          }
        }
      },
      "post": {
        "tags": [
          "Forms"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Create a form",
        "operationId": "createForm",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FormInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "402": {
            "description": "Plan form cap reached"
          }
        }
      }
    },
    "/api/forms/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "pattern": "^frm_[a-f0-9]{16}$"
          }
        }
      ],
      "get": {
        "tags": [
          "Forms"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Get a form",
        "operationId": "getForm",
        "responses": {
          "200": {
            "description": "Form"
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "patch": {
        "tags": [
          "Forms"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Update a form",
        "operationId": "updateForm",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FormInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "400": {
            "description": "Validation"
          }
        }
      },
      "delete": {
        "tags": [
          "Forms"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Delete a form and its submissions",
        "operationId": "deleteForm",
        "responses": {
          "200": {
            "description": "Deleted"
          }
        }
      }
    },
    "/api/forms/{id}/test": {
      "post": {
        "tags": [
          "Forms"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Send a test alert to configured targets",
        "operationId": "testForm",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Delivery statuses"
          }
        }
      }
    },
    "/api/forms/{id}/submissions": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        },
        {
          "name": "limit",
          "in": "query",
          "schema": {
            "type": "integer"
          }
        },
        {
          "name": "before",
          "in": "query",
          "schema": {
            "type": "integer"
          },
          "description": "Unix timestamp cursor"
        }
      ],
      "get": {
        "tags": [
          "Submissions"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "List submissions (JSON)",
        "operationId": "listSubmissions",
        "responses": {
          "200": {
            "description": "Submissions"
          }
        }
      },
      "delete": {
        "tags": [
          "Submissions"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Purge all submissions for a form",
        "operationId": "purgeSubmissions",
        "responses": {
          "200": {
            "description": "Deleted"
          }
        }
      }
    },
    "/api/forms/{id}/submissions.csv": {
      "get": {
        "tags": [
          "Submissions"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Export submissions as CSV",
        "operationId": "exportSubmissionsCsv",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "CSV",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/api/forms/{id}/submissions.json": {
      "get": {
        "tags": [
          "Submissions"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Export submissions as JSON (up to 10,000)",
        "operationId": "exportSubmissionsJson",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "JSON"
          }
        }
      }
    },
    "/api/submissions/{id}": {
      "delete": {
        "tags": [
          "Submissions"
        ],
        "security": [
          {
            "ApiKey": []
          }
        ],
        "summary": "Delete one submission",
        "operationId": "deleteSubmission",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^sub_[a-f0-9]{20}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deleted"
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    }
  },
  "externalDocs": {
    "description": "Docs",
    "url": "https://minuteform.pages.dev/docs/"
  }
}