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

# List all messages by conversation ID

> Retrieves a paginated list of messages for a specific conversation within a company.
Supports sorting by created_at and pagination options.




## OpenAPI

````yaml GET /v1/fetch-messages/{company_id}/{conversation_id}
openapi: 3.0.3
info:
  title: SalesCaptain API Documentation Service
  description: >
    API Documentation Service for SalesCaptain platform.

    This service provides endpoints for managing and retrieving company
    information for API documentation purposes.
  version: 0.1.0
  contact:
    name: SalesCaptain API Team
    email: support@salescaptain.com
  license:
    name: Proprietary
    url: https://salescaptain.com/license
servers:
  - url: https://api.salescaptain.com
    description: Production server
security:
  - BearerAuth: []
tags:
  - name: Health
    description: Service health and status endpoints
  - name: Companies
    description: Company management and retrieval operations
  - name: Accounts
    description: Account management and retrieval operations
  - name: Conversation Profiles
    description: Conversation profile management for communication channels
  - name: Conversations
    description: Conversation management and retrieval operations
  - name: Contacts
    description: Contact management and retrieval operations
  - name: Custom Fields
    description: Custom field definition management
externalDocs:
  description: SalesCaptain API Documentation
  url: https://docs.salescaptain.com
paths:
  /v1/fetch-messages/{company_id}/{conversation_id}:
    get:
      tags:
        - Conversations
      summary: Fetch messages for a conversation (paginated)
      description: >
        Retrieves a paginated list of messages for a specific conversation
        within a company.

        Supports sorting by created_at and pagination options.
      operationId: fetchMessages
      parameters:
        - name: company_id
          in: path
          required: true
          description: Unique identifier for the company
          schema:
            type: string
            format: uuid
            example: a1b2c3d4-e5f6-7890-abcd-ef1234567890
        - name: conversation_id
          in: path
          required: true
          description: Unique identifier for the conversation
          schema:
            type: string
            format: uuid
            example: b2c3d4e5-f6a7-8901-bcde-f12345678901
        - name: page_number
          in: query
          required: true
          description: Page number for pagination (must be a positive integer)
          schema:
            type: integer
            minimum: 1
            example: 1
        - name: items_per_page
          in: query
          required: false
          description: Number of items per page (10-100, default 10)
          schema:
            type: integer
            minimum: 10
            maximum: 100
            default: 10
            example: 10
        - name: sort_by
          in: query
          required: false
          description: Field to sort by
          schema:
            type: string
            enum:
              - created_at
            example: created_at
        - name: sort_dir
          in: query
          required: false
          description: Sort direction (default desc)
          schema:
            type: string
            enum:
              - asc
              - desc
            default: desc
            example: desc
      responses:
        '200':
          description: Messages fetched successfully or error response
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      message:
                        type: string
                        example: Messages fetched successfully!
                      messages:
                        type: object
                        properties:
                          data:
                            type: array
                            items:
                              $ref: '#/components/schemas/Message'
                          pagination:
                            $ref: '#/components/schemas/Pagination'
                  - $ref: '#/components/schemas/FailureResponse'
              examples:
                success:
                  summary: Successful response
                  value:
                    message: Messages fetched successfully!
                    messages:
                      data:
                        - conversation_id: b2c3d4e5-f6a7-8901-bcde-f12345678901
                          message_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                          contact_id: f6a7b8c9-d0e1-2345-f123-456789012345
                          conversation_profile_id: c3d4e5f6-a7b8-9012-cdef-123456789012
                          conversation_profile_email: support@company.com
                          conversation_profile_number: '+1987654321'
                          type_of_message: sms_message
                          direction: inbound
                          assigned_account_id: d4e5f6a7-b8c9-0123-def1-234567890123
                          created_at: '2026-03-15T08:00:00.000Z'
                      pagination:
                        page_number: 1
                        items_per_page: 10
                        total_count: 25
                        total_pages: 3
                missing_params:
                  summary: Missing company_id or conversation_id
                  value:
                    status: failure
                    error: >-
                      {"is_error":true,"error":"company_id and conversation_id
                      must be provided!","message":"company_id and
                      conversation_id must be provided!"}
                    message: >-
                      {"is_error":true,"error":"company_id and conversation_id
                      must be provided!","message":"company_id and
                      conversation_id must be provided!"}
                missing_pagination:
                  summary: Missing page or items_per_page
                  value:
                    status: failure
                    error: >-
                      {"is_error":true,"error":"page and items_per_page are
                      required","message":"page and items_per_page are
                      required"}
                    message: >-
                      {"is_error":true,"error":"page and items_per_page are
                      required","message":"page and items_per_page are
                      required"}
                conversation_not_found:
                  summary: Conversation not found
                  value:
                    status: failure
                    error: >-
                      {"is_error":true,"error":"Conversation not
                      found","message":"Conversation not found"}
                    message: >-
                      {"is_error":true,"error":"Conversation not
                      found","message":"Conversation not found"}
                company_not_found:
                  summary: Company not found
                  value:
                    status: failure
                    error: Problem encountered while fetching messages!
                    message: Company not found
                unexpected_error:
                  summary: Unexpected error (network, DB, etc.)
                  value:
                    status: failure
                    error: Problem encountered while fetching messages!
                    message: connect ECONNREFUSED
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '403':
          $ref: '#/components/responses/ForbiddenError'
        '429':
          $ref: '#/components/responses/RateLimitError'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - BearerAuth: []
components:
  schemas:
    Message:
      type: object
      description: Message information object
      properties:
        conversation_id:
          type: string
          format: uuid
          description: Unique identifier for the conversation
          example: b2c3d4e5-f6a7-8901-bcde-f12345678901
        message_id:
          type: string
          format: uuid
          description: Unique identifier for the message
          example: a1b2c3d4-e5f6-7890-abcd-ef1234567890
        contact_id:
          type: string
          format: uuid
          description: Unique identifier for the contact
          example: f6a7b8c9-d0e1-2345-f123-456789012345
        conversation_profile_id:
          type: string
          format: uuid
          description: Unique identifier for the conversation profile
          example: c3d4e5f6-a7b8-9012-cdef-123456789012
        conversation_profile_email:
          type: string
          format: email
          nullable: true
          description: Email address of the conversation profile
          example: support@company.com
        conversation_profile_number:
          type: string
          nullable: true
          description: Phone number of the conversation profile
          example: '+1987654321'
        type_of_message:
          type: string
          description: Type of the message (e.g., sms_message, email_message, etc.)
          example: sms_message
        direction:
          type: string
          description: Direction of the message
          enum:
            - inbound
            - outbound
          example: inbound
        assigned_account_id:
          type: string
          format: uuid
          nullable: true
          description: Account ID of the agent assigned at the time of the message
          example: d4e5f6a7-b8c9-0123-def1-234567890123
        created_at:
          type: string
          format: date-time
          description: Timestamp when the message was created
          example: '2026-03-15T08:00:00.000Z'
      required:
        - conversation_id
        - message_id
        - contact_id
        - conversation_profile_id
        - type_of_message
        - direction
        - created_at
    Pagination:
      type: object
      description: Pagination metadata
      properties:
        page_number:
          type: integer
          description: Current page number
          example: 1
        items_per_page:
          type: integer
          description: Number of items per page
          example: 10
        total_count:
          type: integer
          description: Total number of items across all pages
          example: 156
        total_pages:
          type: integer
          description: Total number of pages
          example: 16
      required:
        - page_number
        - items_per_page
        - total_count
        - total_pages
    FailureResponse:
      type: object
      description: Standard failure response returned with HTTP 200 status
      properties:
        status:
          type: string
          description: Always "failure" for error responses
          example: failure
        error:
          type: string
          description: Error description (may contain stringified JSON)
          example: Problem encountered while fetching messages!
        message:
          type: string
          description: Error message (may contain stringified JSON)
          example: Company not found
        trace:
          type: array
          description: Stack trace (included in non-production environments)
          items:
            type: string
        request:
          type: object
          description: Original request details
          properties:
            body:
              type: object
            method:
              type: string
            url:
              type: string
            params:
              type: object
      required:
        - status
        - error
        - message
    Error:
      type: object
      description: Error response object
      properties:
        error:
          type: string
          description: Error message
          example: Invalid request parameters
        code:
          type: string
          description: Error code for programmatic handling
          example: INVALID_PARAMS
        timestamp:
          type: string
          format: date-time
          description: Timestamp when the error occurred
          example: '2023-12-01T10:30:00Z'
        path:
          type: string
          description: API endpoint path where the error occurred
          example: /v1/fetch-companies
      required:
        - error
  responses:
    UnauthorizedError:
      description: Authentication token is missing or invalid
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: Unauthorized access
            code: UNAUTHORIZED
            timestamp: '2023-12-01T10:30:00Z'
            path: /v1/fetch-companies
    ForbiddenError:
      description: Access forbidden - valid token but insufficient permissions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: Forbidden access
            code: FORBIDDEN
            timestamp: '2023-12-01T10:30:00Z'
            path: /v1/fetch-companies
    RateLimitError:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: Too many requests, please try again later
            code: RATE_LIMIT_EXCEEDED
            timestamp: '2023-12-01T10:30:00Z'
            path: /v1/fetch-companies
      headers:
        X-RateLimit-Limit:
          description: Request limit per time window
          schema:
            type: integer
            example: 30
        X-RateLimit-Remaining:
          description: Remaining requests in current window
          schema:
            type: integer
            example: 0
        X-RateLimit-Reset:
          description: Time when the rate limit resets
          schema:
            type: integer
            example: 1701425400
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: Problem encountered while fetching companies!
            code: INTERNAL_ERROR
            timestamp: '2023-12-01T10:30:00Z'
            path: /v1/fetch-companies
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        Authentication token required for accessing protected endpoints.

        The token should be obtained from the main SalesCaptain authentication
        service.

````