{
  "components": {
    "schemas": {
      "Error": {
        "properties": {
          "error": {
            "properties": {
              "code": {
                "enum": [
                  "invalid_key",
                  "scope_missing",
                  "origin_mismatch",
                  "quota_exceeded",
                  "rate_limited",
                  "validation_error",
                  "not_found",
                  "permission_denied"
                ],
                "type": "string"
              },
              "details": {
                "type": "object"
              },
              "message": {
                "description": "da/en/uk by Accept-Language",
                "type": "string"
              }
            },
            "required": [
              "code",
              "message",
              "details"
            ],
            "type": "object"
          }
        },
        "required": [
          "error"
        ],
        "type": "object"
      },
      "PublicLeadCreate": {
        "description": "Customer-facing payload — same shape as widget's LeadCreate but\nwithout the consent-text gating (system-to-system).",
        "properties": {
          "company": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Company"
          },
          "consent": {
            "default": true,
            "title": "Consent",
            "type": "boolean"
          },
          "consent_text": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Consent Text"
          },
          "custom_fields": {
            "anyOf": [
              {
                "additionalProperties": true,
                "type": "object"
              },
              {
                "type": "null"
              }
            ],
            "title": "Custom Fields"
          },
          "email": {
            "anyOf": [
              {
                "format": "email",
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Email"
          },
          "first_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "First Name"
          },
          "last_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Last Name"
          },
          "message": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Message"
          },
          "phone": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Phone"
          },
          "project_id": {
            "title": "Project Id",
            "type": "integer"
          },
          "source": {
            "default": "api",
            "title": "Source",
            "type": "string"
          },
          "source_url": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Source Url"
          },
          "utm": {
            "anyOf": [
              {
                "additionalProperties": true,
                "type": "object"
              },
              {
                "type": "null"
              }
            ],
            "title": "Utm"
          }
        },
        "required": [
          "project_id"
        ],
        "title": "PublicLeadCreate",
        "type": "object"
      },
      "PublicLeadOut": {
        "properties": {
          "company": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Company"
          },
          "consent_given": {
            "title": "Consent Given",
            "type": "boolean"
          },
          "created_at": {
            "format": "date-time",
            "title": "Created At",
            "type": "string"
          },
          "email": {
            "anyOf": [
              {
                "format": "email",
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Email"
          },
          "first_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "First Name"
          },
          "id": {
            "title": "Id",
            "type": "integer"
          },
          "last_name": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Last Name"
          },
          "phone": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ],
            "title": "Phone"
          },
          "project_id": {
            "title": "Project Id",
            "type": "integer"
          },
          "source": {
            "title": "Source",
            "type": "string"
          },
          "status": {
            "title": "Status",
            "type": "string"
          }
        },
        "required": [
          "id",
          "project_id",
          "first_name",
          "last_name",
          "email",
          "phone",
          "company",
          "status",
          "source",
          "consent_given",
          "created_at"
        ],
        "title": "PublicLeadOut",
        "type": "object"
      }
    },
    "securitySchemes": {
      "apiKey": {
        "description": "cbot_pk_… created on the WordPress page",
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "info": {
    "description": "Server-to-server only, with the site owner's API key (`Authorization: Bearer cbot_pk_…`). cbot.dk never calls a site except the two signed webhooks below. Guide: https://cbot.dk/en/docs/wordpress",
    "title": "cbot.dk — API for the Lynbro WordPress plugins",
    "version": "1.0.0"
  },
  "openapi": "3.1.0",
  "paths": {
    "/api/v1/external/v1/leads": {
      "get": {
        "operationId": "list_leads_api_v1_external_v1_leads_get",
        "parameters": [
          {
            "description": "Required unless the key is limited to one project",
            "in": "query",
            "name": "project_id",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Required unless the key is limited to one project",
              "title": "Project Id"
            }
          },
          {
            "in": "query",
            "name": "limit",
            "required": false,
            "schema": {
              "default": 50,
              "maximum": 200,
              "minimum": 1,
              "title": "Limit",
              "type": "integer"
            }
          },
          {
            "description": "Keyset pagination: id less than this",
            "in": "query",
            "name": "before",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "integer"
                },
                {
                  "type": "null"
                }
              ],
              "description": "Keyset pagination: id less than this",
              "title": "Before"
            }
          },
          {
            "in": "header",
            "name": "authorization",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Authorization"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "items": {
                    "$ref": "#/components/schemas/PublicLeadOut"
                  },
                  "title": "Response List Leads Api V1 External V1 Leads Get",
                  "type": "array"
                }
              }
            },
            "description": "Successful Response"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "invalid_key"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "scope_missing (details.scope) / permission_denied"
          },
          "422": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "validation_error (details.fields)"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "rate_limited; see Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "summary": "List Leads",
        "tags": [
          "external-api"
        ]
      },
      "post": {
        "operationId": "create_lead_api_v1_external_v1_leads_post",
        "parameters": [
          {
            "in": "header",
            "name": "authorization",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Authorization"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublicLeadCreate"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicLeadOut"
                }
              }
            },
            "description": "Successful Response"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "invalid_key"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "scope_missing (details.scope) / permission_denied"
          },
          "422": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "validation_error (details.fields)"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "rate_limited; see Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "summary": "Create Lead",
        "tags": [
          "external-api"
        ]
      }
    },
    "/api/v1/external/v1/leads/{lead_id}": {
      "get": {
        "operationId": "get_lead_api_v1_external_v1_leads__lead_id__get",
        "parameters": [
          {
            "in": "path",
            "name": "lead_id",
            "required": true,
            "schema": {
              "title": "Lead Id",
              "type": "integer"
            }
          },
          {
            "in": "header",
            "name": "authorization",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Authorization"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicLeadOut"
                }
              }
            },
            "description": "Successful Response"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "invalid_key"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "scope_missing (details.scope) / permission_denied"
          },
          "422": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "validation_error (details.fields)"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "rate_limited; see Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "summary": "Get Lead",
        "tags": [
          "external-api"
        ]
      }
    },
    "/api/v1/external/v1/me": {
      "get": {
        "description": "Who this key is — what a plugin's \"Test connection\" button shows.\n\nShape of the shared LynBro contract (C3): `account_name, plan,\nquota{used,limit,resets_at}, scopes[], origins[], key{id,last4}, sandbox`.\nThe original fields (account_id … rate_limit_per_minute) stay for clients\nthat already read them.\n\n`origins` are the sites the key's project accepts the chat widget on (the\nwidgets' allow-lists) — calls with the key are server-to-server, so they\nare informational: they tell the owner which sites this key is for.",
        "operationId": "whoami_api_v1_external_v1_me_get",
        "parameters": [
          {
            "in": "header",
            "name": "authorization",
            "required": false,
            "schema": {
              "anyOf": [
                {
                  "type": "string"
                },
                {
                  "type": "null"
                }
              ],
              "title": "Authorization"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "additionalProperties": true,
                  "title": "Response Whoami Api V1 External V1 Me Get",
                  "type": "object"
                }
              }
            },
            "description": "Successful Response"
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "invalid_key"
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "scope_missing (details.scope) / permission_denied"
          },
          "422": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "validation_error (details.fields)"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "rate_limited; see Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "summary": "Whoami",
        "tags": [
          "external-api"
        ]
      }
    }
  },
  "servers": [
    {
      "url": "https://cbot.dk"
    }
  ],
  "webhooks": {
    "leadEvent": {
      "post": {
        "description": "Signed with the webhook secret (Lynbro Signature v1; X-Cbot-Signature sha256=hmac(secret, ts + '.' + body) is sent as well). Retried with backoff 1m/5m/30m/2h/12h; the event id stays the same on retries. Re-read the lead with GET /api/v1/external/v1/leads/{lead_id} before acting on it.",
        "parameters": [
          {
            "description": "Unix seconds. Refuse outside +/-300 s.",
            "in": "header",
            "name": "X-Lynbro-Timestamp",
            "required": true,
            "schema": {
              "pattern": "^[0-9]+$",
              "type": "string"
            }
          },
          {
            "description": "Keep for the window and refuse a repeat (replay cache).",
            "in": "header",
            "name": "X-Lynbro-Event-Id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "v1=hex(HMAC-SHA256(secret, ts + \".\" + \"POST \" + path + \".\" + raw_body)); path = the request path without query string.",
            "in": "header",
            "name": "X-Lynbro-Signature",
            "required": true,
            "schema": {
              "pattern": "^v1=[0-9a-f]{64}(,v1=[0-9a-f]{64})*$",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "X-Lynbro-Event",
            "required": true,
            "schema": {
              "enum": [
                "lead.created",
                "lead.updated"
              ],
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "account_id": {
                    "type": "integer"
                  },
                  "data": {
                    "properties": {
                      "lead_id": {
                        "type": "integer"
                      },
                      "status": {
                        "type": "string"
                      }
                    },
                    "type": "object"
                  },
                  "id": {
                    "type": "string"
                  },
                  "project_id": {
                    "type": [
                      "integer",
                      "null"
                    ]
                  },
                  "ts": {
                    "type": "string"
                  },
                  "type": {
                    "type": "string"
                  }
                },
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "2XX": {
            "description": "Delivered"
          }
        },
        "summary": "lead.created / lead.updated to {site}/wp-json/lynbro-chat/v1/webhook"
      }
    },
    "shopTool": {
      "post": {
        "description": "Signed with the bridge secret. Lynbro Signature v1 for bridges set to `v1`; the 0.1.0 scheme (X-Lynbro-Site/-Nonce, hex signature over site\\nts\\nnonce\\nsha256(body)) for `legacy` bridges. X-Lynbro-Site is sent in both.",
        "parameters": [
          {
            "description": "Unix seconds. Refuse outside +/-300 s.",
            "in": "header",
            "name": "X-Lynbro-Timestamp",
            "required": true,
            "schema": {
              "pattern": "^[0-9]+$",
              "type": "string"
            }
          },
          {
            "description": "Keep for the window and refuse a repeat (replay cache).",
            "in": "header",
            "name": "X-Lynbro-Event-Id",
            "required": true,
            "schema": {
              "format": "uuid",
              "type": "string"
            }
          },
          {
            "description": "v1=hex(HMAC-SHA256(secret, ts + \".\" + \"POST \" + path + \".\" + raw_body)); path = the request path without query string.",
            "in": "header",
            "name": "X-Lynbro-Signature",
            "required": true,
            "schema": {
              "pattern": "^v1=[0-9a-f]{64}(,v1=[0-9a-f]{64})*$",
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "X-Lynbro-Site",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "properties": {
                  "args": {
                    "type": "object"
                  },
                  "conversation": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "identity": {
                    "description": "lbi1 identity token the site issued; present only when the visitor has one",
                    "type": "string"
                  },
                  "tool": {
                    "type": "string"
                  },
                  "visitor": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "tool",
                  "args",
                  "visitor",
                  "conversation"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "{\"ok\": true, \"data\": {…}, \"scope\": \"…\"} or {\"ok\": false, \"error\": \"…\", \"message\": \"…\"}"
          }
        },
        "summary": "Tool call cbot.dk makes to {site}/wp-json/lynbro-chat/v1/tool"
      }
    }
  }
}
