> ## 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.

# Preview the expected value derived from treatments

> Returns what creating a lead with these treatments and no `expected_value` would store, or what
changing an existing lead's treatments to this set would store, without saving anything. One
shared currency is kept with today's TCMB rate; mixed currencies are converted into the
clinic's base currency. A treatment whose currency has no recorded rate is left out and listed
in `skipped_treatment_ids`. Re-saving a lead with its unchanged treatments keeps its stored
value and rate instead. Reading treatment prices here needs only the lead form permissions,
not `View:Treatment`.



## OpenAPI

````yaml post /v1/leads/expected-value/preview
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/leads/expected-value/preview:
    post:
      tags:
        - Lead
      summary: Preview the expected value derived from treatments
      description: >-
        Returns what creating a lead with these treatments and no
        `expected_value` would store, or what

        changing an existing lead's treatments to this set would store, without
        saving anything. One

        shared currency is kept with today's TCMB rate; mixed currencies are
        converted into the

        clinic's base currency. A treatment whose currency has no recorded rate
        is left out and listed

        in `skipped_treatment_ids`. Re-saving a lead with its unchanged
        treatments keeps its stored

        value and rate instead. Reading treatment prices here needs only the
        lead form permissions,

        not `View:Treatment`.
      operationId: lead.previewExpectedValue
      parameters:
        - 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/LeadExpectedValuePreviewRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: string
                  data:
                    $ref: '#/components/schemas/LeadExpectedValuePreviewResource'
                required:
                  - success
                  - data
        '401':
          $ref: '#/components/responses/AuthenticationException'
        '403':
          $ref: '#/components/responses/AuthorizationException'
        '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:
    LeadExpectedValuePreviewRequest:
      type: object
      properties:
        treatment_ids:
          type: array
          description: >-
            The active treatment identifiers the lead form has selected. An
            empty array previews a lead without treatments.
          items:
            type: integer
            description: An active treatment identifier belonging to the tenant.
          maxItems: 200
      required:
        - treatment_ids
      title: LeadExpectedValuePreviewRequest
    LeadExpectedValuePreviewResource:
      type: object
      properties:
        expected_value:
          type: string
          description: >-
            The expected value a lead with these treatments would store, in
            `currency_code`, formatted like the lead's own `expected_value`.
        currency_code:
          type: string
          description: >-
            The code of the currency the lead would store: the treatments'
            shared currency, or the clinic's base currency when they are priced
            in several.
        exchange_rate:
          type: string
          description: >-
            The rate of `currency_code` against the clinic's base currency that
            the lead would freeze, formatted like the lead's own
            `exchange_rate`.
        base_currency_expected_value:
          type: number
          description: >-
            The expected value in the clinic's base currency (`expected_value` ×
            `exchange_rate`).
        rate_date:
          type:
            - string
            - 'null'
          description: >-
            The day of the TCMB rate used to convert a treatment price
            (`Y-m-d`); null when no price needed converting.
        skipped_treatment_ids:
          type: array
          description: >-
            Treatments left out of the total because their currency has no
            recorded rate.
          items:
            type: integer
      required:
        - expected_value
        - currency_code
        - exchange_rate
        - base_currency_expected_value
        - rate_date
        - skipped_treatment_ids
      title: LeadExpectedValuePreviewResource
  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
    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://app.flextell.ai/oauth/authorize
          tokenUrl: https://app.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.