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

# Assignment webhook reference

> This endpoint must be implemented on YOUR server (for example: https://yourdomain.com/webhooks/on-agent-assignation). Treble will call it when a conversation reaches a **Transfer Methods** block configured with the **API** destination, so your system can decide which agent should receive the chat.

The URL is configured in the block itself, inside the conversation editor. If you enable Token / API Key authentication, Treble will include your token in the `Authorization` header with the format `Bearer YOUR_TOKEN`.

You must respond in less than 10 seconds. If your server doesn't respond in time, returns a status code other than 200, or returns an agent that can't receive the conversation, Treble will apply the fallback method configured in the main platform.



## OpenAPI

````yaml open-api-files/treble-api-en.json POST /webhooks/on-agent-assignation
openapi: 3.0.1
info:
  title: Treble Poll API
  description: Documentation for the poll deployment endpoint in Treble
  version: 1.0.0
servers:
  - url: https://main.treble.ai
    description: Main Treble server
  - url: https://yourdomain.com
    description: >-
      Example server for implementing webhooks. This represents YOUR server
      where you must implement the endpoints that Treble will call.
security: []
tags:
  - name: Webhooks
    description: >-
      Endpoints that Treble will call on your server. These are not real
      endpoints that you can call, but a representation of the webhooks that
      Treble will invoke in your system.
paths:
  /webhooks/on-agent-assignation:
    post:
      tags:
        - Webhooks
      summary: Webhook - Decide which agent receives the conversation
      description: >-
        This endpoint must be implemented on YOUR server (for example:
        https://yourdomain.com/webhooks/on-agent-assignation). Treble will call
        it when a conversation reaches a **Transfer Methods** block configured
        with the **API** destination, so your system can decide which agent
        should receive the chat.


        The URL is configured in the block itself, inside the conversation
        editor. If you enable Token / API Key authentication, Treble will
        include your token in the `Authorization` header with the format `Bearer
        YOUR_TOKEN`.


        You must respond in less than 10 seconds. If your server doesn't respond
        in time, returns a status code other than 200, or returns an agent that
        can't receive the conversation, Treble will apply the fallback method
        configured in the main platform.
      parameters:
        - name: Authorization
          in: header
          required: false
          description: >-
            Only if you configured Token / API Key authentication in the block.
            Treble sends the token with the format `Bearer YOUR_TOKEN`.
          schema:
            type: string
          example: Bearer YOUR_TOKEN
      requestBody:
        description: >-
          Context of the contact and the conversation that Treble sends to your
          endpoint
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentAssignationRequest'
            example:
              company_id: 1234
              survey_user_id: 567890
              contact:
                treble_id: '5215512345678'
                name: Andrea Soto
                country_code: '52'
                cellphone: '5512345678'
                business_scope_id: '1029384756'
                username: null
              crm_type: salesforce
              crm_objects:
                - entity: Contact
                  id: 0035f00000ABCDEqAO
                - entity: Account
                  id: 0015f00000FGHIJqAO
              channel:
                phone_number_id: '1234567890'
              metadata:
                poll_id: 4321
                node_id: a1b2c3
                tag: Comercial
                language: es
      responses:
        '200':
          description: >-
            The agent Treble must assign the conversation to. Return
            `agent_email` (recommended) or `agent_id`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentAssignationResponse'
              example:
                agent_email: andrea.soto@yourcompany.com
      servers:
        - url: https://yourdomain.com
          description: Your server where you must implement this webhook
components:
  schemas:
    AgentAssignationRequest:
      type: object
      description: >-
        Body Treble sends to your endpoint so you can decide which agent
        receives the conversation.
      properties:
        company_id:
          type: integer
          description: Your company's identifier in Treble.
          example: 1234
        survey_user_id:
          type: integer
          description: Identifier of the contact's session in the conversation.
          example: 567890
        contact:
          $ref: '#/components/schemas/AgentAssignationContact'
        crm_type:
          type: string
          nullable: true
          description: >-
            The CRM your account is integrated with, for example `salesforce` or
            `hubspot`. It's `null` if the account has no CRM integration.
          example: salesforce
        crm_objects:
          type: array
          description: >-
            CRM records associated with the contact. An empty array means the
            contact isn't associated with any record yet.
          items:
            $ref: '#/components/schemas/AgentAssignationCrmObject'
        channel:
          $ref: '#/components/schemas/AgentAssignationChannel'
        metadata:
          $ref: '#/components/schemas/AgentAssignationMetadata'
    AgentAssignationResponse:
      type: object
      description: >-
        Response your server must return indicating the agent who will receive
        the conversation. Use `agent_email` or `agent_id`.
      properties:
        agent_email:
          type: string
          description: >-
            The agent's email as registered in Treble. It's the recommended
            option because it doesn't depend on Treble's internal identifiers.
          example: andrea.soto@yourcompany.com
        agent_id:
          type: integer
          description: The agent's identifier in Treble.
          example: 4567
    AgentAssignationContact:
      type: object
      description: Information about the contact in the conversation.
      properties:
        treble_id:
          type: string
          description: The contact's identifier in Treble.
          example: '5215512345678'
        name:
          type: string
          nullable: true
          description: The contact's name.
          example: Andrea Soto
        country_code:
          type: string
          nullable: true
          description: >-
            Country code. Can be `null` for contacts that only exist as a Meta
            username.
          example: '52'
        cellphone:
          type: string
          nullable: true
          description: >-
            Cellphone number without country code. Can be `null` for contacts
            that only exist as a Meta username.
          example: '5512345678'
        business_scope_id:
          type: string
          nullable: true
          description: The contact's identifier within your business scope in Meta.
          example: '1029384756'
        username:
          type: string
          nullable: true
          description: The contact's Meta username, when applicable.
          example: null
    AgentAssignationCrmObject:
      type: object
      description: CRM record associated with the contact.
      properties:
        entity:
          type: string
          description: Object type in the CRM, for example `Contact`, `Account`, or `Lead`.
          example: Contact
        id:
          type: string
          description: The record's identifier in your CRM.
          example: 0035f00000ABCDEqAO
    AgentAssignationChannel:
      type: object
      description: Channel the conversation came in through.
      properties:
        phone_number_id:
          type: string
          description: Identifier of the WhatsApp line that received the conversation.
          example: '1234567890'
    AgentAssignationMetadata:
      type: object
      description: Context of the flow and the block that originated the call.
      properties:
        poll_id:
          type: integer
          description: Identifier of the Treble conversation (flow).
          example: 4321
        node_id:
          type: string
          description: Identifier of the Transfer Methods block that originated the call.
          example: a1b2c3
        tag:
          type: string
          nullable: true
          description: Team (tag) selected in the block.
          example: Comercial
        language:
          type: string
          nullable: true
          description: Language of the conversation.
          example: es

````