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

# Merge another customer into this one

> Moves every record attached to the source customer — appointments, sales, tickets,
conversations, messages, transactions, forms, invoices, offers, leads, tags, identities,
notes and files — onto this customer, then permanently deletes the source. Field values
are taken from this customer unless `field_selections` says otherwise.



## OpenAPI

````yaml /api-referansi/openapi.json post /v1/customers/{id}/merge
openapi: 3.1.0
info:
  title: Flextell API
  version: 0.0.1
  description: >-
    Flextell REST API referansı. Kimlik doğrulama, scope ve istek kuralları için
    API sekmesindeki rehberlere bakın.
servers:
  - url: https://app.flextell.ai/api
    description: Üretim
security:
  - oauth2: []
  - bearer: []
paths:
  /v1/customers/{id}/merge:
    post:
      tags:
        - Customer
      summary: Merge another customer into this one
      description: >-
        Moves every record attached to the source customer — appointments,
        sales, tickets,

        conversations, messages, transactions, forms, invoices, offers, leads,
        tags, identities,

        notes and files — onto this customer, then permanently deletes the
        source. Field values

        are taken from this customer unless `field_selections` says otherwise.
      operationId: customer.merge
      parameters:
        - name: id
          in: path
          required: true
          description: The customer identifier
          schema:
            type: integer
        - name: X-Tenant
          in: header
          required: true
          description: >-
            Tenant identifier. Send the Tenant ID in the `X-Tenant` header to
            scope API requests to a specific tenant.
          schema:
            type: number
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CustomerMergeRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: string
                  data:
                    type: object
                    properties:
                      customer:
                        $ref: '#/components/schemas/CustomerResource'
                      merge:
                        type: object
                        properties:
                          id:
                            type: string
                          source_customer_id:
                            type: string
                          source_customer_name:
                            type: string
                          moved_counts:
                            type: string
                          total_moved_count:
                            type: string
                        required:
                          - id
                          - source_customer_id
                          - source_customer_name
                          - moved_counts
                          - total_moved_count
                    required:
                      - customer
                      - merge
                required:
                  - success
                  - data
        '401':
          $ref: '#/components/responses/AuthenticationException'
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '404':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  error_code:
                    type: string
                    const: RESOURCE_NOT_FOUND
                  message:
                    type: string
                  errors:
                    type: 'null'
                  data:
                    type: 'null'
                required:
                  - success
                  - error_code
                  - message
                  - errors
                  - data
        '409':
          $ref: '#/components/responses/CustomerErasedException'
        '422':
          $ref: '#/components/responses/ValidationException'
        '428':
          description: >-
            Mandatory setup is incomplete. Finish the setup wizard first;
            `data.next_step` names the step to continue with.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    examples:
                      - false
                  error_code:
                    type: string
                    enum:
                      - SETUP_REQUIRED
                    examples:
                      - SETUP_REQUIRED
                  message:
                    type: string
                    examples:
                      - Complete the required setup steps to continue.
                  data:
                    type: object
                    properties:
                      next_step:
                        type:
                          - string
                          - 'null'
                        examples:
                          - clinic_info
                    required:
                      - next_step
                required:
                  - success
                  - error_code
                  - message
                  - data
components:
  schemas:
    CustomerMergeRequest:
      type: object
      properties:
        source_customer_id:
          type: integer
          description: >-
            Identifier of the customer that is merged into this one and then
            permanently deleted.
          minimum: 1
        field_selections:
          type: object
          description: >-
            Per-field winner map. Keys are customer fields, values are either
            "target" (keep the

            surviving customer's value) or "source" (take the deleted customer's
            value). Fields

            left out keep the surviving customer's value.
          properties:
            first_name:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            last_name:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            phone_number:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            email:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            date_of_birth:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            gender:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            identity_number:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            passport_number:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            country_id:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            city_id:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            district_id:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            occupation_id:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            address:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            default_channel_id:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            user_id:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
            avatar_url:
              type: string
              description: Which record the field's value is taken from.
              enum:
                - target
                - source
          required:
            - first_name
            - last_name
            - phone_number
            - email
            - date_of_birth
            - gender
            - identity_number
            - passport_number
            - country_id
            - city_id
            - district_id
            - occupation_id
            - address
            - default_channel_id
            - user_id
            - avatar_url
      required:
        - source_customer_id
      title: CustomerMergeRequest
    CustomerResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        first_name:
          anyOf:
            - type: string
            - type: 'null'
        last_name:
          anyOf:
            - type: string
            - type: 'null'
        phone_number:
          anyOf:
            - type: string
            - type: 'null'
        email:
          anyOf:
            - type: string
            - type: 'null'
        date_of_birth:
          type:
            - string
            - 'null'
        gender:
          anyOf:
            - $ref: '#/components/schemas/Gender'
            - type: 'null'
        country_id:
          type:
            - integer
            - 'null'
        country_name:
          type: string
        city_id:
          type:
            - integer
            - 'null'
        city_name:
          type: string
        district_id:
          type:
            - integer
            - 'null'
        district_name:
          type: string
        identity_number:
          anyOf:
            - type: string
            - type: 'null'
        passport_number:
          anyOf:
            - type: string
            - type: 'null'
        occupation_id:
          type:
            - integer
            - 'null'
        occupation_name:
          type: string
        address:
          anyOf:
            - type: string
            - type: 'null'
        default_channel_id:
          type:
            - integer
            - 'null'
        default_channel_name:
          type: string
        latest_conversation_id:
          type:
            - integer
            - 'null'
        avatar_url:
          type:
            - string
            - 'null'
        is_lead_stage:
          type: boolean
        lead_id:
          type:
            - integer
            - 'null'
        is_masked:
          type: boolean
          description: >-
            Whether the identity fields are masked because the viewer may not
            see this lead's patient.
        related_user:
          $ref: '#/components/schemas/RelatedUserResource'
        tags:
          type: array
          items:
            $ref: '#/components/schemas/TagResource'
        notification_channels:
          $ref: '#/components/schemas/CustomerNotificationChannelsResource'
        import_source:
          anyOf:
            - $ref: '#/components/schemas/RelatedImportSourceResource'
              description: >-
                The external system the record was imported from, or `null` when
                it was created in Flextell. Only present on detail responses.
            - type: 'null'
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        deleted_at:
          type:
            - string
            - 'null'
          format: date-time
        erased_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - record_state
        - first_name
        - last_name
        - phone_number
        - email
        - date_of_birth
        - gender
        - country_id
        - country_name
        - city_id
        - city_name
        - district_id
        - district_name
        - identity_number
        - passport_number
        - occupation_id
        - occupation_name
        - address
        - default_channel_id
        - default_channel_name
        - latest_conversation_id
        - avatar_url
        - is_lead_stage
        - lead_id
        - is_masked
        - related_user
        - created_at
        - updated_at
        - deleted_at
        - erased_at
      title: CustomerResource
    RecordStateResource:
      type: object
      properties:
        is_read_only:
          type: boolean
          description: >-
            True when every write on this record is refused; false does not
            imply the caller may write.
        reason_code:
          type:
            - string
            - 'null'
          description: >-
            Why the record is read-only (`CUSTOMER_ERASED`, or
            `LEAD_NOT_ASSIGNED` for a salesperson on another rep's lead), or
            null when it is not.
      required:
        - is_read_only
        - reason_code
      title: RecordStateResource
    Gender:
      type: string
      enum:
        - male
        - female
        - other
      title: Gender
    RelatedUserResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        avatar_url:
          type:
            - string
            - 'null'
          description: >-
            A signed profile photo URL valid for a few hours, or `null` without
            a photo. Only on responses that opt in.
      required:
        - id
        - name
      title: RelatedUserResource
    TagResource:
      type: object
      properties:
        id:
          type: integer
        tenant_id:
          type: integer
        name:
          type: string
        color:
          type: string
        created_at:
          type:
            - string
            - 'null'
          format: date-time
        updated_at:
          type:
            - string
            - 'null'
          format: date-time
        deleted_at:
          type:
            - string
            - 'null'
          format: date-time
      required:
        - id
        - tenant_id
        - name
        - color
        - created_at
        - updated_at
        - deleted_at
      title: TagResource
    CustomerNotificationChannelsResource:
      type: object
      properties:
        default_channel_id:
          type:
            - string
            - 'null'
        source:
          type:
            - string
            - 'null'
        channels:
          type: array
          items: {}
      required:
        - default_channel_id
        - source
        - channels
      title: CustomerNotificationChannelsResource
    RelatedImportSourceResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        company_logo:
          type: 'null'
      required:
        - id
        - name
        - company_logo
      title: RelatedImportSourceResource
  responses:
    AuthenticationException:
      description: Unauthenticated
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    AuthorizationException:
      description: Authorization error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Error overview.
            required:
              - message
    CustomerErasedException:
      description: The patient record has been erased and is read-only
      content:
        application/json:
          schema:
            type: object
            properties:
              success:
                type: boolean
                description: Always false for an error.
                examples:
                  - false
              error_code:
                type: string
                description: Machine-readable error code.
                examples:
                  - CUSTOMER_ERASED
              message:
                type: string
                description: Localized error message.
            required:
              - success
              - error_code
              - message
    ValidationException:
      description: Validation error
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                description: Errors overview.
              errors:
                type: object
                description: A detailed description of each field that failed validation.
                additionalProperties:
                  type: array
                  items:
                    type: string
            required:
              - message
              - errors
  securitySchemes:
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://dev.flextell.ai/oauth/authorize
          tokenUrl: https://dev.flextell.ai/oauth/token
          scopes:
            '*': all
    bearer:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.