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

# Create Ads conversion rule

> Adds a rule mapping a channel event to a conversion. Use `ads.listRules` first to avoid duplicating an existing rule.



## OpenAPI

````yaml /api-reference/platform-api.json post /v1/ads/conversion-rules
openapi: 3.1.1
info:
  title: ChatbotX
  version: 0.0.1
servers:
  - url: https://app.chatbotx.io/api
security:
  - bearerAuth: []
  - developerAccessToken: []
  - tokenInSearchParams: []
paths:
  /v1/ads/conversion-rules:
    post:
      tags:
        - Ads
      summary: Create Ads conversion rule
      description: >-
        Adds a rule mapping a channel event to a conversion. Use `ads.listRules`
        first to avoid duplicating an existing rule.
      operationId: ads.createRule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                channel:
                  enum:
                    - whatsapp
                    - facebook
                    - messenger
                    - instagram
                  type: string
                  description: Channel this rule applies to.
                integrationWhatsappId:
                  anyOf:
                    - type: string
                      pattern: ^\d+$
                    - type: 'null'
                  description: Restrict to this WhatsApp integration.
                integrationFacebookAdsId:
                  anyOf:
                    - type: string
                      pattern: ^\d+$
                    - type: 'null'
                  description: Restrict to this Facebook Ads integration.
                integrationMessengerId:
                  anyOf:
                    - type: string
                      pattern: ^\d+$
                    - type: 'null'
                  description: Restrict to this Messenger integration.
                integrationInstagramId:
                  anyOf:
                    - type: string
                      pattern: ^\d+$
                    - type: 'null'
                  description: Restrict to this Instagram integration.
                adAccountId:
                  anyOf:
                    - type: string
                      minLength: 1
                    - type: 'null'
                  description: Meta ad account id (act_<id>) to report conversions to.
                eventType:
                  enum:
                    - lead
                    - purchase
                  type: string
                  description: Conversion event type this rule reports.
                trigger:
                  anyOf:
                    - type: object
                      properties:
                        type:
                          const: templateSent
                        templateIds:
                          type: array
                          minItems: 1
                          items:
                            type: string
                            minLength: 1
                          description: Template ids that trigger this rule when sent.
                      required:
                        - type
                        - templateIds
                    - type: object
                      properties:
                        type:
                          const: tagApplied
                        tagIds:
                          type: array
                          minItems: 1
                          items:
                            type: string
                            minLength: 1
                          description: Tag ids that trigger this rule when applied.
                      required:
                        - type
                        - tagIds
                    - type: object
                      properties:
                        type:
                          const: keywordMatched
                        automatedResponseIds:
                          type: array
                          minItems: 1
                          items:
                            type: string
                            minLength: 1
                          description: >-
                            Keyword automation ids that trigger this rule when
                            matched.
                      required:
                        - type
                        - automatedResponseIds
                    - type: object
                      properties:
                        type:
                          const: contactReplied
                        firstReplyOnly:
                          type: boolean
                          description: >-
                            Only trigger on the contact's first reply, not every
                            reply.
                      required:
                        - type
                        - firstReplyOnly
                  description: Workspace event that fires this rule.
                markAs:
                  anyOf:
                    - type: string
                      minLength: 1
                    - type: 'null'
                  description: Label recorded on the conversion event for this rule.
                enabled:
                  type: boolean
                  description: Whether the rule is active.
              required:
                - channel
                - eventType
                - trigger
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: ^\d+$
                  createdAt:
                    type: string
                    format: date-time
                    x-native-type: date
                  updatedAt:
                    type: string
                    format: date-time
                    x-native-type: date
                  channel:
                    enum:
                      - whatsapp
                      - facebook
                      - messenger
                      - instagram
                    type: string
                  integrationWhatsappId:
                    anyOf:
                      - type: string
                        pattern: ^\d+$
                      - type: 'null'
                  integrationFacebookAdsId:
                    anyOf:
                      - type: string
                        pattern: ^\d+$
                      - type: 'null'
                  integrationMessengerId:
                    anyOf:
                      - type: string
                        pattern: ^\d+$
                      - type: 'null'
                  integrationInstagramId:
                    anyOf:
                      - type: string
                        pattern: ^\d+$
                      - type: 'null'
                  adAccountId:
                    anyOf:
                      - type: string
                      - type: 'null'
                  eventType:
                    enum:
                      - lead
                      - purchase
                    type: string
                  trigger:
                    anyOf:
                      - type: object
                        properties:
                          type:
                            const: templateSent
                          templateIds:
                            type: array
                            minItems: 1
                            items:
                              type: string
                              minLength: 1
                            description: Template ids that trigger this rule when sent.
                        required:
                          - type
                          - templateIds
                      - type: object
                        properties:
                          type:
                            const: tagApplied
                          tagIds:
                            type: array
                            minItems: 1
                            items:
                              type: string
                              minLength: 1
                            description: Tag ids that trigger this rule when applied.
                        required:
                          - type
                          - tagIds
                      - type: object
                        properties:
                          type:
                            const: keywordMatched
                          automatedResponseIds:
                            type: array
                            minItems: 1
                            items:
                              type: string
                              minLength: 1
                            description: >-
                              Keyword automation ids that trigger this rule when
                              matched.
                        required:
                          - type
                          - automatedResponseIds
                      - type: object
                        properties:
                          type:
                            const: contactReplied
                          firstReplyOnly:
                            type: boolean
                            description: >-
                              Only trigger on the contact's first reply, not
                              every reply.
                        required:
                          - type
                          - firstReplyOnly
                  markAs:
                    anyOf:
                      - type: string
                      - type: 'null'
                  enabled:
                    type: boolean
                required:
                  - id
                  - createdAt
                  - updatedAt
                  - channel
                  - integrationWhatsappId
                  - integrationFacebookAdsId
                  - integrationMessengerId
                  - integrationInstagramId
                  - adAccountId
                  - eventType
                  - trigger
                  - markAs
                  - enabled
        '400':
          description: '400'
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: businessError
                      status:
                        const: 400
                      message:
                        type: string
                        default: An error occurred while processing your request
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - $ref: '#/components/schemas/UndefinedError'
        '401':
          description: '401'
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: UNAUTHORIZED
                      status:
                        const: 401
                      message:
                        type: string
                        default: Authentication required
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: INVALID_CHATBOT_TOKEN
                      status:
                        const: 401
                      message:
                        type: string
                        default: Invalid or missing workspace API token
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - $ref: '#/components/schemas/UndefinedError'
        '403':
          description: '403'
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: FORBIDDEN
                      status:
                        const: 403
                      message:
                        type: string
                        default: You do not have permission to perform this action
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: trialExpired
                      status:
                        const: 403
                      message:
                        type: string
                        default: Trial expired
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: macLimitReached
                      status:
                        const: 403
                      message:
                        type: string
                        default: Monthly active contact limit reached
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - $ref: '#/components/schemas/UndefinedError'
        '422':
          description: '422'
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: invalidRequestData
                      status:
                        const: 422
                      message:
                        type: string
                        default: Input validation failed
                      data:
                        type: object
                        properties:
                          issues:
                            type: array
                            items:
                              type: object
                              properties:
                                message:
                                  type: string
                                path:
                                  type: array
                                  items:
                                    anyOf:
                                      - type: string
                                      - type: number
                                      - type: object
                                        properties:
                                          key:
                                            anyOf:
                                              - type: string
                                              - type: number
                                        required:
                                          - key
                                        additionalProperties: {}
                              required:
                                - message
                              additionalProperties: {}
                        required:
                          - issues
                        additionalProperties: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                      - data
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: validation
                      status:
                        const: 422
                      message:
                        type: string
                        default: Validation error
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - $ref: '#/components/schemas/UndefinedError'
        '429':
          description: '429'
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: tooManyRequests
                      status:
                        const: 429
                      message:
                        type: string
                        default: Too many requests
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - $ref: '#/components/schemas/UndefinedError'
        '500':
          description: '500'
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    properties:
                      defined:
                        const: true
                      code:
                        const: INTERNAL_SERVER_ERROR
                      status:
                        const: 500
                      message:
                        type: string
                        default: An unexpected error occurred
                      data: {}
                    required:
                      - defined
                      - code
                      - status
                      - message
                  - $ref: '#/components/schemas/UndefinedError'
components:
  schemas:
    UndefinedError:
      type: object
      properties:
        defined:
          const: false
        code:
          type: string
        status:
          type: number
        message:
          type: string
        data: {}
      required:
        - defined
        - code
        - status
        - message
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
    developerAccessToken:
      type: http
      scheme: bearer
    tokenInSearchParams:
      type: apiKey
      in: query
      name: token

````