{
  "openapi": "3.1.0",
  "info": {
    "title": "Formgrid.dev Public Submission & Management API",
    "version": "1.0.0",
    "description": "Supported public form submission endpoints (/api/f/{endpointSlug}) and authenticated Management API (/api/v1/*) for Formgrid.dev. Internal dashboard, admin, and billing routes are intentionally omitted.",
    "contact": {
      "name": "Formgrid Support",
      "email": "allen@formgrid.dev",
      "url": "https://formgrid.dev/docs"
    },
    "license": {
      "name": "MIT (Open-source core)",
      "url": "https://github.com/allenarduino/formgrid"
    }
  },
  "servers": [
    {
      "url": "https://formgrid.dev",
      "description": "Production Formgrid.dev API"
    }
  ],
  "tags": [
    {
      "name": "Public Form Submissions",
      "description": "Unauthenticated public endpoints for HTML forms, JavaScript fetch, React, Next.js, and static sites. Protected by Allowed Domains CORS, honeypot, per-form IP rate limits, and optional Turnstile/hCaptcha."
    },
    {
      "name": "Management API (v1)",
      "description": "Authenticated REST API using Bearer fg_live_... keys. Read access on Premium (100 req/min); read, write, and bulk access on Business (1000 req/min)."
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "fg_live_...",
        "description": "Server-side API key created in the Formgrid dashboard. Requires Premium (read-only) or Business (read/write). Never embed in client-side browser code."
      }
    },
    "schemas": {
      "PublicSubmissionJsonRequest": {
        "type": "object",
        "required": [
          "formData"
        ],
        "properties": {
          "formData": {
            "type": "object",
            "additionalProperties": true,
            "description": "At least one non-empty form field key/value pair.",
            "example": {
              "name": "Jordan Lee",
              "email": "alex@example.com",
              "message": "Interested in a project quote"
            }
          },
          "honeypot": {
            "type": "string",
            "description": "Optional spam trap. Must stay empty on genuine submissions.",
            "example": ""
          },
          "cf-turnstile-response": {
            "type": "string",
            "description": "Cloudflare Turnstile verification token when CAPTCHA is enabled."
          },
          "h-captcha-response": {
            "type": "string",
            "description": "hCaptcha verification token when hCaptcha is enabled."
          }
        }
      },
      "PublicSubmissionSuccess": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "example": true
          },
          "message": {
            "type": "string",
            "example": "Form submitted successfully"
          },
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "example": "sub_example_123"
              },
              "status": {
                "type": "string",
                "example": "new"
              },
              "submittedAt": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "ApiFormSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "endpointSlug": {
            "type": "string"
          },
          "isActive": {
            "type": "boolean"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "submissionCount": {
            "type": "integer"
          }
        }
      },
      "ApiStage": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "color": {
            "type": "string"
          },
          "order": {
            "type": "integer"
          },
          "submissionCount": {
            "type": "integer"
          }
        }
      },
      "ApiSubmission": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "formId": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          },
          "stage": {
            "type": "string"
          },
          "stageId": {
            "type": "string"
          },
          "stageIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "stages": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "payload": {
            "type": "object",
            "additionalProperties": true
          },
          "notes": {
            "type": [
              "string",
              "null"
            ]
          },
          "followUpDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "isSpam": {
            "type": "boolean"
          },
          "ai": {
            "type": "object",
            "properties": {
              "category": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "priority": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "summary": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "source": {
            "type": [
              "string",
              "null"
            ]
          },
          "utm": {
            "type": "object",
            "properties": {
              "source": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "medium": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "campaign": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        }
      },
      "CreateSubmissionItem": {
        "type": "object",
        "required": [
          "payload"
        ],
        "additionalProperties": false,
        "properties": {
          "payload": {
            "type": "object",
            "additionalProperties": true,
            "description": "Non-empty JSON object of up to 200 form field keys."
          },
          "stage": {
            "type": "string",
            "description": "Optional pipeline stage label."
          },
          "notes": {
            "type": "string",
            "maxLength": 5000
          },
          "followUpDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "source": {
            "type": "string",
            "maxLength": 100
          },
          "utm": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "source": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              },
              "medium": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              },
              "campaign": {
                "type": [
                  "string",
                  "null"
                ],
                "maxLength": 200
              }
            }
          }
        }
      },
      "PatchSubmissionRequest": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "stage": {
            "type": "string"
          },
          "note": {
            "type": "string",
            "maxLength": 1000
          },
          "followUpDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "ApiError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "upgradeUrl": {
            "type": "string"
          },
          "docs": {
            "type": "string"
          }
        }
      }
    }
  },
  "paths": {
    "/api/f/{endpointSlug}": {
      "post": {
        "tags": [
          "Public Form Submissions"
        ],
        "summary": "Submit to a public form endpoint (primary)",
        "description": "Accepts multipart/form-data, application/x-www-form-urlencoded, or application/json ({ formData }). Also exposed at aliases /f/{endpointSlug} and /forms/{endpointSlug}/submit. Send Accept: application/json for JSON responses instead of HTML 302 redirects.",
        "parameters": [
          {
            "name": "endpointSlug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Public form endpoint slug created in Formgrid."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "additionalProperties": true
              }
            },
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublicSubmissionJsonRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Silent drop when honeypot, rate limit, or invalid CAPTCHA triggers"
          },
          "201": {
            "description": "Submission accepted (JSON mode)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicSubmissionSuccess"
                }
              }
            }
          },
          "302": {
            "description": "Redirect to redirectUrl or confirmation page (HTML form mode)"
          },
          "400": {
            "description": "Validation error or disallowed file upload"
          },
          "403": {
            "description": "Form inactive or origin disallowed by Allowed Domains CORS"
          },
          "404": {
            "description": "Form endpointSlug not found"
          }
        }
      }
    },
    "/f/{endpointSlug}": {
      "post": {
        "tags": [
          "Public Form Submissions"
        ],
        "summary": "Short alias for /api/f/{endpointSlug}",
        "parameters": [
          {
            "name": "endpointSlug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Submission accepted (JSON mode)"
          },
          "302": {
            "description": "Confirmation redirect (HTML mode)"
          }
        }
      }
    },
    "/forms/{endpointSlug}/submit": {
      "post": {
        "tags": [
          "Public Form Submissions"
        ],
        "summary": "REST-style alias for /api/f/{endpointSlug}",
        "parameters": [
          {
            "name": "endpointSlug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Submission accepted (JSON mode)"
          },
          "302": {
            "description": "Confirmation redirect (HTML mode)"
          }
        }
      }
    },
    "/api/v1/forms": {
      "get": {
        "tags": [
          "Management API (v1)"
        ],
        "summary": "List forms for the authenticated account (Premium+)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of forms",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiFormSummary"
                      }
                    },
                    "total": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid fg_live_... API key"
          },
          "403": {
            "description": "Free plan (PLAN_REQUIRED)"
          },
          "429": {
            "description": "Per-key API rate limit exceeded"
          }
        }
      }
    },
    "/api/v1/forms/{formId}/stages": {
      "get": {
        "tags": [
          "Management API (v1)"
        ],
        "summary": "List CRM pipeline stages for a form (Premium+)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "formId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Form pipeline stages with counts",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "stages": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiStage"
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Form not found"
          }
        }
      }
    },
    "/api/v1/forms/{formId}/submissions": {
      "get": {
        "tags": [
          "Management API (v1)"
        ],
        "summary": "List submissions for a form (Premium+)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "formId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "stage",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "search",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            }
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "createdAt",
                "updatedAt"
              ],
              "default": "createdAt"
            }
          },
          {
            "name": "order",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "asc",
                "desc"
              ],
              "default": "desc"
            }
          },
          {
            "name": "page",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "default": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated submissions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ApiSubmission"
                      }
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "page": {
                          "type": "integer"
                        },
                        "limit": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        },
                        "totalPages": {
                          "type": "integer"
                        },
                        "hasNext": {
                          "type": "boolean"
                        },
                        "hasPrev": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error or INVALID_STAGE"
          },
          "404": {
            "description": "Form not found"
          }
        }
      },
      "post": {
        "tags": [
          "Management API (v1)"
        ],
        "summary": "Create single or bulk (up to 1,000) submissions (Business only)",
        "description": "Counts toward monthly submission allowance; does not automatically trigger owner email, Sheets, or webhook side effects.",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "formId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/CreateSubmissionItem"
                  },
                  {
                    "type": "object",
                    "required": [
                      "items"
                    ],
                    "additionalProperties": false,
                    "properties": {
                      "items": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 1000,
                        "items": {
                          "$ref": "#/components/schemas/CreateSubmissionItem"
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Submission(s) created"
          },
          "400": {
            "description": "VALIDATION_ERROR or INVALID_STAGE"
          },
          "403": {
            "description": "Requires Business plan (BUSINESS_REQUIRED)"
          },
          "429": {
            "description": "SUBMISSION_LIMIT_REACHED or RATE_LIMIT_EXCEEDED"
          }
        }
      }
    },
    "/api/v1/forms/{formId}/submissions/{submissionId}": {
      "get": {
        "tags": [
          "Management API (v1)"
        ],
        "summary": "Get a single submission (Premium+)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "formId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "submissionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Submission detail",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ApiSubmission"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Form or submission not found"
          }
        }
      },
      "patch": {
        "tags": [
          "Management API (v1)"
        ],
        "summary": "Update submission stage, note, or follow-up date (Business only)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "formId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "submissionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PatchSubmissionRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated submission",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/ApiSubmission"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "VALIDATION_ERROR or INVALID_STAGE"
          },
          "403": {
            "description": "Requires Business plan (BUSINESS_REQUIRED)"
          },
          "404": {
            "description": "Form or submission not found"
          }
        }
      },
      "delete": {
        "tags": [
          "Management API (v1)"
        ],
        "summary": "Soft-delete a submission (Business only)",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "formId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "submissionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Submission deleted"
          },
          "403": {
            "description": "Requires Business plan (BUSINESS_REQUIRED)"
          },
          "404": {
            "description": "Form or submission not found"
          }
        }
      }
    }
  },
  "x-formgrid-plans-summary": {
    "free": {
      "priceUsd": 0,
      "submissionsPerMonth": 50
    },
    "premium": {
      "monthlyUsd": 12,
      "annualEffectiveMonthlyUsd": 10,
      "submissionsPerMonth": 1000,
      "apiAccess": "read-only",
      "apiRateLimitPerMin": 100
    },
    "business": {
      "monthlyUsd": 29,
      "annualEffectiveMonthlyUsd": 24.17,
      "submissionsPerMonth": 15000,
      "apiAccess": "read-write-bulk",
      "apiRateLimitPerMin": 1000
    }
  }
}