{
  "openapi": "3.1.0",
  "info": {
    "title": "Hailtrades API",
    "version": "0.1.0",
    "summary": "Emergency residential plumbers and electricians in Toronto/GTA, for AI agents.",
    "description": "Same capabilities as the MCP server at https://hailtrades.com/mcp. Every search/get result includes ref (a unique HT-XXXX code) and suggested_message (an optional message the user can send; it mentions Hailtrades and the ref). If the user contacts a provider, the outcome can optionally be recorded with POST /api/v1/contact-reports. Null/unknown fields mean unknown, not 'no'."
  },
  "servers": [
    {
      "url": "https://hailtrades.com"
    }
  ],
  "externalDocs": {
    "description": "How to connect (MCP, API, examples)",
    "url": "https://hailtrades.com/for-agents"
  },
  "paths": {
    "/api/v1/providers/search": {
      "get": {
        "operationId": "searchProviders",
        "summary": "Search emergency plumbers/electricians",
        "description": "Provide `location` or `postal_code`. Results ordered 24/7 first, then emergency-capable, then by rating.",
        "parameters": [
          {
            "name": "trade",
            "in": "query",
            "required": true,
            "description": "Which trade you need.",
            "schema": {
              "type": "string",
              "enum": [
                "plumber",
                "electrician"
              ]
            }
          },
          {
            "name": "location",
            "in": "query",
            "description": "Where the job is: a Toronto/GTA city, district or neighbourhood, e.g. 'North York', 'Scarborough', 'Etobicoke', 'Mississauga', 'Oakville', 'Vaughan', 'Thornhill', 'Liberty Village', 'Leslieville'. A postal code or FSA also works here. Provide this or postal_code. Toronto and the GTA only.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "postal_code",
            "in": "query",
            "description": "Canadian postal code or 3-character FSA (forward sortation area), e.g. 'M2N 5W3' or 'M6P'. Use when the user gives one. Provide this or location.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "emergency",
            "in": "query",
            "description": "true = only providers that are 24/7 or explicitly offer emergency (unplanned, urgent) service. Use for burst pipes, no power, sewer backup, sparks.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "open_now",
            "in": "query",
            "description": "true = only providers confirmed open right now (America/Toronto time) from stored hours, or flagged 24/7. Providers with no hours on file are excluded.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "service",
            "in": "query",
            "description": "Service slug or keyword, e.g. burst_pipe, drain_clearing, sewer_backup, water_heater_repair, power_outage, breaker_repair, panel_upgrade.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "max_callout_fee",
            "in": "query",
            "description": "Maximum call-out fee in CAD. Providers with a known fee above this are excluded; providers with an unknown fee are kept and marked unknown.",
            "schema": {
              "type": "number"
            }
          },
          {
            "name": "issue",
            "in": "query",
            "description": "Optional short description of the problem (e.g. 'a burst pipe in the basement'). Only used to word suggested_message.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "description": "best_match (default): 24/7 first, then emergency-capable, then providers with fees/hours/verification on file, then rating. lowest_callout_fee / lowest_after_hours_fee: providers with a KNOWN fee, cheapest first, then providers with an unknown fee. Use for 'cheapest' questions; most providers do not publish a fee, so tell the user how many results had a known fee.",
            "schema": {
              "type": "string",
              "enum": [
                "best_match",
                "lowest_callout_fee",
                "lowest_after_hours_fee"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Max results (default 5, max 10). Each result is a full provider record, so keep this small.",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 10
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SearchResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/providers/{id}": {
      "get": {
        "operationId": "getProvider",
        "summary": "Get a provider by id or slug",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Provider id from search_providers (e.g. prv_ab12cd34ef) or the provider's page slug."
          },
          {
            "name": "issue",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Optional short description of the problem, used to word suggested_message."
          }
        ],
        "responses": {
          "200": {
            "description": "Provider",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "provider": {
                      "$ref": "#/components/schemas/Provider"
                    }
                  },
                  "additionalProperties": true
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/v1/contact-reports": {
      "post": {
        "operationId": "reportContact",
        "summary": "Report the outcome of contacting a provider",
        "description": "Call after you contact a provider so availability data stays accurate for other users.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "description": "The provider id you contacted."
                  },
                  "ref": {
                    "type": "string",
                    "description": "The HT-XXXX ref code from the search/get result for that provider (strongly recommended)."
                  },
                  "channel": {
                    "type": "string",
                    "enum": [
                      "call",
                      "text",
                      "email",
                      "form"
                    ],
                    "description": "How you contacted them."
                  },
                  "outcome": {
                    "type": "string",
                    "enum": [
                      "no_answer",
                      "quote_given",
                      "visit_booked",
                      "declined",
                      "other"
                    ],
                    "description": "What happened: no_answer, quote_given, visit_booked, declined (provider declined or unavailable), or other (explain in notes)."
                  },
                  "time": {
                    "type": "string",
                    "description": "ISO 8601 time of the contact attempt (defaults to now if omitted)."
                  },
                  "notes": {
                    "type": "string",
                    "description": "Optional facts that help other users: actual fee quoted, arrival time, whether they were open/after-hours. No personal details about the customer."
                  }
                },
                "required": [
                  "provider_id",
                  "channel",
                  "outcome"
                ],
                "additionalProperties": false
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Recorded",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "string"
                }
              },
              "required": [
                "error"
              ]
            }
          }
        }
      }
    },
    "schemas": {
      "Provider": {
        "type": "object",
        "additionalProperties": true,
        "description": "Provider record. See /for-agents for field notes.",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "trade": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "plumber",
                "electrician"
              ]
            }
          },
          "ref": {
            "type": "string",
            "description": "Unique ref code HT-XXXX for this result"
          },
          "suggested_message": {
            "type": "string",
            "description": "Optional message the user can send; mentions Hailtrades and the ref"
          },
          "mock": {
            "type": "boolean"
          },
          "last_verified": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "SearchResponse": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "request_id": {
            "type": "string"
          },
          "mock": {
            "type": "boolean"
          },
          "count": {
            "type": "integer"
          },
          "total_matches": {
            "type": "integer"
          },
          "results": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Provider"
            }
          },
          "report_contact_note": {
            "type": "string"
          }
        }
      }
    }
  }
}