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

# Execute CRM Query

> Executes a query against the connected CRM platform (e.g., Salesforce SOQL). The query is validated for security before execution.



## OpenAPI

````yaml post /crm/query
openapi: 3.0.1
info:
  title: Attention Service V2
  description: Attention Service API V2
  termsOfService: https://www.attention.com/terms-of-use
  contact:
    name: Attention Team
    url: https://docs.attention.com/welcome
    email: support@attention.com
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.8.0
servers:
  - url: https://api.attention.tech/v2
security:
  - APIKeyHeader: []
paths:
  /crm/query:
    post:
      tags:
        - CRM
      summary: Execute CRM Query
      description: >-
        Executes a query against the connected CRM platform (e.g., Salesforce
        SOQL). The query is validated for security before execution.
      operationId: executeCRMQuery
      requestBody:
        description: Query request payload
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ExecuteCRMQueryRequest'
        required: true
      responses:
        '200':
          description: Query executed successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExecuteCRMQueryResponse'
        '400':
          description: Invalid query or request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Valid API key required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Base_401_Error'
        '404':
          description: No CRM account configured for this organization
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        default:
          description: Unexpected error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
      security:
        - APIKeyHeader: []
components:
  schemas:
    ExecuteCRMQueryRequest:
      required:
        - query
      type: object
      properties:
        query:
          maxLength: 10000
          type: string
          description: The query to execute (e.g., SOQL for Salesforce)
          example: >-
            SELECT Id, Name, Email FROM Contact WHERE CreatedDate =
            LAST_N_DAYS:30 LIMIT 100
      example:
        query: >-
          SELECT Id, Name, Amount FROM Opportunity WHERE StageName = 'Closed
          Won' LIMIT 10
    ExecuteCRMQueryResponse:
      type: object
      properties:
        records:
          type: array
          description: Query result records
          items:
            type: object
            additionalProperties: true
        totalSize:
          type: integer
          description: Total number of records matching the query
        done:
          type: boolean
          description: Whether all records have been returned
        nextRecordsUrl:
          type: string
          description: URL to fetch the next batch of records (if paginated)
      example:
        records:
          - Id: 006ABC123
            Name: Enterprise Deal
            Amount: 50000
        totalSize: 1
        done: true
    Error:
      type: object
      properties:
        id:
          type: string
          description: A unique identifier for the error.
        status:
          type: string
          description: >-
            The HTTP status code applicable to this problem, expressed as a
            string value.
        code:
          type: string
          description: An application-specific error code, expressed as a string value.
        title:
          type: string
          description: A short, human-readable summary of the problem.
        detail:
          type: string
          description: >-
            A human-readable explanation specific to this occurrence of the
            problem.
        source:
          type: object
          properties:
            pointer:
              type: string
            parameter:
              type: string
        meta:
          type: object
          properties: {}
      example:
        id: not_found_error
        status: '404'
        code: '404'
        title: Not Found Error
        detail: The requested resource was not found
        source:
          pointer: /data/attributes/id
    Base_401_Error:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/BaseError'
      example:
        code: 401
        message: unauthenticated for Invalid API key
    BaseError:
      type: object
      properties:
        code:
          type: string
          description: Error code
        message:
          type: string
          description: Error message
      example:
        code: unauthorized
        message: Invalid or expired API key
  securitySchemes:
    APIKeyHeader:
      type: apiKey
      name: Authorization
      in: header

````