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

# Set a campaign's commission rule

> A campaign carries multiple rules. With no scope this creates/updates the
campaign's **catch-all** rule; `product_ids` scopes the rule to those
Stripe products; `billing_interval` scopes it to a billing cadence (one
scope type per rule). Conversion-time precedence: product → interval →
catch-all → nothing.

`amount` is a percentage (0–100) unless `type` is `flat`. `duration`
controls recurrence: `lifetime` pays every renewal, `first_order` pays
only the first payment, `capped` pays for `length_months` periods.

Set `reward_type` to `non_cash` (with a `unit`, e.g. `credits`) to pay a
non-cash reward — credits / points / free months delivered via the
fulfilment webhook, never cash — at **any** scope; `amount` is then the
count of units and `type` is ignored. Requires `write` (or `*`) scope.
Configuration only — never moves money.




## OpenAPI

````yaml /openapi.yaml put /v1/campaigns/{id}/commission-rule
openapi: 3.1.0
info:
  title: Affixo API
  version: 1.0.0
  description: |
    The Affixo REST API for affiliate program management and server-to-server
    conversion tracking.

    All requests authenticate with a workspace key (`sa_live_…`) as a Bearer
    token. Scopes: `read` / `write` / `track` / `*`.

    Rate limit: 600 req/min per key (enforced at the edge).
servers:
  - url: https://go.affixo.dev
    description: Production
security: []
tags:
  - name: Affiliates
    description: Manage affiliates (workspace key)
  - name: Campaigns
    description: Create and configure campaigns + commission rules (workspace key)
  - name: Links
    description: Manage referral links (workspace key)
  - name: Risk
    description: AI risk assessments for fraud triage (workspace key)
  - name: Commissions
    description: Approve, deny, and manage commissions (workspace key)
  - name: Conversions
    description: Re-attribute and manage conversions (workspace key)
  - name: Webhooks
    description: Manage webhook endpoint subscriptions (workspace key)
  - name: Reports
    description: Aggregated reporting data (workspace key)
  - name: Resources
    description: Read campaigns, commissions, conversions, payouts (workspace key)
  - name: Tracking
    description: >-
      Server-to-server click & conversion tracking (workspace key, scope
      "track")
paths:
  /v1/campaigns/{id}/commission-rule:
    put:
      tags:
        - Campaigns
      summary: Set a campaign's commission rule
      description: >
        A campaign carries multiple rules. With no scope this creates/updates
        the

        campaign's **catch-all** rule; `product_ids` scopes the rule to those

        Stripe products; `billing_interval` scopes it to a billing cadence (one

        scope type per rule). Conversion-time precedence: product → interval →

        catch-all → nothing.


        `amount` is a percentage (0–100) unless `type` is `flat`. `duration`

        controls recurrence: `lifetime` pays every renewal, `first_order` pays

        only the first payment, `capped` pays for `length_months` periods.


        Set `reward_type` to `non_cash` (with a `unit`, e.g. `credits`) to pay a

        non-cash reward — credits / points / free months delivered via the

        fulfilment webhook, never cash — at **any** scope; `amount` is then the

        count of units and `type` is ignored. Requires `write` (or `*`) scope.

        Configuration only — never moves money.
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                amount:
                  type: number
                  exclusiveMinimum: 0
                  description: >-
                    Percentage (0–100), a flat amount when type=flat, or the
                    count of units when reward_type=non_cash. Required unless
                    library_reward_id is passed.
                library_reward_id:
                  type: string
                  format: uuid
                  description: >-
                    Author the rate FROM a reusable library reward (GET
                    /v1/rewards) instead of inline values — copies the
                    template's terms onto the campaign (copy-on-assign).
                type:
                  type: string
                  enum:
                    - percent
                    - flat
                  default: percent
                  description: Ignored for non-cash rewards.
                reward_type:
                  type: string
                  enum:
                    - cash
                    - non_cash
                  default: cash
                  description: >-
                    cash = a monetary commission; non_cash pays credits / points
                    / free months via the fulfilment webhook.
                unit:
                  type: string
                  description: >-
                    Non-cash unit label (e.g. credits, points, free months).
                    Required when reward_type=non_cash.
                  example: credits
                duration:
                  type: string
                  enum:
                    - lifetime
                    - first_order
                    - capped
                  default: lifetime
                length_months:
                  type: integer
                  minimum: 1
                  description: Required when duration is capped.
                product_ids:
                  type: array
                  items:
                    type: string
                  description: >-
                    Stripe product ids (prod_…) or Affixo product uuids to scope
                    this rule to. Mutually exclusive with billing_interval; omit
                    for the catch-all.
                billing_interval:
                  type: string
                  enum:
                    - one_time
                    - month
                    - year
                  description: >-
                    Scope the rule to a billing cadence. Mutually exclusive with
                    product_ids.
      responses:
        '200':
          description: Updated commission rule
          content:
            application/json:
              schema:
                type: object
                properties:
                  object:
                    type: string
                    example: commission_rule
                  campaign:
                    type: string
                  data:
                    $ref: '#/components/schemas/CommissionRule'
        '201':
          description: Created commission rule
          content:
            application/json:
              schema:
                type: object
                properties:
                  object:
                    type: string
                    example: commission_rule
                  campaign:
                    type: string
                  data:
                    $ref: '#/components/schemas/CommissionRule'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/InsufficientScope'
        '404':
          $ref: '#/components/responses/NotFound'
      security:
        - WorkspaceKey: []
components:
  schemas:
    CommissionRule:
      type: object
      description: A campaign's promoter-side reward (the rate affiliates earn).
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
          example: Default commission
        kind:
          type: string
          enum:
            - monetary
            - other
            - exclude
          description: >-
            monetary = cash commission; other = a non-cash reward (credits /
            points / free months) whose value + unit ride in name; exclude = a
            dashboard-authored 'pay nothing on these products' rule (amount 0).
        amount:
          type: number
          description: >-
            Percentage (0–100) when is_flat=false, else a flat amount (or a
            count of units for a non-cash reward).
        is_flat:
          type: boolean
        length_type:
          type: string
          enum:
            - lifetime
            - first_order
            - capped
        length_months:
          type: integer
          nullable: true
          description: Only when length_type=capped.
        applies_to_interval:
          type: string
          nullable: true
          enum:
            - one_time
            - month
            - year
          description: >-
            The rule's billing-cadence scope, or null for an
            unscoped/product-scoped rule.
        product_ids:
          type: array
          items:
            type: string
          description: >-
            Stripe product ids this rule is scoped to (empty for an unscoped or
            interval-scoped rule).
    Error:
      type: object
      properties:
        error:
          type: string
        need:
          type: string
          description: Present on insufficient_scope.
        detail:
          type: string
  responses:
    BadRequest:
      description: Invalid or missing parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: invalid_json
    Unauthorized:
      description: Missing or invalid bearer token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: unauthorized
    InsufficientScope:
      description: The key lacks the required scope
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: insufficient_scope
            need: write
    NotFound:
      description: Resource not found / not in workspace
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: link_not_found
  securitySchemes:
    WorkspaceKey:
      type: http
      scheme: bearer
      description: 'Workspace API key, e.g. `sa_live_…`. Scopes: read / write / track / *.'

````