{
  "openapi": "3.1.0",
  "info": {
    "title": "KasaDESK Public API",
    "version": "1.0.0",
    "description": "Bearer-token API for integrations. Each API key is scoped to one or more workspaces and to `read` and/or `write`. Resources outside the key’s workspaces return 404. Internal notes are never exposed. Staff session cookies are not accepted."
  },
  "servers": [
    {
      "url": "https://support.example.com/api/v1/public-api"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/me": {
      "get": {
        "summary": "Describe the calling API key",
        "operationId": "getMe",
        "responses": {
          "200": {
            "description": "Key details",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyInfo"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired or revoked API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/conversations": {
      "get": {
        "summary": "List conversations in the key’s workspaces",
        "operationId": "listConversations",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from a previous page"
          },
          {
            "name": "workspaceId",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Narrow to one of the key’s workspaces. Other ids return an empty list."
          },
          {
            "name": "lifecycle",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "pending",
                "resolved"
              ]
            }
          },
          {
            "name": "reference",
            "in": "query",
            "schema": {
              "type": "string",
              "example": "T-00001"
            },
            "description": "Exact conversation reference, case-insensitive and with an optional # prefix"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of conversations, newest activity first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "nextCursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Conversation"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired or revoked API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/conversations/{id}": {
      "get": {
        "summary": "Get one conversation",
        "operationId": "getConversation",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The conversation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/Conversation"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired or revoked API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found or outside the key’s workspaces",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/conversations/{id}/messages": {
      "get": {
        "summary": "List public messages (internal notes are never included)",
        "operationId": "listMessages",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 500,
              "default": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Messages, oldest first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Message"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired or revoked API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found or outside the key’s workspaces",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/conversations/{id}/replies": {
      "post": {
        "summary": "Send a public reply through the conversation’s origin channel",
        "operationId": "createReply",
        "x-required-scope": "write",
        "description": "The reply is sent through the conversation’s own channel (for email, via the outbox with retries). Channels without an outbound adapter return 409 `channel_outbound_unavailable`. Repeating an idempotency key returns the original message.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "minLength": 8,
              "maxLength": 100
            },
            "description": "Alternative to the body field"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReplyInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Duplicate idempotency key; original message returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReplyResult"
                }
              }
            }
          },
          "201": {
            "description": "Reply accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReplyResult"
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired or revoked API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the write scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found or outside the key’s workspaces",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Channel cannot send replies",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/customers": {
      "get": {
        "summary": "List customers in the key’s workspaces",
        "operationId": "listCustomers",
        "x-required-scope": "read",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 25
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Opaque cursor from a previous page"
          },
          {
            "name": "workspaceId",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Narrow to one of the key’s workspaces. Other ids return an empty list."
          },
          {
            "name": "email",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact, case-insensitive match"
          }
        ],
        "responses": {
          "200": {
            "description": "A page of customers",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "data",
                    "nextCursor"
                  ],
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Customer"
                      }
                    },
                    "nextCursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Missing, invalid, expired or revoked API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Key lacks the read scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "webhooks": {
    "conversation.created": {
      "post": {
        "summary": "conversation.created event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.created"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.reopened": {
      "post": {
        "summary": "conversation.reopened event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.reopened"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.status": {
      "post": {
        "summary": "conversation.status event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.status"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.priority": {
      "post": {
        "summary": "conversation.priority event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.priority"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.assigned": {
      "post": {
        "summary": "conversation.assigned event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.assigned"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.unassigned": {
      "post": {
        "summary": "conversation.unassigned event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.unassigned"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.moved": {
      "post": {
        "summary": "conversation.moved event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.moved"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.escalated": {
      "post": {
        "summary": "conversation.escalated event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.escalated"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.human_takeover": {
      "post": {
        "summary": "conversation.human_takeover event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.human_takeover"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "conversation.ai_resumed": {
      "post": {
        "summary": "conversation.ai_resumed event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "conversation.ai_resumed"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "message.created": {
      "post": {
        "summary": "message.created event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "message.created"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "message.delivery": {
      "post": {
        "summary": "message.delivery event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "message.delivery"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    },
    "webhook.test": {
      "post": {
        "summary": "webhook.test event",
        "description": "Signed with HMAC-SHA256 over `{X-KasaDesk-Timestamp}.{raw body}` using the endpoint signing secret. `X-KasaDesk-Signature` holds `v1=<hex>` (two comma-separated values during a secret rotation grace period; accept either). Reject timestamps older than 5 minutes. Deduplicate on `X-KasaDesk-Event-Id` (stable across retries). Respond 2xx within 10 seconds; other responses are retried with backoff, and the endpoint is disabled after repeated consecutive failures. Redirects are not followed.",
        "parameters": [
          {
            "name": "X-KasaDesk-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd"
            }
          },
          {
            "name": "X-KasaDesk-Timestamp",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "description": "Unix seconds"
            }
          },
          {
            "name": "X-KasaDesk-Event-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-KasaDesk-Event-Type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "const": "webhook.test"
            }
          },
          {
            "name": "X-KasaDesk-Delivery-Id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookTestEvent"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Acknowledged"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key beginning with `kd_live_`, created in Admin > Settings > Developer"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {}
            }
          }
        }
      },
      "ApiKeyInfo": {
        "type": "object",
        "required": [
          "id",
          "name",
          "scopes",
          "workspaceIds"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "read",
                "write"
              ]
            }
          },
          "workspaceIds": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        }
      },
      "Conversation": {
        "type": "object",
        "required": [
          "id",
          "lifecycle",
          "handler",
          "priority",
          "workspace",
          "workgroup",
          "channel",
          "customer",
          "createdAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "reference": {
            "type": "string",
            "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
            "description": "Stable short record reference"
          },
          "subject": {
            "type": [
              "string",
              "null"
            ]
          },
          "lifecycle": {
            "type": "string",
            "enum": [
              "open",
              "pending",
              "resolved"
            ]
          },
          "handler": {
            "type": "string",
            "enum": [
              "ai",
              "human",
              "queued"
            ]
          },
          "priority": {
            "type": "string",
            "enum": [
              "low",
              "normal",
              "high",
              "urgent"
            ]
          },
          "workspace": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "reference": {
                "type": "string",
                "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
                "description": "Stable short record reference"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "workgroup": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "reference": {
                "type": "string",
                "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
                "description": "Stable short record reference"
              },
              "name": {
                "type": "string"
              }
            }
          },
          "channel": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "reference": {
                "type": "string",
                "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
                "description": "Stable short record reference"
              },
              "type": {
                "type": "string"
              },
              "label": {
                "type": "string"
              }
            }
          },
          "customer": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "reference": {
                "type": "string",
                "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
                "description": "Stable short record reference"
              },
              "name": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "email": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "verification": {
                "type": "string",
                "enum": [
                  "guest",
                  "unverified",
                  "verified"
                ]
              }
            }
          },
          "assignee": {
            "oneOf": [
              {
                "type": "null"
              },
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "reference": {
                    "type": "string",
                    "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
                    "description": "Stable short record reference"
                  },
                  "name": {
                    "type": "string"
                  }
                }
              }
            ]
          },
          "lastMessagePreview": {
            "type": [
              "string",
              "null"
            ]
          },
          "lastMessageAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "slaDueAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "id",
          "conversationId",
          "authorType",
          "body",
          "deliveryStatus",
          "createdAt",
          "attachments"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "reference": {
            "type": "string",
            "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
            "description": "Stable short record reference"
          },
          "conversationId": {
            "type": "string",
            "format": "uuid"
          },
          "conversationReference": {
            "type": "string",
            "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
            "description": "Stable short record reference"
          },
          "authorType": {
            "type": "string",
            "enum": [
              "customer",
              "agent",
              "ai",
              "system"
            ]
          },
          "authorName": {
            "type": [
              "string",
              "null"
            ]
          },
          "body": {
            "type": "string"
          },
          "deliveryStatus": {
            "type": "string",
            "enum": [
              "none",
              "queued",
              "sending",
              "accepted",
              "delivered",
              "read",
              "failed"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "attachments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "filename": {
                  "type": "string"
                },
                "contentType": {
                  "type": "string"
                },
                "size": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "Customer": {
        "type": "object",
        "required": [
          "id",
          "workspaceId",
          "verification",
          "createdAt"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "reference": {
            "type": "string",
            "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
            "description": "Stable short record reference"
          },
          "workspaceId": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceReference": {
            "type": "string",
            "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
            "description": "Stable short record reference"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "phone": {
            "type": [
              "string",
              "null"
            ]
          },
          "verification": {
            "type": "string",
            "enum": [
              "guest",
              "unverified",
              "verified"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ReplyInput": {
        "type": "object",
        "required": [
          "body"
        ],
        "properties": {
          "body": {
            "type": "string",
            "minLength": 1,
            "maxLength": 20000
          },
          "idempotencyKey": {
            "type": "string",
            "minLength": 8,
            "maxLength": 100
          }
        }
      },
      "ReplyResult": {
        "type": "object",
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "type": "object",
            "required": [
              "messageId",
              "duplicate"
            ],
            "properties": {
              "messageId": {
                "type": "string",
                "format": "uuid"
              },
              "duplicate": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "WebhookEvent": {
        "type": "object",
        "required": [
          "id",
          "type",
          "createdAt",
          "workspaceId",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Stable event id (`evt_…`); identical on every retry",
            "examples": [
              "evt_1234"
            ]
          },
          "type": {
            "type": "string",
            "enum": [
              "conversation.created",
              "conversation.reopened",
              "conversation.status",
              "conversation.priority",
              "conversation.assigned",
              "conversation.unassigned",
              "conversation.moved",
              "conversation.escalated",
              "conversation.human_takeover",
              "conversation.ai_resumed",
              "message.created",
              "message.delivery"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "workspaceId": {
            "type": "string",
            "format": "uuid"
          },
          "workspaceReference": {
            "type": "string",
            "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
            "description": "Stable short record reference"
          },
          "data": {
            "type": "object",
            "required": [
              "conversation",
              "actorType",
              "changes"
            ],
            "properties": {
              "conversation": {
                "$ref": "#/components/schemas/Conversation"
              },
              "actorType": {
                "type": "string",
                "description": "customer, agent, ai, api or system"
              },
              "changes": {
                "type": "object",
                "description": "Allow-listed event fields such as from/to, assigneeId, status, reason, messageId",
                "additionalProperties": true
              },
              "message": {
                "description": "message.created: the full public message. message.delivery: id, reference and deliveryStatus.",
                "oneOf": [
                  {
                    "$ref": "#/components/schemas/Message"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "reference": {
                        "type": "string",
                        "pattern": "^[TCWGAHM]-[0-9A-HJKMNP-TV-Z]{5}$",
                        "description": "Stable short record reference"
                      },
                      "deliveryStatus": {
                        "type": "string"
                      }
                    }
                  }
                ]
              }
            }
          }
        }
      },
      "WebhookTestEvent": {
        "type": "object",
        "required": [
          "id",
          "type",
          "createdAt",
          "workspaceId",
          "data"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "type": {
            "const": "webhook.test"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "workspaceId": {
            "type": "string",
            "format": "uuid"
          },
          "data": {
            "type": "object",
            "properties": {
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
