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

# Update a sale



## OpenAPI

````yaml put /v1/sales/{id}
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/sales/{id}:
    put:
      tags:
        - Sales
      summary: Update a sale
      operationId: sales.update
      parameters:
        - name: id
          in: path
          required: true
          description: The sale 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:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SaleUpdateRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: string
                  data:
                    $ref: '#/components/schemas/SaleResource'
                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:
    SaleUpdateRequest:
      type: object
      properties:
        customer_id:
          type: integer
          description: Customer ID.
        appointment_id:
          type:
            - integer
            - 'null'
          description: >-
            Related appointment ID (optional). Must belong to current tenant and
            the provided customer.
        currency_id:
          type: integer
          description: Currency ID.
        exchange_rate:
          type: number
          description: Exchange rate (e.g. 1 or 34.5).
          minimum: 0
        status:
          type: string
          description: 'Sale status: draft, completed, cancelled, invoiced, pending.'
          enum:
            - draft
            - completed
            - cancelled
            - invoiced
            - pending
        sale_date:
          type: string
          format: date-time
          description: >-
            When the sale happened. A naive value is read in the tenant
            timezone.
        user_id:
          type:
            - integer
            - 'null'
          description: User ID (optional).
        notes:
          type:
            - string
            - 'null'
          description: Internal notes.
          maxLength: 65535
        items:
          type: array
          description: Sale line items (optional on update).
          items:
            type: object
            properties:
              staff_id:
                type: integer
                description: Staff (user) ID who performed or is responsible for this item.
              itemable_type:
                type: string
                description: 'Polymorphic type: Treatment or Product.'
                enum:
                  - Treatment
                  - Product
                  - App\Models\Treatment
                  - App\Models\Product
              itemable_id:
                type: integer
                description: ID of the treatment or product.
                minimum: 1
              quantity:
                type: number
                description: Quantity.
                minimum: 0.0001
              unit_price:
                type: number
                description: Unit price.
                minimum: 0
              tax_rate:
                type: integer
                description: Tax rate (0, 1, 10, or 20).
                enum:
                  - '0'
                  - '1'
                  - '10'
                  - '20'
              discount_amount:
                type: number
                description: Discount amount.
                minimum: 0
              discount_percentage:
                type: number
                description: Discount percentage (0-100).
                minimum: 0
                maximum: 100
              sub_total:
                type:
                  - number
                  - 'null'
                description: >-
                  Sub-total before tax and discount (optional, will be
                  server-calculated if omitted).
                minimum: 0
              total_discount:
                type:
                  - number
                  - 'null'
                description: >-
                  Total discount applied (optional, will be server-calculated if
                  omitted).
                minimum: 0
              total_tax:
                type:
                  - number
                  - 'null'
                description: Total tax (optional, will be server-calculated if omitted).
                minimum: 0
              total_price:
                type:
                  - number
                  - 'null'
                description: >-
                  Total price for this item. Server-calculated unless the tenant
                  enabled the accounting setting preserve_item_total_price, in
                  which case this value is kept and total_tax absorbs the
                  rounding difference.
                minimum: 0
              cost_price:
                type:
                  - number
                  - 'null'
                description: Cost price (optional).
                minimum: 0
              warehouse_id:
                type:
                  - integer
                  - 'null'
                description: >-
                  Warehouse ID for stock (optional). Must belong to current
                  tenant.
              order:
                type:
                  - integer
                  - 'null'
                description: Display order (optional).
                minimum: 0
              assistants:
                type:
                  - array
                  - 'null'
                description: Assisting staff for this item (optional).
                items:
                  type: object
                  properties:
                    staff_id:
                      type: integer
                      description: User ID of the assisting staff member.
                    duty:
                      type:
                        - string
                        - 'null'
                      description: Duty performed by the assisting staff member (optional).
                      maxLength: 255
                  required:
                    - staff_id
            required:
              - staff_id
              - itemable_type
              - itemable_id
              - quantity
              - unit_price
              - tax_rate
              - discount_amount
              - discount_percentage
          minItems: 1
      title: SaleUpdateRequest
    SaleResource:
      type: object
      properties:
        id:
          type: integer
        record_state:
          $ref: '#/components/schemas/RecordStateResource'
        tenant_id:
          type: integer
        user_id:
          type: integer
        customer_id:
          type:
            - integer
            - 'null'
        appointment_id:
          type:
            - integer
            - 'null'
        currency_id:
          type: integer
        exchange_rate:
          type: number
        notes:
          type:
            - string
            - 'null'
        status:
          type: string
        sale_date:
          type: string
          format: date-time
        total_price:
          type: number
        remaining_balance:
          type: number
        payments:
          type: object
          description: >-
            Collected amounts per payment method, in the sale's own currency.
            Methods outside

            the three named buckets land in `other`; the four add up to
            `total_collected`.
          properties:
            cash:
              type: number
            credit_card:
              type: number
            bank_account:
              type: number
            other:
              type: number
            total_collected:
              type: number
          required:
            - cash
            - credit_card
            - bank_account
            - other
            - total_collected
        default_invoice_account_id:
          type: string
          description: >-
            Invoice account to preselect when invoicing this sale: the doctor's
            preferred account,

            else the clinic default, else `null`. Only present on the sale
            detail endpoint.
        customer:
          $ref: '#/components/schemas/RelatedCustomerResource'
        user:
          $ref: '#/components/schemas/RelatedUserResource'
        currency:
          $ref: '#/components/schemas/RelatedCurrencyResource'
        items:
          anyOf:
            - type: array
              items:
                $ref: '#/components/schemas/SaleItemSummaryResource'
            - type: array
              items:
                $ref: '#/components/schemas/SaleItemResource'
        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
      required:
        - id
        - record_state
        - tenant_id
        - user_id
        - customer_id
        - appointment_id
        - currency_id
        - exchange_rate
        - notes
        - status
        - sale_date
        - total_price
        - remaining_balance
        - payments
        - items
        - created_at
        - updated_at
        - deleted_at
      title: SaleResource
    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
    RelatedCustomerResource:
      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'
        is_masked:
          type: boolean
          description: >-
            Whether the identity fields are masked because the viewer may not
            see this lead's patient.
        is_lead_stage:
          type: boolean
          description: >-
            Whether the person is still a lead (link to `/leads/{lead_id}`)
            rather than a patient (link to `/customers/{id}`).
        lead_id:
          type:
            - integer
            - 'null'
          description: >-
            The lead the person came from; kept after conversion, so check
            `is_lead_stage` before linking to it.
      required:
        - id
        - record_state
        - first_name
        - last_name
        - phone_number
        - email
        - is_masked
        - is_lead_stage
        - lead_id
      title: RelatedCustomerResource
    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
    RelatedCurrencyResource:
      type: object
      properties:
        id:
          type: integer
        code:
          type:
            - string
            - 'null'
        symbol:
          type:
            - string
            - 'null'
        name:
          type: string
      required:
        - id
        - code
        - symbol
        - name
      title: RelatedCurrencyResource
    SaleItemSummaryResource:
      type: object
      properties:
        order:
          type: integer
        itemable_type:
          type:
            - string
            - 'null'
        itemable_id:
          type:
            - integer
            - 'null'
        itemable_name:
          type: string
        quantity:
          type: number
        total_price:
          type: number
      required:
        - order
        - itemable_type
        - itemable_id
        - quantity
        - total_price
      title: SaleItemSummaryResource
    SaleItemResource:
      type: object
      properties:
        id:
          type: integer
        sale_id:
          type: integer
        staff_id:
          type:
            - integer
            - 'null'
        order:
          type: integer
        itemable_type:
          type:
            - string
            - 'null'
        itemable_id:
          type:
            - integer
            - 'null'
        warehouse_id:
          type:
            - integer
            - 'null'
        quantity:
          type: number
        tax_rate:
          type: number
        unit_price:
          type: number
        cost_price:
          type: number
        discount_amount:
          type: number
        discount_percentage:
          type: number
        sub_total:
          type: number
        total_discount:
          type: number
        total_tax:
          type: number
        total_price:
          type: number
        staff:
          $ref: '#/components/schemas/RelatedUserResource'
        itemable:
          anyOf:
            - $ref: '#/components/schemas/RelatedItemableResource'
            - type: 'null'
        assistants:
          type: array
          items:
            $ref: '#/components/schemas/SaleItemAssistantResource'
      required:
        - id
        - sale_id
        - staff_id
        - order
        - itemable_type
        - itemable_id
        - warehouse_id
        - quantity
        - tax_rate
        - unit_price
        - cost_price
        - discount_amount
        - discount_percentage
        - sub_total
        - total_discount
        - total_tax
        - total_price
      title: SaleItemResource
    RelatedImportSourceResource:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        company_logo:
          type: 'null'
      required:
        - id
        - name
        - company_logo
      title: RelatedImportSourceResource
    RelatedItemableResource:
      type: object
      properties:
        id:
          type: string
        name:
          type:
            - string
            - 'null'
      required:
        - id
        - name
      title: RelatedItemableResource
    SaleItemAssistantResource:
      type: object
      properties:
        id:
          type: integer
        sale_item_id:
          type: integer
        staff_id:
          type:
            - integer
            - 'null'
        duty:
          type:
            - string
            - 'null'
        staff:
          $ref: '#/components/schemas/RelatedUserResource'
      required:
        - id
        - sale_item_id
        - staff_id
        - duty
      title: SaleItemAssistantResource
  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.