{
  "openapi": "3.1.0",
  "info": {
    "title": "Wybox API",
    "version": "0.1.0",
    "description": "Sandbox HTTP API. Wybox matches assets to official warnings and returns the affected assets with the issuing agency's own text. Wybox does not issue warnings. It does not issue forecasts. It does not reroute people or assets. Earthquake alerts are issued after the event. Wybox does not provide earthquake early warning. The server URL in this file is example data. The base URL is issued with the sandbox API key. This document does not state a numeric rate limit."
  },
  "servers": [
    {
      "url": "https://api.example.invalid",
      "description": "Example data. Replace with the base URL issued with the sandbox API key."
    }
  ],
  "security": [{ "bearerAuth": [] }, { "apiKeyAuth": [] }],
  "tags": [
    { "name": "Assets" },
    { "name": "Recipients" },
    { "name": "Subscriptions" },
    { "name": "Alerts" },
    { "name": "Deliveries" },
    { "name": "Usage" },
    { "name": "Sources" },
    { "name": "Account" }
  ],
  "paths": {
    "/v1/assets": {
      "get": {
        "tags": ["Assets"],
        "summary": "List monitored assets for the tenant.",
        "responses": {
          "200": { "description": "Assets for the tenant." },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      },
      "post": {
        "tags": ["Assets"],
        "summary": "Create a monitored asset.",
        "description": "Moving assets send the latest position, not a track.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AssetInput" }
            }
          }
        },
        "responses": {
          "201": { "description": "The asset was created." },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/recipients": {
      "get": {
        "tags": ["Recipients"],
        "summary": "List recipients for the tenant.",
        "responses": {
          "200": { "description": "Recipients for the tenant." },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      },
      "post": {
        "tags": ["Recipients"],
        "summary": "Create a recipient.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/RecipientInput" }
            }
          }
        },
        "responses": {
          "201": { "description": "The recipient was created." },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/subscriptions": {
      "get": {
        "tags": ["Subscriptions"],
        "summary": "List subscriptions for the tenant.",
        "responses": {
          "200": { "description": "Subscriptions for the tenant." },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      },
      "post": {
        "tags": ["Subscriptions"],
        "summary": "Subscribe a recipient to alerts for an asset.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SubscriptionInput" }
            }
          }
        },
        "responses": {
          "201": { "description": "The subscription was created." },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/alerts": {
      "get": {
        "tags": ["Alerts"],
        "summary": "List official warnings that affect the tenant's assets.",
        "responses": {
          "200": {
            "description": "Matched alerts. Example payloads are example data.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AlertList" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/alerts/{id}": {
      "get": {
        "tags": ["Alerts"],
        "summary": "Read one matched alert.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": { "description": "The alert." },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/v1/deliveries": {
      "get": {
        "tags": ["Deliveries"],
        "summary": "List delivery attempts for the tenant.",
        "responses": {
          "200": { "description": "Delivery attempts." },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "tags": ["Usage"],
        "summary": "Report monitored assets and messages for the current month.",
        "responses": {
          "200": {
            "description": "Monitored assets in the current month, and messages sent.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Usage" }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/sources": {
      "get": {
        "tags": ["Sources"],
        "summary": "List official sources configured for the tenant.",
        "responses": {
          "200": { "description": "Official sources configured for the tenant." },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/status": {
      "get": {
        "tags": ["Sources"],
        "summary": "Feed health for connected official sources.",
        "responses": {
          "200": { "description": "Current feed health." },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/account/export": {
      "get": {
        "tags": ["Account"],
        "summary": "Export customer data held for the tenant.",
        "description": "Customer export endpoint for data-rights requests.",
        "responses": {
          "200": { "description": "Export of customer data held for the tenant." },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/v1/account": {
      "delete": {
        "tags": ["Account"],
        "summary": "Delete customer data held for the tenant.",
        "description": "Customer delete endpoint for data-rights requests.",
        "responses": {
          "202": { "description": "Deletion of customer data for the tenant was accepted." },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    }
  },
  "webhooks": {
    "alertDelivery": {
      "post": {
        "summary": "Signed delivery of an official warning to the tenant webhook.",
        "description": "X-Wybox-Timestamp is unix time in seconds. X-Wybox-Signature is the string v1= followed by HMAC-SHA256 of timestamp + '.' + raw body, using the tenant webhook secret. Reject timestamps older than 5 minutes.",
        "parameters": [
          {
            "name": "X-Wybox-Timestamp",
            "in": "header",
            "required": true,
            "description": "Unix time in seconds. Reject timestamps older than 5 minutes.",
            "schema": { "type": "string" }
          },
          {
            "name": "X-Wybox-Signature",
            "in": "header",
            "required": true,
            "description": "v1= plus HMAC-SHA256 of timestamp + '.' + raw body, keyed with the tenant webhook secret.",
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/Alert" }
            }
          }
        },
        "responses": {
          "200": { "description": "The receiver accepted the delivery." }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authorization: Bearer, followed by the tenant API key."
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Api-Key",
        "description": "Tenant API key in the X-Api-Key header."
      }
    },
    "responses": {
      "BadRequest": { "description": "The request is invalid." },
      "Unauthorized": { "description": "The API key is missing or not recognized." },
      "NotFound": { "description": "The resource does not exist." }
    },
    "schemas": {
      "AssetInput": {
        "type": "object",
        "required": ["name", "kind"],
        "properties": {
          "name": { "type": "string" },
          "kind": {
            "type": "string",
            "enum": ["vehicle", "site", "property", "itinerary", "field"]
          },
          "zone": {
            "type": "string",
            "description": "Official zone code, where the source publishes zones."
          },
          "radius_m": {
            "type": "number",
            "description": "Radius in meters around a point."
          },
          "geometry": {
            "type": "object",
            "description": "GeoJSON Point or Polygon. For a moving asset, send the latest position, not a track.",
            "properties": {
              "type": { "type": "string", "enum": ["Point", "Polygon"] },
              "coordinates": {}
            }
          }
        }
      },
      "RecipientInput": {
        "type": "object",
        "required": ["name", "channel", "address"],
        "properties": {
          "name": { "type": "string" },
          "channel": {
            "type": "string",
            "enum": ["in_app", "email", "sms", "whatsapp", "telegram", "webhook"]
          },
          "address": {
            "type": "string",
            "description": "Destination on that channel."
          },
          "language": {
            "type": "string",
            "description": "Language for labels and the delivery wrapper. Official warning text is included in a language the issuing agency publishes. Wybox does not machine-translate safety text."
          }
        }
      },
      "SubscriptionInput": {
        "type": "object",
        "required": ["asset_id", "recipient_id"],
        "properties": {
          "asset_id": { "type": "string" },
          "recipient_id": { "type": "string" }
        }
      },
      "Alert": {
        "type": "object",
        "description": "An official warning matched to the tenant's assets. Text fields are the issuing agency's own words. Values in examples are example data.",
        "properties": {
          "id": { "type": "string" },
          "source": { "type": "string" },
          "event": { "type": "string" },
          "headline": { "type": "string" },
          "description": { "type": "string" },
          "instruction": { "type": "string" },
          "affected_asset_ids": {
            "type": "array",
            "items": { "type": "string" }
          }
        },
        "example": {
          "id": "alt_example",
          "source": "Example Agency",
          "event": "Flood Warning",
          "headline": "Example data: Flood Warning",
          "description": "Example data. Not an official bulletin.",
          "instruction": "Example data. Not an official bulletin.",
          "affected_asset_ids": ["ast_example_18", "ast_example_42", "ast_example_7"]
        }
      },
      "AlertList": {
        "type": "object",
        "properties": {
          "data": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Alert" }
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "monitored_assets": {
            "type": "integer",
            "description": "Monitored assets in the current month."
          },
          "messages": {
            "type": "integer",
            "description": "Messages sent in the current month."
          }
        }
      }
    }
  }
}
