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

# Update Sale

> Updates a sale identified by `saleId`, and fires the `sale.updated` webhook.

`commissionEarned` is handled separately from the other fields: it updates the commission record for the affiliate credited with the sale, not the sale itself. Every other field you send is applied directly to the sale, so sending a field that is not listed below will fail the request.



## OpenAPI

````yaml PUT /sales
openapi: 3.0.1
info:
  title: Referly API
  description: >-
    REST API for managing affiliates, referrals, sales, affiliate links, coupons
    and promotional codes in your Referly affiliate program.


    Every request must send `Authorization: Bearer <YOUR_API_KEY>`. The token is
    scoped to a single affiliate program, so no program ID is ever required in
    the request — every read and write is automatically limited to that program.


    Requests are rate limited per token, per endpoint and per method.
  version: 1.0.0
servers:
  - url: https://www.referly.so/api/v1
security:
  - bearerAuth: []
paths:
  /sales:
    put:
      summary: Update a sale
      description: >-
        Updates a sale identified by `saleId`, and fires the `sale.updated`
        webhook.


        `commissionEarned` is handled separately from the other fields: it
        updates the commission record for the affiliate credited with the sale,
        not the sale itself. Every other field you send is applied directly to
        the sale, so sending a field that is not listed below will fail the
        request.
      requestBody:
        description: Fields to update
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SaleUpdate'
        required: true
      responses:
        '200':
          description: The updated sale, including its recalculated `commissionEarned`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sale'
        '400':
          description: >-
            `saleId` was missing, or the request contained a field that cannot
            be updated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: No sale with that ID exists in this program.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  schemas:
    SaleUpdate:
      type: object
      required:
        - saleId
      properties:
        saleId:
          type: integer
          description: The sale to update
        name:
          type: string
          description: Name of the customer
        email:
          type: string
          format: email
          description: Email of the customer
        totalEarned:
          type: number
          format: float
          description: Gross value of the sale
        commissionRate:
          type: number
          format: float
          description: Commission rate recorded on the sale
        commissionEarned:
          type: number
          format: float
          description: >-
            Sets the commission recorded for the credited affiliate. Applied to
            the commission record rather than the sale.
        externalId:
          type: string
          description: The ID of this sale in your own system
        externalInvoiceId:
          type: string
          description: The ID of the invoice in your own system
        metadata:
          type: object
          description: Arbitrary JSON to attach to the sale
    Sale:
      type: object
      properties:
        id:
          type: integer
          format: int64
          description: The sale ID
        affiliateId:
          type: string
          format: uuid
          nullable: true
          description: The affiliate credited with this sale
        referralId:
          type: string
          format: uuid
          nullable: true
          description: The referral this sale belongs to
        affiliateProgramId:
          type: string
          format: uuid
          nullable: true
          description: The affiliate program this sale belongs to
        affiliateLinkId:
          type: string
          format: uuid
          nullable: true
          description: The affiliate link the sale was attributed to
        promotionalCodeId:
          type: string
          format: uuid
          nullable: true
          description: The promotional code used on this sale, if any
        externalId:
          type: string
          nullable: true
          description: The ID of this sale in your own system. Unique per program.
        externalInvoiceId:
          type: string
          nullable: true
          description: The ID of the invoice in your own system. Unique per program.
        name:
          type: string
          nullable: true
          description: Name of the customer
        email:
          type: string
          format: email
          nullable: true
          description: Email of the customer
        totalEarned:
          type: number
          format: float
          description: Gross value of the sale
        commissionRate:
          type: number
          format: float
          nullable: true
          description: Commission rate applied to this sale
        commissionEarned:
          type: number
          format: float
          nullable: true
          description: >-
            Commission recorded for the credited affiliate. Merged in by the API
            from the sale's commission record — it is not a column on the sale
            itself.
        taxAmount:
          type: number
          format: float
          description: Tax deducted before commission was calculated
        shippingAmount:
          type: number
          format: float
          description: Shipping deducted before commission was calculated
        productsBought:
          type: array
          items:
            type: string
          description: Product identifiers attached to this sale
        clicks:
          type: integer
          description: Clicks attributed to this sale
        status:
          type: string
          enum:
            - ACTIVE
            - REFUNDED
          description: Whether the sale is live or has been refunded
        refundedAt:
          type: string
          format: date-time
          nullable: true
          description: When the sale was marked refunded
        paymentTrigger:
          type: string
          enum:
            - SIGNUP
            - PURCHASE
            - BONUS
            - CONTENT_REWARD
          description: What triggered the commission for this sale
        source:
          type: string
          enum:
            - UNKNOWN
            - API
            - INTEGRATION
            - MANUAL
            - IMPORTED
            - AUTOMATED
          description: Where the sale came from. Sales created through this API have `API`.
        metadata:
          type: object
          nullable: true
          description: Arbitrary JSON you can attach to the sale
        createdAt:
          type: string
          format: date-time
          description: When the sale was recorded
    Error:
      type: object
      properties:
        error:
          type: string
          description: Human readable description of what went wrong
  responses:
    Unauthorized:
      description: >-
        The `Authorization` header is missing, is not a `Bearer` header, or the
        token is not valid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: API access is not enabled for this account.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimited:
      description: Too many requests for this token on this endpoint. Please slow down.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````