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

# Update Reward

> Update a coupon or feature grant. Omitted fields keep their current value.

export const DynamicResponseExample = ({json, statusCode = "200"}) => {
  const toCamelCase = str => {
    return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
  };
  const convertKeysToCamelCase = obj => {
    if (Array.isArray(obj)) {
      return obj.map(item => convertKeysToCamelCase(item));
    }
    if (obj !== null && typeof obj === "object") {
      return Object.keys(obj).reduce((acc, key) => {
        const camelKey = toCamelCase(key);
        acc[camelKey] = convertKeysToCamelCase(obj[key]);
        return acc;
      }, {});
    }
    return obj;
  };
  const [isTypeScript, setIsTypeScript] = useState(() => {
    if (typeof window !== "undefined") {
      try {
        const lang = localStorage.getItem("code");
        return JSON.parse(lang) === "typescript";
      } catch {
        return true;
      }
    }
    return true;
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      if (event.detail?.key === "code") {
        try {
          const value = JSON.parse(event.detail.value);
          setIsTypeScript(value === "typescript");
        } catch {}
      }
    };
    const pollInterval = setInterval(() => {
      try {
        const lang = localStorage.getItem("code");
        const value = JSON.parse(lang);
        setIsTypeScript(value === "typescript");
      } catch {}
    }, 300);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, []);
  const camelCaseJson = useMemo(() => convertKeysToCamelCase(json), [json]);
  const snakeCaseString = JSON.stringify(json, null, 2);
  const camelCaseString = JSON.stringify(camelCaseJson, null, 2);
  return <ResponseExample>
			{isTypeScript ? <CodeBlock language="json" filename={statusCode}>
					{camelCaseString}
				</CodeBlock> : <CodeBlock language="json" filename={statusCode}>
					{snakeCaseString}
				</CodeBlock>}
		</ResponseExample>;
};

export const DynamicResponseField = ({children, name, ...props}) => {
  const convertToCamelCase = str => {
    if (typeof str !== "string") return str;
    return str.replace(/[_-](\w)/g, (_, c) => c.toUpperCase());
  };
  const [lang, setLang] = useState(() => {
    if (typeof window !== "undefined") {
      const stored = localStorage.getItem("code");
      return stored || '"typescript"';
    }
    return '"typescript"';
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      const key = event.detail?.key;
      if (key === "code") {
        setLang(event.detail.value);
      }
    };
    const pollInterval = setInterval(() => {
      const current = localStorage.getItem("code");
      if (current && current !== lang) {
        setLang(current);
      }
    }, 500);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, [lang]);
  const resolvedName = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(name) : name;
    } catch {
      return name;
    }
  }, [name, lang]);
  return <ResponseField name={resolvedName} {...props}>
			{children}
		</ResponseField>;
};

export const DynamicParamField = ({children, body, path, ...props}) => {
  const convertToCamelCase = str => {
    if (typeof str !== "string") return str;
    return str.replace(/[_-](\w)/g, (_, c) => c.toUpperCase());
  };
  const [lang, setLang] = useState(() => {
    if (typeof window !== "undefined") {
      const stored = localStorage.getItem("code");
      return stored || '"typescript"';
    }
    return '"typescript"';
  });
  useEffect(() => {
    const onMintlifyStorage = event => {
      const key = event.detail?.key;
      if (key === "code") {
        setLang(event.detail.value);
      }
    };
    const pollInterval = setInterval(() => {
      const current = localStorage.getItem("code");
      if (current && current !== lang) {
        setLang(current);
      }
    }, 500);
    document.addEventListener("mintlify-localstorage", onMintlifyStorage);
    return () => {
      document.removeEventListener("mintlify-localstorage", onMintlifyStorage);
      clearInterval(pollInterval);
    };
  }, [lang]);
  const resolvedBody = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(body) : body;
    } catch {
      return body;
    }
  }, [body, lang]);
  const resolvedPath = useMemo(() => {
    try {
      const value = JSON.parse(lang);
      const useCamelCase = value === "typescript";
      return useCamelCase ? convertToCamelCase(path) : path;
    } catch {
      return path;
    }
  }, [path, lang]);
  return <ParamField body={resolvedBody} path={resolvedPath} {...props}>
			{children}
		</ParamField>;
};

### Body Parameters

<DynamicParamField body="reward_id" type="string" required>
  The ID of the coupon or feature grant.
</DynamicParamField>

<DynamicParamField body="coupon" type="object">
  <Expandable title="properties">
    <DynamicParamField body="name" type="string" />

    <DynamicParamField body="plan_ids" type="string[] | null">
      Plan IDs must be unique. Null applies the coupon to all plans.
    </DynamicParamField>

    <DynamicParamField body="promo_codes" type="object[]">
      Replaces the existing promo codes when provided.

      <Expandable title="properties">
        <DynamicParamField body="code" type="string" required />

        <DynamicParamField body="global_max_redemption" type="integer | null" />

        <DynamicParamField body="first_time_transaction" type="boolean | null" />
      </Expandable>
    </DynamicParamField>
  </Expandable>
</DynamicParamField>

<DynamicParamField body="feature_grant" type="object">
  <Expandable title="properties">
    <DynamicParamField body="name" type="string" />

    <DynamicParamField body="grants" type="object[]">
      Replaces the existing grants when provided.

      <Expandable title="properties">
        <DynamicParamField body="feature_id" type="string" required />

        <DynamicParamField body="included" type="number | null" required />

        <DynamicParamField body="expiry" type="object | null" required>
          How long the granted amount lasts before expiring, or null for a permanent grant.

          <Expandable title="properties">
            <DynamicParamField body="type" type="'day' | 'week' | 'month' | 'year'" required>
              The unit of time the grant lasts.
            </DynamicParamField>

            <DynamicParamField body="length" type="integer" required>
              The positive integer count of periods before the grant expires.
            </DynamicParamField>
          </Expandable>
        </DynamicParamField>
      </Expandable>
    </DynamicParamField>

    <DynamicParamField body="promo_codes" type="object[]">
      Replaces the existing promo codes when provided.

      <Expandable title="properties">
        <DynamicParamField body="code" type="string" required />

        <DynamicParamField body="max_uses" type="integer | null" required />
      </Expandable>
    </DynamicParamField>
  </Expandable>
</DynamicParamField>

### Response

<DynamicResponseField name="coupon" type="object">
  <Expandable title="properties">
    <DynamicResponseField name="id" type="string">
      The unique identifier for the coupon.
    </DynamicResponseField>

    <DynamicResponseField name="name" type="string | null">
      A human-readable name for the coupon.
    </DynamicResponseField>

    <DynamicResponseField name="type" type="'percentage_discount' | 'fixed_discount' | 'invoice_credits'">
      The type of discount: percentage\_discount, fixed\_discount, or invoice\_credits.
    </DynamicResponseField>

    <DynamicResponseField name="value" type="number">
      The discount value. A percentage for percentage\_discount, or an amount for fixed\_discount / invoice\_credits.
    </DynamicResponseField>

    <DynamicResponseField name="duration" type="object">
      How long the coupon applies once redeemed.

      <Expandable title="properties">
        <DynamicResponseField name="type" type="'one_off' | 'months' | 'forever'">
          The unit of time the duration is measured in.
        </DynamicResponseField>

        <DynamicResponseField name="length" type="number | null">
          The number of `type` periods the duration lasts, or null when the type has no length (e.g. one\_off, forever).
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="plan_ids" type="string[] | null">
      The plan IDs the coupon applies to, or null when it applies to all plans.
    </DynamicResponseField>

    <DynamicResponseField name="promo_codes" type="object[]">
      <Expandable title="properties">
        <DynamicResponseField name="code" type="string">
          The promo code customers enter to redeem the coupon.
        </DynamicResponseField>

        <DynamicResponseField name="global_max_redemption" type="number | null">
          Maximum number of times this promo code can be redeemed across all customers, or null for unlimited.
        </DynamicResponseField>

        <DynamicResponseField name="first_time_transaction" type="boolean | null">
          Whether this promo code can only be applied to a customer's first transaction.
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="created_at" type="number">
      The Unix timestamp (in milliseconds) when the coupon was created.
    </DynamicResponseField>
  </Expandable>
</DynamicResponseField>

<DynamicResponseField name="feature_grant" type="object">
  <Expandable title="properties">
    <DynamicResponseField name="id" type="string">
      The unique identifier for the feature grant.
    </DynamicResponseField>

    <DynamicResponseField name="name" type="string | null">
      A human-readable name for the feature grant.
    </DynamicResponseField>

    <DynamicResponseField name="grants" type="object[]">
      <Expandable title="properties">
        <DynamicResponseField name="feature_id" type="string">
          The feature ID this grant applies to.
        </DynamicResponseField>

        <DynamicResponseField name="included" type="number | null">
          The amount of the feature granted, or null for boolean features.
        </DynamicResponseField>

        <DynamicResponseField name="expiry" type="object | null">
          How long the granted amount lasts before expiring, or null for a permanent grant.

          <Expandable title="properties">
            <DynamicResponseField name="type" type="'day' | 'week' | 'month' | 'year'">
              The unit of time the grant lasts.
            </DynamicResponseField>

            <DynamicResponseField name="length" type="integer">
              The positive integer count of periods before the grant expires.
            </DynamicResponseField>
          </Expandable>
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="promo_codes" type="object[]">
      <Expandable title="properties">
        <DynamicResponseField name="code" type="string">
          The promo code customers enter to redeem the feature grant.
        </DynamicResponseField>

        <DynamicResponseField name="max_uses" type="number | null">
          Maximum number of times this promo code can be redeemed, or null for unlimited.
        </DynamicResponseField>
      </Expandable>
    </DynamicResponseField>

    <DynamicResponseField name="created_at" type="number">
      The Unix timestamp (in milliseconds) when the feature grant was created.
    </DynamicResponseField>
  </Expandable>
</DynamicResponseField>

<ResponseExample>
  ```json 200 theme={null}
  {
    "feature_grant": {
      "id": "beta_credits_grant",
      "name": "Beta Tester Credits",
      "promo_codes": [
        {
          "code": "BETA2024",
          "max_uses": 500
        }
      ],
      "grants": [
        {
          "feature_id": "credits",
          "included": 1000,
          "expiry": {
            "type": "month",
            "length": 1
          }
        }
      ],
      "created_at": 1718000000000
    }
  }
  ```
</ResponseExample>


## OpenAPI

````yaml openapi POST /v1/rewards.update
openapi: 3.1.0
info:
  title: Autumn API
  version: 2.3.0
servers:
  - url: https://api.useautumn.com
    description: Production server
security:
  - secretKey: []
paths:
  /v1/rewards.update:
    post:
      tags:
        - rewards
      description: >-
        Update a coupon or feature grant. Omitted fields keep their current
        value.
      operationId: updateReward
      parameters:
        - name: x-api-version
          in: header
          required: true
          schema:
            type: string
            default: 2.3.0
          x-speakeasy-globals-hidden: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                reward_id:
                  type: string
                  minLength: 1
                  description: The ID of the coupon or feature grant.
                coupon:
                  type: object
                  properties:
                    name:
                      type: string
                      minLength: 1
                    plan_ids:
                      anyOf:
                        - type: array
                          minItems: 1
                          items:
                            type: string
                            minLength: 1
                        - type: 'null'
                      description: >-
                        Plan IDs must be unique. Null applies the coupon to all
                        plans.
                    promo_codes:
                      type: array
                      items:
                        type: object
                        properties:
                          code:
                            type: string
                            minLength: 1
                          global_max_redemption:
                            anyOf:
                              - type: integer
                                minimum: -9007199254740991
                                maximum: 9007199254740991
                                exclusiveMinimum: 0
                              - type: 'null'
                          first_time_transaction:
                            anyOf:
                              - type: boolean
                              - type: 'null'
                        required:
                          - code
                        additionalProperties: false
                      description: Replaces the existing promo codes when provided.
                  additionalProperties: false
                  title: UpdateRewardCouponRequest
                feature_grant:
                  type: object
                  properties:
                    name:
                      type: string
                      minLength: 1
                    grants:
                      type: array
                      minItems: 1
                      items:
                        type: object
                        properties:
                          feature_id:
                            type: string
                            minLength: 1
                          included:
                            anyOf:
                              - type: number
                                exclusiveMinimum: 0
                              - type: 'null'
                          expiry:
                            anyOf:
                              - type: object
                                properties:
                                  type:
                                    enum:
                                      - day
                                      - week
                                      - month
                                      - year
                                    type: string
                                    description: The unit of time the grant lasts.
                                  length:
                                    type: integer
                                    minimum: -9007199254740991
                                    maximum: 9007199254740991
                                    exclusiveMinimum: 0
                                    description: >-
                                      The positive integer count of periods
                                      before the grant expires.
                                required:
                                  - type
                                  - length
                              - type: 'null'
                            description: >-
                              How long the granted amount lasts before expiring,
                              or null for a permanent grant.
                        required:
                          - feature_id
                          - included
                          - expiry
                        additionalProperties: false
                      description: Replaces the existing grants when provided.
                    promo_codes:
                      type: array
                      minItems: 1
                      items:
                        type: object
                        properties:
                          code:
                            type: string
                            minLength: 1
                          max_uses:
                            anyOf:
                              - type: integer
                                minimum: -9007199254740991
                                maximum: 9007199254740991
                                exclusiveMinimum: 0
                              - type: 'null'
                        required:
                          - code
                          - max_uses
                        additionalProperties: false
                      description: Replaces the existing promo codes when provided.
                  additionalProperties: false
                  title: UpdateRewardFeatureGrantRequest
              required:
                - reward_id
              additionalProperties: false
              title: UpdateRewardParams
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  coupon:
                    type: object
                    properties:
                      id:
                        type: string
                        description: The unique identifier for the coupon.
                      name:
                        anyOf:
                          - type: string
                          - type: 'null'
                        description: A human-readable name for the coupon.
                      type:
                        enum:
                          - percentage_discount
                          - fixed_discount
                          - invoice_credits
                        type: string
                        description: >-
                          The type of discount: percentage_discount,
                          fixed_discount, or invoice_credits.
                      value:
                        type: number
                        description: >-
                          The discount value. A percentage for
                          percentage_discount, or an amount for fixed_discount /
                          invoice_credits.
                      duration:
                        type: object
                        properties:
                          type:
                            enum:
                              - one_off
                              - months
                              - forever
                            type: string
                            description: The unit of time the duration is measured in.
                          length:
                            anyOf:
                              - type: number
                              - type: 'null'
                            description: >-
                              The number of `type` periods the duration lasts,
                              or null when the type has no length (e.g. one_off,
                              forever).
                        required:
                          - type
                          - length
                        description: How long the coupon applies once redeemed.
                      plan_ids:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          The plan IDs the coupon applies to, or null when it
                          applies to all plans.
                      promo_codes:
                        type: array
                        items:
                          type: object
                          properties:
                            code:
                              type: string
                              description: >-
                                The promo code customers enter to redeem the
                                coupon.
                            global_max_redemption:
                              anyOf:
                                - type: number
                                - type: 'null'
                              description: >-
                                Maximum number of times this promo code can be
                                redeemed across all customers, or null for
                                unlimited.
                            first_time_transaction:
                              anyOf:
                                - type: boolean
                                - type: 'null'
                              description: >-
                                Whether this promo code can only be applied to a
                                customer's first transaction.
                          required:
                            - code
                      created_at:
                        type: number
                        description: >-
                          The Unix timestamp (in milliseconds) when the coupon
                          was created.
                    required:
                      - id
                      - type
                      - value
                      - duration
                      - plan_ids
                      - promo_codes
                      - created_at
                  feature_grant:
                    type: object
                    properties:
                      id:
                        type: string
                        description: The unique identifier for the feature grant.
                      name:
                        anyOf:
                          - type: string
                          - type: 'null'
                        description: A human-readable name for the feature grant.
                      grants:
                        type: array
                        items:
                          type: object
                          properties:
                            feature_id:
                              type: string
                              description: The feature ID this grant applies to.
                            included:
                              anyOf:
                                - type: number
                                - type: 'null'
                              description: >-
                                The amount of the feature granted, or null for
                                boolean features.
                            expiry:
                              anyOf:
                                - type: object
                                  properties:
                                    type:
                                      enum:
                                        - day
                                        - week
                                        - month
                                        - year
                                      type: string
                                      description: The unit of time the grant lasts.
                                    length:
                                      type: integer
                                      minimum: -9007199254740991
                                      maximum: 9007199254740991
                                      exclusiveMinimum: 0
                                      description: >-
                                        The positive integer count of periods
                                        before the grant expires.
                                  required:
                                    - type
                                    - length
                                - type: 'null'
                              description: >-
                                How long the granted amount lasts before
                                expiring, or null for a permanent grant.
                          required:
                            - feature_id
                            - included
                            - expiry
                      promo_codes:
                        type: array
                        items:
                          type: object
                          properties:
                            code:
                              type: string
                              description: >-
                                The promo code customers enter to redeem the
                                feature grant.
                            max_uses:
                              anyOf:
                                - type: number
                                - type: 'null'
                              description: >-
                                Maximum number of times this promo code can be
                                redeemed, or null for unlimited.
                          required:
                            - code
                            - max_uses
                      created_at:
                        type: number
                        description: >-
                          The Unix timestamp (in milliseconds) when the feature
                          grant was created.
                    required:
                      - id
                      - grants
                      - promo_codes
                      - created_at
                additionalProperties: false
                title: UpdateRewardResponse
                examples:
                  - feature_grant:
                      id: beta_credits_grant
                      name: Beta Tester Credits
                      promo_codes:
                        - code: BETA2024
                          max_uses: 500
                      grants:
                        - feature_id: credits
                          included: 1000
                          expiry:
                            type: month
                            length: 1
                      created_at: 1718000000000
              example:
                feature_grant:
                  id: beta_credits_grant
                  name: Beta Tester Credits
                  promo_codes:
                    - code: BETA2024
                      max_uses: 500
                  grants:
                    - feature_id: credits
                      included: 1000
                      expiry:
                        type: month
                        length: 1
                  created_at: 1718000000000
      x-codeSamples:
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { Autumn } from 'autumn-js'

            const autumn = new Autumn()

            const result = await autumn.rewards.update({
              rewardId: "<id>",
            });
        - lang: python
          label: Python (SDK)
          source: |-
            from autumn_sdk import Autumn

            autumn = Autumn(secret_key="am_sk_test...")

            res = autumn.rewards.update(reward_id="<id>")
components:
  securitySchemes:
    secretKey:
      type: http
      scheme: bearer
      bearerFormat: JWT

````