{
  "openapi": "3.1.0",
  "info": {
    "title": "CurbScanner API",
    "version": "0.1.0-draft"
  },
  "servers": [
    {
      "url": "https://curbscanner.com"
    }
  ],
  "security": [
    {
      "key": []
    }
  ],
  "components": {
    "securitySchemes": {
      "key": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "House": {
        "type": "object",
        "required": [
          "n",
          "address",
          "result",
          "tier",
          "condition",
          "vacancy",
          "evidence",
          "vacancy_cues",
          "signs",
          "photo_date",
          "photo_old",
          "sold_after_photo",
          "verdict"
        ],
        "properties": {
          "n": {
            "type": "integer",
            "description": "Position in the scan, from 1"
          },
          "address": {
            "type": "string"
          },
          "result": {
            "enum": [
              "graded",
              "no_photo",
              "not_visible"
            ],
            "description": "no_photo: no street-level photo here (free). not_visible: the photo doesn’t show the front."
          },
          "tier": {
            "enum": [
              "extreme",
              "high",
              "medium",
              "low",
              null
            ]
          },
          "condition": {
            "enum": [
              "good",
              "fair",
              "poor",
              "distressed",
              null
            ]
          },
          "vacancy": {
            "enum": [
              "none",
              "possible",
              "likely",
              null
            ]
          },
          "evidence": {
            "type": "array",
            "description": "What the grade rests on",
            "items": {
              "type": "object",
              "required": [
                "text",
                "severity"
              ],
              "properties": {
                "text": {
                  "type": "string"
                },
                "severity": {
                  "enum": [
                    "minor",
                    "moderate",
                    "severe"
                  ]
                }
              }
            }
          },
          "vacancy_cues": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "signs": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "For Sale, For Rent, Sold, dumpster, renovation"
          },
          "photo_date": {
            "type": [
              "string",
              "null"
            ],
            "description": "YYYY-MM"
          },
          "photo_old": {
            "type": "boolean",
            "description": "The photo is more than 5 years old"
          },
          "sold_after_photo": {
            "type": "boolean",
            "description": "The house sold after the photo was taken"
          },
          "verdict": {
            "enum": [
              "keep",
              "reject",
              null
            ]
          }
        }
      },
      "HouseView": {
        "allOf": [
          {
            "$ref": "#/components/schemas/House"
          },
          {
            "type": "object",
            "properties": {
              "prev": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "next": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          }
        ]
      },
      "HousePage": {
        "type": "object",
        "required": [
          "items",
          "next",
          "total"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/House"
            }
          },
          "next": {
            "type": [
              "string",
              "null"
            ]
          },
          "total": {
            "type": "integer"
          }
        }
      },
      "Scan": {
        "type": "object",
        "required": [
          "id",
          "name",
          "created",
          "status",
          "total",
          "scanned",
          "counts",
          "charged",
          "filters"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "created": {
            "type": "string",
            "format": "date-time"
          },
          "status": {
            "enum": [
              "running",
              "done"
            ]
          },
          "total": {
            "type": "integer"
          },
          "scanned": {
            "type": "integer",
            "description": "Houses finished so far"
          },
          "counts": {
            "type": "object",
            "description": "Filled in when the scan is done",
            "properties": {
              "extreme": {
                "type": "integer"
              },
              "high": {
                "type": "integer"
              },
              "medium": {
                "type": "integer"
              },
              "low": {
                "type": "integer"
              },
              "no_photo": {
                "type": "integer"
              },
              "not_visible": {
                "type": "integer"
              },
              "kept": {
                "type": "integer"
              }
            }
          },
          "charged": {
            "type": "number",
            "description": "Dollars charged beyond the plan’s included houses"
          },
          "filters": {
            "type": "array",
            "items": {
              "enum": [
                "absentee"
              ]
            },
            "description": "What narrowed a scan of places; empty for none"
          }
        }
      },
      "ScanList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Scan"
            }
          }
        }
      },
      "Place": {
        "type": "object",
        "required": [
          "id",
          "kind",
          "name",
          "houses"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "zip:53711, city:WI:fairview, or county: and the county’s FIPS code"
          },
          "kind": {
            "enum": [
              "zip",
              "city",
              "county"
            ]
          },
          "name": {
            "type": "string"
          },
          "houses": {
            "type": "integer",
            "description": "Single-family homes, townhouses, 2-4 units and manufactured homes"
          }
        }
      },
      "PlaceList": {
        "type": "object",
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Place"
            }
          }
        }
      },
      "Estimate": {
        "type": "object",
        "required": [
          "houses",
          "ceiling"
        ],
        "properties": {
          "houses": {
            "type": "integer",
            "description": "Each house counted once, even where places overlap"
          },
          "ceiling": {
            "type": "number",
            "description": "Dollars: the most the scan can cost on your plan"
          }
        }
      },
      "NewScan": {
        "type": "object",
        "description": "Places or addresses, not both",
        "oneOf": [
          {
            "required": [
              "places"
            ]
          },
          {
            "required": [
              "addresses"
            ]
          }
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Defaults to the places and filters, or to the first address"
          },
          "places": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string"
            },
            "description": "Place ids, from Find places"
          },
          "filters": {
            "type": "array",
            "items": {
              "enum": [
                "absentee"
              ]
            },
            "description": "With places only. absentee: the owner’s mailing address is somewhere else, or the owner is a company"
          },
          "addresses": {
            "type": "array",
            "minItems": 1,
            "maxItems": 10000,
            "items": {
              "oneOf": [
                {
                  "type": "string"
                },
                {
                  "type": "object",
                  "required": [
                    "address"
                  ],
                  "properties": {
                    "address": {
                      "type": "string"
                    },
                    "city": {
                      "type": "string"
                    },
                    "state": {
                      "type": "string"
                    },
                    "zip": {
                      "type": "string"
                    }
                  }
                }
              ]
            }
          }
        }
      },
      "Verdict": {
        "type": "object",
        "required": [
          "verdict"
        ],
        "properties": {
          "verdict": {
            "enum": [
              "keep",
              "reject",
              null
            ]
          }
        }
      },
      "PlanChange": {
        "type": "object",
        "required": [
          "plan"
        ],
        "properties": {
          "plan": {
            "enum": [
              "payg",
              "scout",
              "pro"
            ]
          }
        }
      },
      "Funds": {
        "type": "object",
        "required": [
          "amount",
          "card_token"
        ],
        "properties": {
          "amount": {
            "type": "number",
            "minimum": 25
          },
          "card_token": {
            "type": "string"
          }
        }
      },
      "NewKey": {
        "type": "object",
        "required": [
          "key"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "Shown once"
          }
        }
      },
      "Account": {
        "type": "object",
        "properties": {
          "email": {
            "type": "string"
          },
          "plan": {
            "enum": [
              "payg",
              "scout",
              "pro"
            ]
          },
          "included_used": {
            "type": "integer"
          },
          "balance": {
            "type": "number"
          },
          "renews": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "api_key_last4": {
            "type": "string"
          },
          "receipts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "date": {
                  "type": "string"
                },
                "amount": {
                  "type": "number"
                },
                "what": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "enum": [
                  "unauthorized",
                  "not_found",
                  "invalid_places",
                  "invalid_scan",
                  "invalid_addresses",
                  "too_many_addresses",
                  "insufficient_funds",
                  "unavailable",
                  "not_open"
                ]
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  },
  "paths": {
    "/api/places": {
      "get": {
        "operationId": "find-places",
        "summary": "Find places",
        "description": "ZIPs, cities and counties, each with its houses: single-family homes, townhouses, 2-4 units and manufactured homes.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "a name, or the start of a ZIP: Fairview, Kettle County, 537",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Find places",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PlaceList"
                },
                "example": {
                  "items": [
                    {
                      "id": "city:WI:fairview",
                      "kind": "city",
                      "name": "Fairview, WI",
                      "houses": 21480
                    },
                    {
                      "id": "zip:53711",
                      "kind": "zip",
                      "name": "53711 · Fairview, WI",
                      "houses": 2839
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/scans": {
      "post": {
        "operationId": "start-a-scan",
        "summary": "Start a scan",
        "description": "Places from Find places, or up to 10,000 addresses, not both. An address is a line of text or an object with address, city, state and zip. Where places overlap, each house is scanned once. Filters narrow a scan of places (absentee: the owner’s mailing address is somewhere else, or the owner is a company). Without a name, a scan of places is named after its places and filters.",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewScan"
              },
              "example": {
                "places": [
                  "zip:53711"
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Start a scan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scan"
                },
                "example": {
                  "id": "k3f9q2",
                  "name": "53711 · Fairview, WI",
                  "created": "2026-11-16T15:04:05Z",
                  "status": "running",
                  "total": 2839,
                  "scanned": 0,
                  "counts": {
                    "extreme": 0,
                    "high": 0,
                    "medium": 0,
                    "low": 0,
                    "no_photo": 0,
                    "not_visible": 0,
                    "kept": 0
                  },
                  "charged": 0,
                  "filters": []
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "operationId": "list-scans",
        "summary": "List scans",
        "description": "Newest first.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "List scans",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanList"
                },
                "example": {
                  "items": [
                    {
                      "id": "k3f9q2",
                      "name": "53711 · Fairview, WI",
                      "created": "2026-11-16T15:04:05Z",
                      "status": "done",
                      "total": 2839,
                      "scanned": 2839,
                      "counts": {
                        "extreme": 41,
                        "high": 212,
                        "medium": 398,
                        "low": 1513,
                        "no_photo": 312,
                        "not_visible": 363,
                        "kept": 0
                      },
                      "charged": 0,
                      "filters": []
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/scans/estimate": {
      "post": {
        "operationId": "estimate-a-scan",
        "summary": "Estimate a scan",
        "description": "The houses Start a scan would cover, and the most it can cost on your plan. Houses with no photo are free, so the charge is usually lower.",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/NewScan"
              },
              "example": {
                "places": [
                  "county:55901"
                ],
                "filters": [
                  "absentee"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Estimate a scan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Estimate"
                },
                "example": {
                  "houses": 10302,
                  "ceiling": 282.66
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/scans/{id}": {
      "get": {
        "operationId": "get-a-scan",
        "summary": "Get a scan",
        "description": "Progress while it runs. Houses and tiers arrive when the status is done.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Get a scan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scan"
                },
                "example": {
                  "id": "k3f9q2",
                  "name": "53711 · Fairview, WI",
                  "created": "2026-11-16T15:04:05Z",
                  "status": "done",
                  "total": 2839,
                  "scanned": 2839,
                  "counts": {
                    "extreme": 41,
                    "high": 212,
                    "medium": 398,
                    "low": 1513,
                    "no_photo": 312,
                    "not_visible": 363,
                    "kept": 0
                  },
                  "charged": 0,
                  "filters": []
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/scans/{id}/houses": {
      "get": {
        "operationId": "list-houses",
        "summary": "List houses",
        "description": "Ordered by tier, Extreme first. Houses that weren’t graded come last.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "filter",
            "in": "query",
            "description": "all (default), extreme, high, medium, low or kept",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "next, from the previous page",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "1 to 500, default 100",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List houses",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HousePage"
                },
                "example": {
                  "items": [
                    {
                      "n": 7,
                      "address": "2210 Juniper Ave, Fairview, WI 53711",
                      "result": "graded",
                      "tier": "extreme",
                      "condition": "distressed",
                      "vacancy": "likely",
                      "evidence": [
                        {
                          "text": "Boarded windows",
                          "severity": "severe"
                        },
                        {
                          "text": "Roof tarp",
                          "severity": "moderate"
                        }
                      ],
                      "vacancy_cues": [
                        "Mail piled at the door"
                      ],
                      "signs": [],
                      "photo_date": "2024-08",
                      "photo_old": false,
                      "sold_after_photo": false,
                      "verdict": null
                    }
                  ],
                  "next": "100",
                  "total": 2839
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/scans/{id}/houses/{n}": {
      "get": {
        "operationId": "get-a-house",
        "summary": "Get a house",
        "description": "One house, with the houses before and after it in the same order.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "n",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "filter",
            "in": "query",
            "description": "the order to step through, as in List houses",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Get a house",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HouseView"
                },
                "example": {
                  "n": 7,
                  "address": "2210 Juniper Ave, Fairview, WI 53711",
                  "result": "graded",
                  "tier": "extreme",
                  "condition": "distressed",
                  "vacancy": "likely",
                  "evidence": [
                    {
                      "text": "Boarded windows",
                      "severity": "severe"
                    },
                    {
                      "text": "Roof tarp",
                      "severity": "moderate"
                    }
                  ],
                  "vacancy_cues": [
                    "Mail piled at the door"
                  ],
                  "signs": [],
                  "photo_date": "2024-08",
                  "photo_old": false,
                  "sold_after_photo": false,
                  "verdict": null,
                  "prev": null,
                  "next": 12
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/scans/{id}/houses/{n}/verdict": {
      "put": {
        "operationId": "keep-or-reject",
        "summary": "Keep or reject a house",
        "description": "Send null to clear it.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "n",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Verdict"
              },
              "example": {
                "verdict": "keep"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Keep or reject a house",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/House"
                },
                "example": {
                  "n": 7,
                  "address": "2210 Juniper Ave, Fairview, WI 53711",
                  "result": "graded",
                  "tier": "extreme",
                  "condition": "distressed",
                  "vacancy": "likely",
                  "evidence": [
                    {
                      "text": "Boarded windows",
                      "severity": "severe"
                    },
                    {
                      "text": "Roof tarp",
                      "severity": "moderate"
                    }
                  ],
                  "vacancy_cues": [
                    "Mail piled at the door"
                  ],
                  "signs": [],
                  "photo_date": "2024-08",
                  "photo_old": false,
                  "sold_after_photo": false,
                  "verdict": "keep"
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account": {
      "get": {
        "operationId": "get-your-account",
        "summary": "Get your account",
        "description": "Plan, included houses used this month, balance and receipts.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Get your account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                },
                "example": {
                  "email": "you@example.com",
                  "plan": "scout",
                  "included_used": 1620,
                  "balance": 18.4,
                  "renews": "2026-12-01T00:00:00Z",
                  "api_key_last4": "4f2a",
                  "receipts": [
                    {
                      "id": "r3",
                      "date": "2026-11-13T09:00:00Z",
                      "amount": 49,
                      "what": "Scout, monthly"
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/plan": {
      "put": {
        "operationId": "change-plan",
        "summary": "Change plan",
        "description": "payg, scout or pro.",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PlanChange"
              },
              "example": {
                "plan": "pro"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Change plan",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                },
                "example": {
                  "email": "you@example.com",
                  "plan": "pro",
                  "included_used": 1620,
                  "balance": 18.4,
                  "renews": "2026-12-01T00:00:00Z",
                  "api_key_last4": "4f2a",
                  "receipts": [
                    {
                      "id": "r3",
                      "date": "2026-11-13T09:00:00Z",
                      "amount": 49,
                      "what": "Scout, monthly"
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/funds": {
      "post": {
        "operationId": "add-funds",
        "summary": "Add funds",
        "description": "At least $25. The card token comes from the card form on the Account screen.",
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Funds"
              },
              "example": {
                "amount": 50,
                "card_token": "tok_…"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Add funds",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Account"
                },
                "example": {
                  "email": "you@example.com",
                  "plan": "scout",
                  "included_used": 1620,
                  "balance": 68.4,
                  "renews": "2026-12-01T00:00:00Z",
                  "api_key_last4": "4f2a",
                  "receipts": [
                    {
                      "id": "r3",
                      "date": "2026-11-13T09:00:00Z",
                      "amount": 49,
                      "what": "Scout, monthly"
                    }
                  ]
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/account/key": {
      "post": {
        "operationId": "new-api-key",
        "summary": "New API key",
        "description": "Replaces the current key. The new key is shown once.",
        "parameters": [],
        "responses": {
          "200": {
            "description": "New API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NewKey"
                },
                "example": {
                  "key": "cs_live_…"
                }
              }
            }
          },
          "default": {
            "description": "Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}