openapi: 3.1.0
info:
  title: Beamdesk Public API
  version: 1.0.0
  description: Public API for Beamdesk tickets, contacts, knowledge, audit logs, and webhooks.
servers:
  - url: https://beamdesk.preview.softblaze.net
    description: Preview
  - url: https://app.beamdesk.com
    description: Production
tags:
  - name: Tickets
  - name: Contacts
  - name: Knowledge
  - name: Audit
  - name: Webhooks
paths:
  /api/audit-log:
    get:
      summary: Query audit log (offset or cursor) + optional facets
      tags:
        - Audit
      x-rate-limit: 60 requests per minute
    post:
      summary: Record a settings change audit event
      tags:
        - Audit
  /api/contacts:
    get:
      summary: List contacts
      tags:
        - Contacts
      x-required-scope: read:contacts
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      parameters:
        - $ref: '#/components/parameters/Limit'
        - name: search
          in: query
          schema:
            type: string
        - name: list
          in: query
          schema:
            type: string
      responses:
        '200':
          description: Contact list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContactListResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
    post:
      summary: Create or update a contact
      tags:
        - Contacts
      x-required-scope: write:contacts
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertContactRequest'
      responses:
        '200':
          description: Upserted contact
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContactResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
  /api/knowledge/articles:
    get:
      summary: List knowledge articles
      tags:
        - Knowledge
      x-required-scope: read:knowledge
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      parameters:
        - $ref: '#/components/parameters/Limit'
        - name: search
          in: query
          schema:
            type: string
        - name: status
          in: query
          schema:
            type: string
            enum:
              - draft
              - published
              - archived
      responses:
        '200':
          description: Knowledge articles
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ArticleListResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
  /api/knowledge/ingest:
    post:
      summary: Ingest knowledge content
      tags:
        - Knowledge
      x-required-scope: write:knowledge
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/IngestKnowledgeRequest'
      responses:
        '200':
          description: Ingestion result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IngestKnowledgeResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
  /api/tickets/{id}/close:
    post:
      summary: Close a ticket
      tags:
        - Tickets
      x-required-scope: write:tickets
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      parameters:
        - $ref: '#/components/parameters/TicketId'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CloseTicketRequest'
      responses:
        '200':
          description: Ticket closed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /api/tickets/{id}/reply:
    post:
      summary: Send a ticket reply
      tags:
        - Tickets
      x-required-scope: write:tickets
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      parameters:
        - $ref: '#/components/parameters/TicketId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TicketReplyRequest'
      responses:
        '200':
          description: Reply accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /api/tickets/{id}:
    get:
      summary: Get a ticket
      description: Returns one ticket from the authenticated tenant.
      tags:
        - Tickets
      x-required-scope: read:tickets
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      parameters:
        - $ref: '#/components/parameters/TicketId'
      responses:
        '200':
          description: Ticket detail
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TicketResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /api/tickets/{id}/snooze:
    post:
      summary: Snooze a ticket
      tags:
        - Tickets
      x-required-scope: write:tickets
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      parameters:
        - $ref: '#/components/parameters/TicketId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SnoozeTicketRequest'
      responses:
        '200':
          description: Ticket snoozed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      summary: Unsnooze a ticket
      tags:
        - Tickets
      x-required-scope: write:tickets
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      parameters:
        - $ref: '#/components/parameters/TicketId'
      responses:
        '200':
          description: Ticket unsnoozed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuccessResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /api/v1/accounts:
    get:
      summary: Get workspace account
      tags:
        - Accounts
      x-required-scope: manage:workspace
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      responses:
        '200':
          description: Workspace account details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Account'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
    put:
      summary: Update workspace account
      tags:
        - Accounts
      x-required-scope: manage:workspace
      x-rate-limit: 30 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  maxLength: 255
                default_language:
                  type: string
                default_timezone:
                  type: string
                config:
                  type: object
      responses:
        '200':
          description: Workspace updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Account'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
  /api/v1/contacts:
    get:
      summary: List contacts
      tags:
        - Contacts
      x-required-scope: read:contacts
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      parameters:
        - name: search
          in: query
          schema:
            type: string
        - name: email
          in: query
          schema:
            type: string
            format: email
        - name: limit
          in: query
          schema:
            type: integer
            default: 50
        - name: offset
          in: query
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Contact list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContactListResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
    post:
      summary: Create a contact
      tags:
        - Contacts
      x-required-scope: write:contacts
      x-rate-limit: 30 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                  format: email
                name:
                  type: string
                  maxLength: 255
                phone:
                  type: string
                company:
                  type: string
                custom_fields:
                  type: object
                  additionalProperties: true
              required:
                - email
      responses:
        '201':
          description: Contact created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Contact'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          description: Contact already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/conversations:
    get:
      summary: List conversations
      tags:
        - Conversations
      description: Returns paginated list of conversations (ticket_queue records) for the authenticated workspace.
      x-required-scope: read:conversations
      x-rate-limit: 100 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
        - name: offset
          in: query
          schema:
            type: integer
            minimum: 0
            default: 0
        - name: status
          in: query
          schema:
            type: string
            enum:
              - new
              - open
              - pending
              - resolved
              - escalated
        - name: search
          in: query
          schema:
            type: string
      responses:
        '200':
          description: Paginated conversation list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ConversationListResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
    post:
      summary: Create a conversation
      tags:
        - Conversations
      description: Create a new conversation in the workspace.
      x-required-scope: write:conversations
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                subject:
                  type: string
                  maxLength: 500
                message:
                  type: string
                  maxLength: 50000
                priority:
                  type: string
                  enum:
                    - low
                    - normal
                    - high
                    - urgent
                  default: normal
                channel:
                  type: string
                  enum:
                    - email
                    - chat
                    - voice
                    - api
                customer_email:
                  type: string
                  format: email
                customer_name:
                  type: string
              required:
                - subject
                - message
      responses:
        '201':
          description: Conversation created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Conversation'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/RateLimited'
  /api/v1/messages:
    get:
      summary: List messages in a conversation
      tags:
        - Messages
      x-required-scope: read:messages
      x-rate-limit: 120 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      parameters:
        - name: ticket_id
          in: query
          required: true
          schema:
            type: string
            format: uuid
        - name: limit
          in: query
          schema:
            type: integer
            default: 50
        - name: offset
          in: query
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Message list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MessageListResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
    post:
      summary: Send a message to a conversation
      tags:
        - Messages
      x-required-scope: write:messages
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                ticket_id:
                  type: string
                  format: uuid
                body:
                  type: string
                  maxLength: 50000
                internal_note:
                  type: boolean
                  default: false
              required:
                - ticket_id
                - body
      responses:
        '201':
          description: Message sent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: Conversation not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
  /api/v1/runs:
    get:
      summary: List AI runs
      tags:
        - Runs
      x-required-scope: read:runs
      x-rate-limit: 100 requests per minute
      security:
        - apiKey: []
        - bearerAuth: []
      parameters:
        - name: ticket_id
          in: query
          schema:
            type: string
            format: uuid
        - name: status
          in: query
          schema:
            type: string
            enum:
              - pending
              - running
              - completed
              - failed
        - name: limit
          in: query
          schema:
            type: integer
            default: 20
        - name: offset
          in: query
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Run list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RunListResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
  /api/webhooks/{id}/test:
    post:
      summary: Test webhook delivery
      tags:
        - Webhooks
      x-required-scope: write:webhooks
      x-rate-limit: 60 requests per minute
      security:
        - apiKey: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TestWebhookRequest'
      responses:
        '200':
          description: Delivery attempt result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TestWebhookResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: X-API-Key
  parameters:
    Page:
      name: page
      in: query
      schema:
        type: integer
        minimum: 1
        default: 1
    Limit:
      name: limit
      in: query
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 50
    TicketId:
      name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    TicketStatus:
      name: status
      in: query
      schema:
        type: string
        enum:
          - pending
          - sent
          - closed
          - rejected
          - snoozed
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: Missing required scope
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  schemas:
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: string
    SuccessResponse:
      type: object
      required:
        - success
      properties:
        success:
          type: boolean
        id:
          type: string
    Ticket:
      type: object
      additionalProperties: true
      properties:
        id:
          type: string
          format: uuid
        ticket_code:
          type:
            - string
            - 'null'
        subject:
          type: string
        customer_email:
          type:
            - string
            - 'null'
          format: email
        customer_name:
          type:
            - string
            - 'null'
        status:
          type: string
        priority:
          type:
            - string
            - 'null'
          enum:
            - low
            - normal
            - high
            - urgent
            - null
        created_at:
          type: string
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
    CreateTicketRequest:
      type: object
      required:
        - customer_email
        - subject
        - body
      properties:
        customer_email:
          type: string
          format: email
        customer_name:
          type: string
        subject:
          type: string
        body:
          type: string
        priority:
          type: string
          enum:
            - low
            - normal
            - high
            - urgent
          default: normal
    CreateTicketResponse:
      type: object
      required:
        - success
        - ticket_id
        - ticket_code
      properties:
        success:
          type: boolean
        ticket_id:
          type: string
        ticket_code:
          type: string
    TicketListResponse:
      type: object
      required:
        - success
        - tickets
        - pagination
      properties:
        success:
          type: boolean
        tickets:
          type: array
          items:
            $ref: '#/components/schemas/Ticket'
        pagination:
          $ref: '#/components/schemas/Pagination'
    TicketResponse:
      type: object
      required:
        - success
        - ticket
      properties:
        success:
          type: boolean
        ticket:
          $ref: '#/components/schemas/Ticket'
    TicketReplyRequest:
      type: object
      required:
        - body
      properties:
        body:
          type: string
        public:
          type: boolean
          default: true
    SnoozeTicketRequest:
      type: object
      required:
        - snoozed_until
      properties:
        snoozed_until:
          type: string
          format: date-time
    CloseTicketRequest:
      type: object
      properties:
        reason:
          type: string
    Contact:
      type: object
      additionalProperties: true
      properties:
        id:
          type: string
          format: uuid
        email:
          type: string
          format: email
        firstname:
          type:
            - string
            - 'null'
        lastname:
          type:
            - string
            - 'null'
        company:
          type:
            - string
            - 'null'
        phone:
          type:
            - string
            - 'null'
    UpsertContactRequest:
      type: object
      required:
        - email
      properties:
        email:
          type: string
          format: email
        name:
          type: string
        firstname:
          type: string
        lastname:
          type: string
        company:
          type: string
        phone:
          type: string
        metadata:
          type: object
          additionalProperties: true
    ContactListResponse:
      type: object
      properties:
        success:
          type: boolean
        contacts:
          type: array
          items:
            $ref: '#/components/schemas/Contact'
        total:
          type: integer
    ContactResponse:
      type: object
      properties:
        success:
          type: boolean
        contact:
          $ref: '#/components/schemas/Contact'
    Article:
      type: object
      additionalProperties: true
      properties:
        id:
          type: string
          format: uuid
        title:
          type: string
        slug:
          type: string
        content:
          type: string
        status:
          type: string
        published_at:
          type:
            - string
            - 'null'
          format: date-time
    ArticleListResponse:
      type: object
      properties:
        success:
          type: boolean
        articles:
          type: array
          items:
            $ref: '#/components/schemas/Article'
    IngestKnowledgeRequest:
      type: object
      required:
        - title
        - content
      properties:
        title:
          type: string
        content:
          type: string
        excerpt:
          type: string
        tags:
          type: array
          items:
            type: string
        status:
          type: string
          enum:
            - draft
            - published
          default: draft
    IngestKnowledgeResponse:
      type: object
      properties:
        success:
          type: boolean
        article:
          $ref: '#/components/schemas/Article'
    AuditLogResponse:
      type: object
      properties:
        success:
          type: boolean
        entries:
          type: array
          items:
            type: object
            additionalProperties: true
        total:
          type: integer
        page:
          type: integer
        limit:
          type: integer
        totalPages:
          type: integer
    TestWebhookRequest:
      type: object
      properties:
        event:
          type: string
          default: ticket.created
        payload:
          type: object
          additionalProperties: true
    TestWebhookResponse:
      type: object
      properties:
        success:
          type: boolean
        delivered:
          type: boolean
    Pagination:
      type: object
      properties:
        page:
          type: integer
        limit:
          type: integer
        total:
          type: integer
        totalPages:
          type: integer

