{
  "openapi": "3.0.3",
  "info": {
    "title": "StatusFleet API",
    "version": "1.0.0",
    "description": "Account API for status pages, components, and incidents. Authenticate with an API key created on the dashboard. The key is sent as Authorization: Bearer sf_live_<prefix>_<secret>. The Supabase gateway also requires the project publishable key in the apikey header. Every response is limited to the key owner's account. Resources belonging to another account are 404."
  },
  "servers": [
    {
      "url": "https://wfhcckdxmrnhccakafyh.supabase.co/functions/v1/api"
    }
  ],
  "security": [
    {
      "bearerAuth": [],
      "publishableKey": []
    }
  ],
  "tags": [
    { "name": "Pages" },
    { "name": "Components" },
    { "name": "Monitors" },
    { "name": "Incidents" }
  ],
  "paths": {
    "/v1/pages": {
      "get": {
        "tags": ["Pages"],
        "operationId": "listPages",
        "summary": "List the account's status pages",
        "responses": {
          "200": {
            "description": "Pages owned by the key's account",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Page" } }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/pages/{page_id}": {
      "get": {
        "tags": ["Pages"],
        "operationId": "getPage",
        "summary": "Read one status page",
        "parameters": [{ "$ref": "#/components/parameters/PageId" }],
        "responses": {
          "200": {
            "description": "The page",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Page" } } }
          },
          "400": { "$ref": "#/components/responses/Invalid" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/pages/{page_id}/components": {
      "get": {
        "tags": ["Components"],
        "operationId": "listComponents",
        "summary": "List components on a page",
        "parameters": [{ "$ref": "#/components/parameters/PageId" }],
        "responses": {
          "200": {
            "description": "Components",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Component" } }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Invalid" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/pages/{page_id}/monitors": {
      "get": {
        "tags": ["Monitors"],
        "operationId": "listMonitors",
        "summary": "List monitors on a page, with 24h and 30d uptime",
        "parameters": [{ "$ref": "#/components/parameters/PageId" }],
        "responses": {
          "200": {
            "description": "Monitors",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Monitor" } }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Invalid" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/pages/{page_id}/incidents": {
      "get": {
        "tags": ["Incidents"],
        "operationId": "listIncidents",
        "summary": "List incidents on a page",
        "parameters": [{ "$ref": "#/components/parameters/PageId" }],
        "responses": {
          "200": {
            "description": "Incidents, newest first, with updates and component ids",
            "content": {
              "application/json": {
                "schema": { "type": "array", "items": { "$ref": "#/components/schemas/Incident" } }
              }
            }
          },
          "400": { "$ref": "#/components/responses/Invalid" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      },
      "post": {
        "tags": ["Incidents"],
        "operationId": "createIncident",
        "summary": "Open an incident",
        "description": "Creates the incident as investigating, with the first update and optional component links. Webhooks, Slack, and subscriber email are queued the same way as from the dashboard.",
        "parameters": [{ "$ref": "#/components/parameters/PageId" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/CreateIncident" } }
          }
        },
        "responses": {
          "200": {
            "description": "The created incident",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Incident" } } }
          },
          "400": { "$ref": "#/components/responses/Invalid" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/components/{component_id}": {
      "patch": {
        "tags": ["Components"],
        "operationId": "patchComponent",
        "summary": "Set a component status",
        "description": "Same direct status edit as the dashboard. Queues component.status_changed when the status changes and the page has an integration.",
        "parameters": [{ "$ref": "#/components/parameters/ComponentId" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/PatchComponent" } }
          }
        },
        "responses": {
          "200": {
            "description": "The updated component",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Component" } } }
          },
          "400": { "$ref": "#/components/responses/Invalid" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/incidents/{incident_id}/updates": {
      "post": {
        "tags": ["Incidents"],
        "operationId": "postIncidentUpdate",
        "summary": "Post an incident update",
        "description": "Posts one update to this incident. Resolving restores linked components when no other open incident still affects them, and queues the same webhook and email events as the dashboard.",
        "parameters": [{ "$ref": "#/components/parameters/IncidentId" }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/PostUpdate" } }
          }
        },
        "responses": {
          "200": {
            "description": "The update and the incident's linked component statuses",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PostedUpdate" } } }
          },
          "400": { "$ref": "#/components/responses/Invalid" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/v1/incident-groups": {
      "post": {
        "tags": ["Incidents"],
        "operationId": "createIncidentGroup",
        "summary": "Post one incident across pages",
        "description": "Creates one investigating incident per page, sharing an incident_group_id. Each component is linked only on the page it belongs to. One failure rolls the whole group back.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": { "schema": { "$ref": "#/components/schemas/CreateIncidentGroup" } }
          }
        },
        "responses": {
          "200": {
            "description": "The group and its incidents",
            "content": { "application/json": { "schema": { "$ref": "#/components/schemas/IncidentGroup" } } }
          },
          "400": { "$ref": "#/components/responses/Invalid" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "StatusFleet API key: sf_live_<prefix>_<secret>"
      },
      "publishableKey": {
        "type": "apiKey",
        "in": "header",
        "name": "apikey",
        "description": "Supabase project publishable key required by the gateway. It does not select an account."
      }
    },
    "parameters": {
      "PageId": {
        "name": "page_id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "format": "uuid" }
      },
      "ComponentId": {
        "name": "component_id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "format": "uuid" }
      },
      "IncidentId": {
        "name": "incident_id",
        "in": "path",
        "required": true,
        "schema": { "type": "string", "format": "uuid" }
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Missing, invalid, or revoked API key",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "Invalid": {
        "description": "The request body or id is not valid",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "NotFound": {
        "description": "The resource does not exist on this account",
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      },
      "RateLimited": {
        "description": "More than 60 requests in the current minute for this key",
        "headers": {
          "Retry-After": {
            "schema": { "type": "integer", "minimum": 1 },
            "description": "Seconds until the window resets"
          }
        },
        "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string",
                "enum": ["unauthorized", "invalid", "not_found", "rate_limited"]
              },
              "message": { "type": "string" }
            }
          }
        }
      },
      "Page": {
        "type": "object",
        "required": ["id", "name", "slug", "is_published", "created_at", "updated_at"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "slug": { "type": "string" },
          "custom_domain": { "type": "string", "nullable": true },
          "is_published": { "type": "boolean" },
          "created_at": { "type": "string", "format": "date-time" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "Component": {
        "type": "object",
        "required": ["id", "page_id", "name", "status", "position"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "page_id": { "type": "string", "format": "uuid" },
          "name": { "type": "string" },
          "description": { "type": "string", "nullable": true },
          "status": { "$ref": "#/components/schemas/ComponentStatus" },
          "position": { "type": "integer" },
          "updated_at": { "type": "string", "format": "date-time" }
        }
      },
      "ComponentStatus": {
        "type": "string",
        "enum": ["operational", "degraded", "partial_outage", "major_outage", "maintenance"]
      },
      "IncidentStatus": {
        "type": "string",
        "enum": ["investigating", "identified", "monitoring", "resolved"]
      },
      "IncidentImpact": {
        "type": "string",
        "enum": ["none", "minor", "major", "critical"]
      },
      "IncidentUpdate": {
        "type": "object",
        "required": ["id", "status", "body", "created_at"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "status": { "$ref": "#/components/schemas/IncidentStatus" },
          "body": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "Incident": {
        "type": "object",
        "required": ["id", "page_id", "title", "status", "impact", "component_ids", "updates"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "page_id": { "type": "string", "format": "uuid" },
          "title": { "type": "string" },
          "status": { "$ref": "#/components/schemas/IncidentStatus" },
          "impact": { "$ref": "#/components/schemas/IncidentImpact" },
          "started_at": { "type": "string", "format": "date-time" },
          "resolved_at": { "type": "string", "format": "date-time", "nullable": true },
          "created_at": { "type": "string", "format": "date-time" },
          "incident_group_id": { "type": "string", "format": "uuid", "nullable": true },
          "component_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } },
          "updates": { "type": "array", "items": { "$ref": "#/components/schemas/IncidentUpdate" } }
        }
      },
      "CreateIncident": {
        "type": "object",
        "required": ["title", "impact", "body"],
        "properties": {
          "title": { "type": "string", "maxLength": 300 },
          "impact": { "$ref": "#/components/schemas/IncidentImpact" },
          "body": { "type": "string", "maxLength": 8000 },
          "component_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } }
        }
      },
      "PatchComponent": {
        "type": "object",
        "required": ["status"],
        "properties": { "status": { "$ref": "#/components/schemas/ComponentStatus" } }
      },
      "PostUpdate": {
        "type": "object",
        "required": ["status", "body"],
        "properties": {
          "status": { "$ref": "#/components/schemas/IncidentStatus" },
          "body": { "type": "string", "maxLength": 8000 }
        }
      },
      "GroupPage": {
        "type": "object",
        "required": ["id"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "component_ids": { "type": "array", "items": { "type": "string", "format": "uuid" } }
        }
      },
      "CreateIncidentGroup": {
        "type": "object",
        "required": ["title", "impact", "body", "pages"],
        "properties": {
          "title": { "type": "string", "maxLength": 300 },
          "impact": { "$ref": "#/components/schemas/IncidentImpact" },
          "body": { "type": "string", "maxLength": 8000 },
          "pages": { "type": "array", "minItems": 1, "items": { "$ref": "#/components/schemas/GroupPage" } }
        }
      },
      "PostedUpdate": {
        "type": "object",
        "required": ["incident_id", "update_id", "status", "body", "components"],
        "properties": {
          "incident_id": { "type": "string", "format": "uuid" },
          "update_id": { "type": "string", "format": "uuid" },
          "status": { "$ref": "#/components/schemas/IncidentStatus" },
          "body": { "type": "string" },
          "incident": { "$ref": "#/components/schemas/Incident" },
          "components": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["id", "status"],
              "properties": {
                "id": { "type": "string", "format": "uuid" },
                "status": { "$ref": "#/components/schemas/ComponentStatus" }
              }
            }
          }
        }
      },
      "Monitor": {
        "type": "object",
        "required": ["id", "page_id", "name", "url", "method", "enabled", "state"],
        "properties": {
          "id": { "type": "string", "format": "uuid" },
          "page_id": { "type": "string", "format": "uuid" },
          "component_id": { "type": "string", "format": "uuid", "nullable": true },
          "name": { "type": "string" },
          "url": { "type": "string" },
          "method": { "type": "string", "enum": ["GET", "HEAD"] },
          "interval_minutes": { "type": "integer", "enum": [1, 5, 10] },
          "keyword": { "type": "string", "nullable": true },
          "enabled": { "type": "boolean" },
          "state": { "type": "string", "enum": ["up", "down", "unknown"] },
          "last_checked_at": { "type": "string", "format": "date-time", "nullable": true },
          "uptime_24h": { "type": "number", "nullable": true },
          "uptime_30d": { "type": "number", "nullable": true }
        }
      },
      "IncidentGroup": {
        "type": "object",
        "required": ["incident_group_id", "incidents"],
        "properties": {
          "incident_group_id": { "type": "string", "format": "uuid" },
          "incidents": { "type": "array", "items": { "$ref": "#/components/schemas/Incident" } }
        }
      }
    }
  }
}
