> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appliedai.club/llms.txt
> Use this file to discover all available pages before exploring further.

# Analyze Tickets

> Analyze customer service tickets for quality assessment

### Process Flow

1. Validates the API key and gets account\_id
2. Generates a batch\_id
3. Creates a batch record in database
4. Queues the processing task
5. Returns the batch\_id for tracking

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.example.com/api/cs-qa/v1/analyze \
    -H "Authorization: YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "tickets": [
        {
          "ticket_id": "123",
          "subject": "Need help",
          "description": "Having issues with login",
          "status": "open",
          "priority": "high"
        }
      ]
    }'
  ```

  ```python Python theme={null}
  import requests

  tickets_payload = {
      "tickets": [{
          "ticket_id": "123",
          "subject": "Need help",
          "description": "Having issues with login",
          "status": "open",
          "priority": "high"
      }]
  }

  response = requests.post(
      "https://api.example.com/api/cs-qa/v1/analyze",
      headers={
          "Authorization": "YOUR_API_KEY",
          "Content-Type": "application/json"
      },
      json=tickets_payload
  )
  batch_id = response.json()["batch_id"]
  ```
</RequestExample>


## OpenAPI

````yaml POST /api/cs-qa/v1/analyze
openapi: 3.1.0
info:
  title: Freshdesk Quality Assistant API
  description: API for analyzing customer service ticket quality
  version: 1.0.0
servers: []
security:
  - APIKeyHeader: []
paths:
  /api/cs-qa/v1/analyze:
    post:
      tags:
        - cs-qa
        - CS QA
      summary: Analyze Tickets
      description: >-
        Analyze a batch of customer service tickets


        This endpoint:

        1. Validates the API key and gets account_id

        2. Generates a batch_id

        3. Creates a batch record in database

        4. Queues the processing task

        5. Returns the batch_id for tracking


        The actual processing happens asynchronously and results are stored in
        the database.
      operationId: analyze_tickets_api_cs_qa_v1_analyze_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BatchQARequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchQAResponse'
        '401':
          description: Invalid or missing API key
          content:
            application/json:
              example:
                detail: Invalid API key
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              example:
                detail: Too many requests. Please try again later.
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDetail'
              example:
                detail: Internal server error
      security:
        - APIKeyHeader: []
components:
  schemas:
    BatchQARequest:
      properties:
        schema_id:
          anyOf:
            - type: integer
            - type: 'null'
          title: Schema Id
        tickets:
          items:
            $ref: '#/components/schemas/TicketData'
          type: array
          title: Tickets
      type: object
      required:
        - tickets
      title: BatchQARequest
    BatchQAResponse:
      properties:
        batch_id:
          type: string
          format: uuid
          title: Batch Id
        total_tickets:
          type: integer
          title: Total Tickets
        processed_tickets:
          type: integer
          title: Processed Tickets
        failed_tickets:
          type: integer
          title: Failed Tickets
        status:
          type: string
          title: Status
          default: pending
        results:
          anyOf:
            - items:
                $ref: '#/components/schemas/QAResult'
              type: array
            - type: 'null'
          title: Results
        errors:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Errors
      type: object
      required:
        - batch_id
        - total_tickets
        - processed_tickets
        - failed_tickets
      title: BatchQAResponse
    ValidationError:
      properties:
        detail:
          items:
            type: object
          type: array
          title: Detail
      type: object
      required:
        - detail
      title: ValidationError
      description: Validation error response schema
    ErrorDetail:
      properties:
        detail:
          type: string
          title: Detail
      type: object
      required:
        - detail
      title: ErrorDetail
      description: Standard error response schema
    TicketData:
      properties:
        ticket_id:
          type: string
          title: Ticket Id
        subject:
          type: string
          title: Subject
        description:
          type: string
          title: Description
        conversation:
          anyOf:
            - items:
                $ref: '#/components/schemas/ConversationMessage'
              type: array
            - type: 'null'
          title: Conversation
        custom_fields:
          anyOf:
            - type: object
            - type: 'null'
          title: Custom Fields
        feedback:
          anyOf:
            - $ref: '#/components/schemas/Feedback'
            - type: 'null'
        created_timestamp:
          type: string
          format: date-time
          title: Created Timestamp
        updated_timestamp:
          type: string
          format: date-time
          title: Updated Timestamp
        status:
          type: string
          title: Status
        priority:
          type: string
          title: Priority
      type: object
      required:
        - ticket_id
        - subject
        - description
        - created_timestamp
        - updated_timestamp
        - status
        - priority
      title: TicketData
    QAResult:
      properties:
        ticket_id:
          type: string
          title: Ticket Id
        agent_id:
          type: string
          title: Agent Id
        parameter_name:
          type: string
          title: Parameter Name
        value:
          anyOf:
            - type: string
            - type: integer
            - type: number
            - type: boolean
            - type: 'null'
          title: Value
        reason:
          anyOf:
            - type: string
            - type: 'null'
          title: Reason
      type: object
      required:
        - ticket_id
        - agent_id
        - parameter_name
        - reason
      title: QAResult
    ConversationMessage:
      properties:
        role:
          $ref: '#/components/schemas/MessageRole'
        user_id:
          type: string
          title: User Id
        message_text:
          type: string
          title: Message Text
        timestamp:
          type: string
          format: date-time
          title: Timestamp
      type: object
      required:
        - role
        - user_id
        - message_text
        - timestamp
      title: ConversationMessage
    Feedback:
      properties:
        csat_rating:
          anyOf:
            - type: number
            - type: 'null'
          title: Csat Rating
        customer_comments:
          anyOf:
            - type: string
            - type: 'null'
          title: Customer Comments
      type: object
      title: Feedback
    MessageRole:
      type: string
      enum:
        - customer
        - agent
      title: MessageRole
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      in: header
      name: Authorization
      description: Enter your API key

````