{
  "openapi": "3.1.0",
  "info": {
    "title": "Trusoro API",
    "version": "0.1.0",
    "description": "Read and submit Florida business listings. By submitting, you confirm the information is accurate and that you may share it. Every listing is checked and moderated before it is published; we may edit or remove it. Street addresses are never shown publicly. Owners can confirm a listing to manage it."
  },
  "servers": [
    {
      "url": "https://trusoro.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Optional. Get one from POST /v1/keys."
      }
    },
    "schemas": {
      "ListingInput": {
        "type": "object",
        "description": "Send at least a website that shows the business name and city, or send name and city. Everything else is optional; missing details are read from the website.",
        "properties": {
          "name": {
            "type": "string",
            "maxLength": 120
          },
          "city": {
            "type": "string",
            "maxLength": 60
          },
          "state": {
            "type": "string",
            "pattern": "^[A-Za-z]{2}$",
            "default": "FL"
          },
          "category": {
            "type": "string",
            "description": "Slug from GET /v1/categories, or a plain word such as \"roofer\". Optional: guessed from the name or website when omitted."
          },
          "industry": {
            "type": "string",
            "maxLength": 60,
            "description": "What the business does, when no category fits."
          },
          "website": {
            "type": "string",
            "maxLength": 200
          },
          "phone": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "maxLength": 1000
          },
          "address": {
            "type": "string",
            "maxLength": 200,
            "description": "Stored privately, never published."
          },
          "license_no": {
            "type": "string",
            "maxLength": 20
          },
          "social": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 8,
            "description": "Business pages on Google, Facebook, Instagram, Yelp, Nextdoor and similar sites."
          }
        }
      }
    }
  },
  "paths": {
    "/v1/prefill": {
      "post": {
        "summary": "Read business details and a website check from a website",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "website"
                ],
                "properties": {
                  "website": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "fields, site_report"
          }
        }
      }
    },
    "/v1/keys": {
      "post": {
        "summary": "Create an API key (no account)",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "agent_name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "api_key, shown once"
          },
          "429": {
            "description": "Too many keys today"
          }
        }
      }
    },
    "/v1/categories": {
      "get": {
        "summary": "Categories with listing counts",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/v1/listings": {
      "get": {
        "summary": "Search published listings",
        "parameters": [
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "city",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "listings, next_offset"
          }
        }
      },
      "post": {
        "summary": "Submit a business",
        "security": [
          {},
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ListingInput"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "submission_id, status_url, terms"
          },
          "400": {
            "description": "reason_codes and per-field errors"
          },
          "429": {
            "description": "Daily limit"
          }
        }
      }
    },
    "/v1/listings/{id}": {
      "get": {
        "summary": "One listing with Florida license records",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "listing"
          },
          "404": {
            "description": "Not found"
          }
        }
      },
      "patch": {
        "summary": "Edit a listing (owner-approved key)",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "description": {
                    "type": "string"
                  },
                  "phone": {
                    "type": "string"
                  },
                  "website": {
                    "type": "string"
                  },
                  "industry_label": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "changed fields"
          },
          "403": {
            "description": "Key not approved by the owner"
          }
        }
      }
    },
    "/v1/listings/{id}/report": {
      "post": {
        "summary": "Report a problem",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "minLength": 5,
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted"
          }
        }
      }
    },
    "/v1/submissions/{id}": {
      "get": {
        "summary": "Submission status and reason codes",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "status: checking | published | yellow | needs_info | red | rejected"
          }
        }
      }
    },
    "/v1/claims": {
      "post": {
        "summary": "Start owner confirmation",
        "security": [
          {},
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "listing_id"
                ],
                "properties": {
                  "listing_id": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "confirm_url, user_code, site_verification"
          }
        }
      }
    },
    "/v1/claims/{id}": {
      "get": {
        "summary": "Owner confirmation status",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "pending | confirmed | expired"
          }
        }
      }
    },
    "/v1/claims/{id}/verify-site": {
      "post": {
        "summary": "Check the site verification file or meta tag",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "confirmed"
          },
          "400": {
            "description": "reason_codes"
          }
        }
      }
    }
  }
}