{
  "openapi": "3.1.0",
  "info": {
    "title": "SeaTree Intelligence API",
    "version": "0.3.0",
    "description": "Business website intelligence, construction/license activity intelligence, saved watches, durable event history, and signed webhooks. Public-record scores are heuristics and limited-source summaries, not verification or guarantees."
  },
  "servers": [
    {
      "url": "https://api.seatreesoftware.com"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "Healthy"
          }
        }
      }
    },
    "/v1/sources": {
      "get": {
        "summary": "List active data sources",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Sources"
          }
        }
      }
    },
    "/v1/business/extract": {
      "post": {
        "summary": "Extract structured intelligence from a public business website",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "refresh",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Bypass the extraction cache"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "examples": [
                      "https://example.com"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Structured business profile"
          },
          "400": {
            "description": "Invalid URL"
          },
          "422": {
            "description": "Target could not be processed"
          }
        }
      }
    },
    "/v1/business/enrich": {
      "post": {
        "summary": "Enrich a business by crawling high-value pages on the same website",
        "description": "Starts from the supplied URL, follows selected same-origin services/contact/location/about links, and merges deterministic signals from up to 8 pages.",
        "parameters": [
          {
            "name": "refresh",
            "in": "query",
            "schema": {
              "type": "boolean"
            },
            "description": "Bypass the enrichment cache"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "examples": [
                      "https://example.com"
                    ]
                  },
                  "max_pages": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8,
                    "default": 4
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Merged multi-page business profile"
          },
          "400": {
            "description": "Invalid request"
          },
          "422": {
            "description": "Target could not be processed"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/permits/greenville": {
      "get": {
        "summary": "Search recent City of Greenville building permits",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 730,
              "default": 30
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "min_value",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0,
              "default": 0
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "contractor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Normalized permit records"
          }
        }
      }
    },
    "/v1/signals/greenville": {
      "get": {
        "summary": "Derive construction and adjacent-service opportunity signals from Greenville permits",
        "security": [
          {
            "ApiKey": []
          }
        ],
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "maximum": 730,
              "default": 30
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "min_value",
            "in": "query",
            "schema": {
              "type": "number",
              "minimum": 0,
              "default": 0
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "contractor",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked intent-signal records"
          }
        }
      }
    },
    "/v1/licenses/sc/status-changes": {
      "get": {
        "summary": "Search recent South Carolina contractor and residential-builder license status changes",
        "description": "Normalizes the SC LLR rolling seven-day status-change page. This is not a complete license roster or authoritative verification endpoint.",
        "parameters": [
          {
            "name": "board",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "contractors",
                "residential"
              ],
              "default": "all"
            }
          },
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 7,
              "default": 7
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "current_status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Normalized recent status-change events"
          },
          "502": {
            "description": "SC LLR source unavailable or format changed"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/contractors/sc/activity": {
      "get": {
        "summary": "Build a partial South Carolina contractor activity profile",
        "description": "Combines City of Greenville permit activity matching a contractor name with SC LLR rolling seven-day license-status events. It is intentionally labeled partial and is not license verification.",
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 2
            }
          },
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 730,
              "default": 365
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Partial contractor activity profile"
          },
          "400": {
            "description": "Missing or invalid contractor name"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/contractors/greenville/rankings": {
      "get": {
        "summary": "Rank contractors by observed Greenville permit activity",
        "description": "Ranks contractors using permit count, reported valuation and recency. The activity score is not a quality, credit, safety or compliance score.",
        "parameters": [
          {
            "name": "days",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 730,
              "default": 90
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200,
              "default": 50
            }
          },
          {
            "name": "min_permits",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked contractor activity records"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/watches": {
      "post": {
        "summary": "Create a saved intelligence watch",
        "description": "Creates a recurring watch for Greenville permits or SC LLR license-status changes. Existing source records are baselined so webhooks focus on newly detected events.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "type"
                ],
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "permit.greenville",
                      "license.sc.status"
                    ]
                  },
                  "filters": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Type-specific filters. Permit watches support days, min_value, q, contractor. License watches support board, days, q, city, current_status."
                  },
                  "webhook_url": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uri",
                    "description": "Optional public HTTPS/HTTP endpoint for signed event delivery."
                  },
                  "enabled": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Watch created. If webhook_url is supplied, webhook_secret is returned only in this response."
          },
          "400": {
            "description": "Invalid watch definition"
          },
          "409": {
            "description": "Per-consumer watch limit reached"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      },
      "get": {
        "summary": "List saved watches",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Watches owned by the authenticated consumer"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/watches/{id}": {
      "get": {
        "summary": "Get a saved watch",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Watch"
          },
          "404": {
            "description": "Watch not found"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      },
      "patch": {
        "summary": "Update a saved watch",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "filters": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "webhook_url": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "uri",
                    "description": "Set to null to disable webhook delivery. Replacing it rotates the webhook secret."
                  },
                  "enabled": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated watch. A new webhook_secret is returned only when webhook_url is replaced."
          },
          "400": {
            "description": "Invalid update"
          },
          "404": {
            "description": "Watch not found"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      },
      "delete": {
        "summary": "Delete a saved watch and its event history",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Watch deleted"
          },
          "404": {
            "description": "Watch not found"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/watches/{id}/run": {
      "post": {
        "summary": "Run a saved watch immediately",
        "description": "Runs the same evaluation used by the recurring monitor loop and immediately attempts any due webhook deliveries.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Watch evaluation summary"
          },
          "404": {
            "description": "Watch not found"
          },
          "502": {
            "description": "Upstream source unavailable"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    },
    "/v1/events": {
      "get": {
        "summary": "List detected watch events",
        "description": "Returns durable event history. Baselined source records are hidden by default.",
        "parameters": [
          {
            "name": "watch_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 100
            }
          },
          {
            "name": "include_baseline",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Detected events owned by the authenticated consumer"
          },
          "404": {
            "description": "Specified watch not found"
          }
        },
        "security": [
          {
            "ApiKey": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Direct SeaTree API key. RapidAPI consumers use RapidAPI runtime authentication instead."
      }
    }
  }
}