{
  "openapi": "3.1.0",
  "info": {
    "title": "AutoTill Developer API",
    "version": "1.0.0",
    "summary": "Put an AI sales agent on any website in minutes.",
    "description": "AutoTill is an AI sales agent that completes purchases and captures leads in a conversation. Connect a website with one call, and AutoTill reads it straight away — pages, services, contact details, delivery and returns — so the agent can answer well from the first visitor. Push your catalogue for exact, live data, run the conversation headlessly, and read conversations, leads, support requests and orders back out.",
    "contact": { "name": "AutoTill", "url": "https://autotill.com/api-documentation", "email": "info@autotill.com" }
  },
  "servers": [{ "url": "https://fslswfrutcitukxzkhib.supabase.co/functions/v1/api-v1/v1" }],
  "security": [{ "secretKey": [] }],
  "components": {
    "securitySchemes": {
      "secretKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Your AutoTill secret key, created in the dashboard under Account → API keys. Starts `at_sk_`. Server-side only."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" },
              "docs": { "type": "string" }
            }
          }
        }
      },
      "Product": {
        "type": "object",
        "required": ["id", "name"],
        "properties": {
          "id": { "type": "string", "description": "Your own product id. Upserts are keyed on this." },
          "name": { "type": "string" },
          "description": { "type": "string" },
          "short_description": { "type": "string" },
          "price": { "type": "number" },
          "sale_price": { "type": "number" },
          "currency": { "type": "string", "example": "GBP" },
          "sku": { "type": "string" },
          "stock_status": { "type": "string", "enum": ["instock", "outofstock", "onbackorder"] },
          "stock_quantity": { "type": "integer" },
          "image_url": { "type": "string" },
          "images": { "type": "array", "items": { "type": "string" } },
          "categories": { "type": "array", "items": { "type": "string" } },
          "url": { "type": "string" },
          "status": { "type": "string", "enum": ["publish", "draft"] }
        }
      },
      "Service": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": { "type": "string" },
          "summary": { "type": "string" },
          "details": { "type": "string" },
          "price_signal": { "type": "string", "example": "From £45" },
          "url": { "type": "string" },
          "enabled": { "type": "boolean" }
        }
      }
    }
  },
  "paths": {
    "/me": {
      "get": {
        "summary": "What this key can do",
        "description": "Returns the key's permissions and the websites it covers, with their business model, product count and reading status.",
        "responses": { "200": { "description": "Key and website summary" }, "401": { "description": "Invalid key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } } }
      }
    },
    "/connect": {
      "post": {
        "summary": "Connect a website",
        "description": "Registers the website against your account and immediately starts reading it. Returns the website id and the embed snippet to paste on the site.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["website_url"],
                "properties": {
                  "website_url": { "type": "string", "example": "https://example.com" },
                  "name": { "type": "string" },
                  "platform": { "type": "string", "enum": ["custom", "shopify", "woocommerce"] },
                  "currency": { "type": "string", "example": "GBP" }
                }
              }
            }
          }
        },
        "responses": { "201": { "description": "Connected" }, "409": { "description": "Already connected to another account" } }
      }
    },
    "/products": {
      "get": {
        "summary": "List products AutoTill holds",
        "parameters": [{ "name": "limit", "in": "query", "schema": { "type": "integer", "default": 50, "maximum": 200 } }],
        "responses": { "200": { "description": "Products" } }
      },
      "post": {
        "summary": "Upsert products",
        "description": "Idempotent upsert keyed on your own product id. Up to 500 a request. Safe to run on a schedule.",
        "requestBody": {
          "required": true,
          "content": { "application/json": { "schema": { "type": "object", "properties": { "website_id": { "type": "string" }, "products": { "type": "array", "items": { "$ref": "#/components/schemas/Product" } } } } } }
        },
        "responses": { "200": { "description": "Saved" } }
      },
      "delete": {
        "summary": "Remove products",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "ids": { "type": "array", "items": { "type": "string" } } } } } } },
        "responses": { "200": { "description": "Removed" } }
      }
    },
    "/services": {
      "get": { "summary": "List services", "responses": { "200": { "description": "Services" } } },
      "post": {
        "summary": "Upsert services",
        "description": "For service businesses. Anything edited by hand in the AutoTill dashboard is left untouched.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "services": { "type": "array", "items": { "$ref": "#/components/schemas/Service" } } } } } } },
        "responses": { "200": { "description": "Saved" } }
      }
    },
    "/pages": {
      "get": { "summary": "List page content the agent knows", "responses": { "200": { "description": "Pages" } } },
      "post": {
        "summary": "Upsert page content",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "pages": { "type": "array", "items": { "type": "object", "required": ["title", "content"], "properties": { "title": { "type": "string" }, "slug": { "type": "string" }, "content": { "type": "string" }, "tags": { "type": "array", "items": { "type": "string" } } } } } } } } } },
        "responses": { "200": { "description": "Saved" } }
      }
    },
    "/policies": {
      "get": { "summary": "Read delivery options and returns rules", "responses": { "200": { "description": "Policies" } } },
      "post": {
        "summary": "Upsert delivery options and returns rules",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "delivery": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "cost_cents": { "type": "integer" }, "free_over_cents": { "type": "integer" }, "dispatch_days_min": { "type": "integer" }, "dispatch_days_max": { "type": "integer" }, "areas": { "type": "string" }, "notes": { "type": "string" } } } }, "returns": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "window_days": { "type": "integer" }, "who_pays_return_postage": { "type": "string" }, "refund_method": { "type": "string" }, "notes": { "type": "string" } } } } } } } } },
        "responses": { "200": { "description": "Saved" } }
      }
    },
    "/orders": {
      "get": { "summary": "Read attributed orders", "responses": { "200": { "description": "Orders" } } },
      "post": {
        "summary": "Push orders for attribution",
        "description": "Send `session_id` when the order came from an agent conversation, so AutoTill can attribute the revenue.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "orders": { "type": "array", "items": { "type": "object", "required": ["id"], "properties": { "id": { "type": "string" }, "order_number": { "type": "string" }, "status": { "type": "string" }, "total_cents": { "type": "integer" }, "currency": { "type": "string" }, "customer_name": { "type": "string" }, "customer_email": { "type": "string" }, "session_id": { "type": "string" }, "ordered_at": { "type": "string", "format": "date-time" } } } } } } } } },
        "responses": { "200": { "description": "Saved" } }
      }
    },
    "/chat": {
      "post": {
        "summary": "One conversation turn (headless)",
        "description": "Keep the same `session_id` for the whole conversation. Returns the agent's reply, any products it is recommending, the basket and the checkout handoff.",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "required": ["session_id", "message"], "properties": { "website_id": { "type": "string" }, "session_id": { "type": "string" }, "message": { "type": "string" } } } } } },
        "responses": { "200": { "description": "Agent reply" } }
      }
    },
    "/basket": {
      "post": {
        "summary": "Change the basket or get the checkout link",
        "requestBody": { "required": true, "content": { "application/json": { "schema": { "type": "object", "properties": { "action": { "type": "string", "enum": ["add", "update", "remove", "checkout"] }, "session_id": { "type": "string" }, "product_id": { "type": "string" }, "quantity": { "type": "integer" } } } } } },
        "responses": { "200": { "description": "Basket" } }
      }
    },
    "/conversations": { "get": { "summary": "List conversations", "responses": { "200": { "description": "Conversations" } } } },
    "/conversation": {
      "get": {
        "summary": "One conversation with its messages",
        "parameters": [{ "name": "id", "in": "query", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Transcript" } }
      }
    },
    "/leads": { "get": { "summary": "Leads captured by the agent", "responses": { "200": { "description": "Leads" } } } },
    "/support": { "get": { "summary": "Support requests captured by the agent", "responses": { "200": { "description": "Support requests" } } } },
    "/stats": {
      "get": {
        "summary": "Headline numbers",
        "parameters": [{ "name": "days", "in": "query", "schema": { "type": "integer", "default": 30, "maximum": 365 } }],
        "responses": { "200": { "description": "Stats" } }
      }
    },
    "/resync": { "post": { "summary": "Re-read the website", "responses": { "202": { "description": "Started" } } } },
    "/widget-config": {
      "get": {
        "summary": "Resolve a publishable key (public)",
        "security": [],
        "parameters": [{ "name": "key", "in": "query", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Website id and live state" } }
      }
    }
  }
}
