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

# Create AI Brand Coding Job

> Analyze survey responses in the context of specified brands and code them into hierarchical categories



## OpenAPI

````yaml POST /api/v1/brand-coding
openapi: 3.0.0
info:
  title: Followup Generation API
  version: 1.0.0
  description: API for generating followup questions based on survey responses
  contact:
    name: API Support
    email: justin@getaftercare.com
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: https://surveys.getaftercare.com
    description: Production server
  - url: https://staging.aftercareai.com
    description: Staging server
security:
  - ApiKeyAuth: []
tags:
  - name: Followups
    description: Operations related to followup question generation
  - name: Data Quality
    description: Operations related to response data quality evaluation
  - name: Coding
    description: Operations related to coding survey responses
paths:
  /api/v1/brand-coding:
    post:
      tags:
        - Coding
      summary: Create a brand coding job
      description: >-
        Analyze survey responses in the context of specified brands and code
        them into hierarchical categories
      operationId: createBrandCodingJob
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BatchCodingRequest'
            example:
              surveyIdentifier: CSAT-2024-Q1
              surveyName: Customer Satisfaction
              surveyDescription: Tracking customer satisfaction and loyalty for the XYZ Company
              surveyResponses:
                - questionIdentifier: Q1
                  question: What did you like about our service?
                  brandContext:
                    industryDescription: E-commerce retail
                    brands:
                      - name: Acme Store
                        variations:
                          - Acme
                          - AcmeOnline
                  responseEntries:
                    - responseIdentifier: '12345'
                      answer: >-
                        The customer service representatives were very helpful
                        and resolved my issue quickly.
                      followupResponses:
                        - question: Which feature was most important?
                          answer: Fast shipping
                    - responseIdentifier: '12346'
                      answer: I liked the easy-to-use website and fast delivery.
      responses:
        '202':
          description: Brand coding job accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BatchCodingResponse'
              example:
                batchJobId: 123e4567-e89b-12d3-a456-426614174001
                surveyIdentifier: CSAT-2024-Q1
                status: queued
                results: null
        '400':
          description: Bad request - invalid input parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: INVALID_REQUEST
                message: Invalid request parameters
                details:
                  brandContext: industryDescription is required
        '403':
          description: Forbidden - Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: INVALID_API_KEY
                message: Invalid or missing API key
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: INTERNAL_ERROR
                message: An unexpected error occurred
        '504':
          description: Gateway timeout
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                code: GATEWAY_TIMEOUT
                message: The server took too long to respond
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            const response = await api.coding.createBrandJob({
              surveyIdentifier: 'CSAT-2024-Q1',
              surveyName: 'Customer Satisfaction',
              surveyDescription: 'Tracking customer satisfaction and loyalty',
              surveyResponses: [
                {
                  questionIdentifier: 'Q1',
                  question: 'What did you like about our service?',
                  brandContext: {
                    industryDescription: 'E-commerce retail',
                    brands: [
                      { name: 'Acme Store', variations: ['Acme', 'AcmeOnline'] }
                    ]
                  },
                  responseEntries: [
                    {
                      responseIdentifier: '12345',
                      answer: 'The customer service representatives were very helpful.',
                      followupResponses: [
                        { question: 'Which rep assisted you?', answer: 'Alice from support' }
                      ]
                    }
                  ]
                }
              ]
            });
        - lang: Python
          source: |-
            response = api.coding.create_brand_job(
                survey_identifier='CSAT-2024-Q1',
                survey_name='Customer Satisfaction',
                survey_description='Tracking customer satisfaction and loyalty',
                survey_responses=[{
                    'question_identifier': 'Q1',
                    'question': 'What did you like about our service?',
                    'brand_context': {
                        'industry_description': 'E-commerce retail',
                        'brands': [
                            {'name': 'Acme Store', 'variations': ['Acme', 'AcmeOnline']}
                        ]
                    },
                    'response_entries': [
                        {
                            'response_identifier': '12345',
                            'answer': 'The customer service representatives were very helpful.',
                            'followup_responses': [
                                {'question': 'Which rep assisted you?', 'answer': 'Alice from support'}
                            ]
                        }
                    ]
                }]
            )
components:
  schemas:
    BatchCodingRequest:
      type: object
      required:
        - surveyIdentifier
        - surveyResponses
      properties:
        surveyIdentifier:
          type: string
          description: Unique string to identify the survey.
          example: CSAT-2024-Q1
        surveyName:
          type: string
          description: >-
            Optional name for the survey. This is used to identify the survey in
            the Aftercare platform.
          example: Customer Satisfaction
        surveyDescription:
          type: string
          description: >-
            An optional description of the survey's purpose, used to help the AI
            understand the context behind thesurvey better.
          example: >-
            Quarterly survey tracking customer satisfaction and loyalty for the
            XYZ Company which sells xyz products
        surveyResponses:
          type: array
          description: Full collection of survey responses by question.
          items:
            $ref: '#/components/schemas/SurveyQuestionData'
    BatchCodingResponse:
      type: object
      required:
        - batchJobId
        - surveyIdentifier
        - status
      properties:
        batchJobId:
          type: string
          description: Unique identifier for the coding job
          example: 123e4567-e89b-12d3-a456-426614174000
        surveyIdentifier:
          type: string
          description: Unique identifier for the survey
          example: CSAT-2024-Q1
        status:
          $ref: '#/components/schemas/BatchCodingStatus'
          description: Status of the batch job that determines the structure of results
        results:
          oneOf:
            - $ref: '#/components/schemas/BatchCodingSuccess'
              title: Success Response
              description: Present when status is 'completed'
            - $ref: '#/components/schemas/BatchCodingErrorDetails'
              title: Error Response
              description: Present when status is 'partial_failure' or 'total_failure'
          description: >-
            The results structure depends on the status value. If the job is
            successful, the results will be a list of question codes with a
            hierarchical tree of codes and subcodes. If the job fails, the
            results will be the error details.
          discriminator:
            propertyName: status
            mapping:
              completed: '#/components/schemas/BatchCodingSuccess'
              partial_failure: '#/components/schemas/BatchCodingErrorDetails'
              total_failure: '#/components/schemas/BatchCodingErrorDetails'
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Error code
          example: INVALID_REQUEST
        message:
          type: string
          description: Error message
          example: Invalid request parameters
        details:
          type: object
          description: Additional error details
          example:
            question: Question is required
    SurveyQuestionData:
      type: object
      required:
        - questionIdentifier
        - question
        - brandContext
        - responseEntries
      properties:
        questionIdentifier:
          type: string
          description: Unique identifier for the question
          example: q1
        question:
          type: string
          description: The question that was asked
          example: What do you like about our product?
        brandContext:
          $ref: '#/components/schemas/BrandContext'
          description: Additional context about the brands for this question
        responseEntries:
          type: array
          items:
            $ref: '#/components/schemas/ResponseEntry'
    BatchCodingStatus:
      type: string
      enum:
        - queued
        - processing
        - completed
        - partial_failure
        - total_failure
      description: >-
        Status values for the batch processing job.


        * `queued` - Job has been received but processing has not yet started

        * `processing` - Job is currently being processed

        * `completed` - Job has finished processing successfully

        * `partial_failure` - Job has finished processing with some failures

        * `total_failure` - Job encountered an error during processing and did
        not complete any results.
    BatchCodingSuccess:
      type: object
      required:
        - completedAt
        - questionCodes
      properties:
        completedAt:
          type: string
          format: date-time
          description: When the batch job completed processing
          example: '2024-03-12T15:30:45Z'
        questionCodes:
          type: array
          description: >-
            Coding results organized by question identifier. Each question will
            have its own hierarchical category tree.
          items:
            $ref: '#/components/schemas/QuestionCodeData'
        nextCursor:
          type: string
          nullable: true
          description: >-
            Cursor for the next page of results. Null if there are no more
            results.
          example: null
    BatchCodingErrorDetails:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
          description: Error code identifying the type of failure
          example: PROCESSING_ERROR
        message:
          type: string
          description: Description of the error
          example: Failed to process survey responses
    BrandContext:
      type: object
      required:
        - industryDescription
        - brands
      properties:
        industryDescription:
          type: string
          description: Description of the industry the brand is in
          example: Consumer electronics
        brands:
          type: array
          description: Common names for the brand and any variations
          items:
            type: object
            required:
              - name
            properties:
              name:
                type: string
                description: Canonical brand name
                example: Acme Corp
              variations:
                type: array
                items:
                  type: string
                description: Alternative names or spellings
                example:
                  - ACME
                  - Acme Corporation
    ResponseEntry:
      type: object
      required:
        - responseIdentifier
        - answer
      properties:
        responseIdentifier:
          type: string
          description: Unique identifier for this response entry
          example: resp-123
        answer:
          type: string
          description: The respondent's answer to the question
          example: I really enjoy the battery life.
        followupResponses:
          type: array
          description: Any follow-up question/answer pairs for this response
          items:
            $ref: '#/components/schemas/FollowupResponse'
    QuestionCodeData:
      type: object
      required:
        - questionIdentifier
        - question
        - responseCodes
      properties:
        questionIdentifier:
          type: string
          description: Unique identifier for the question.
          example: Q1
        question:
          type: string
          description: The question text.
          example: What did you like about our service?
        responseCodes:
          type: array
          description: >-
            Hierarchical code tree for this specific question. Codes can have
            subcodes forming a tree structure.
          items:
            $ref: '#/components/schemas/ResponseCode'
    FollowupResponse:
      type: object
      required:
        - question
        - answer
      properties:
        question:
          type: string
          description: The follow-up question that was asked
          example: What features of our product stood out most?
        answer:
          type: string
          description: The answer provided to the follow-up
          example: I loved the night-vision mode.
    ResponseCode:
      type: object
      required:
        - id
        - label
        - responses
        - subCodes
      properties:
        id:
          type: integer
          description: Unique identifier for this code
          example: 1
        label:
          type: string
          description: Label of the code
          example: Customer Service Quality
        responses:
          type: array
          description: The responses that were classified into this code
          items:
            $ref: '#/components/schemas/ResponseEntry'
        subCodes:
          type: array
          description: >-
            More specific codes classified under this code that can be used to
            further classify the responses
          items:
            $ref: '#/components/schemas/ResponseCode'
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-Aftercare-Key
      description: API key for authentication

````