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

# Apply discount code to subscription

> Applies an existing Shopify discount code to a subscription contract. The discount code must already exist in Shopify and be valid for subscription usage.

**Discount Application Process:**
- **Code Validation**: Verifies discount code exists in Shopify
- **Eligibility Check**: Ensures code is valid for subscription use
- **Contract Update**: Applies discount to subscription contract
- **Price Recalculation**: Updates subscription pricing with discount applied
- **Activity Logging**: Records discount application event

**Key Features:**
- **Existing Code Support**: Uses Shopify discount codes already created in admin
- **Automatic Validation**: Checks code validity and subscription eligibility
- **Immediate Application**: Discount applies to next billing cycle
- **Contract Synchronization**: Keeps Shopify contract in sync with discount

**Discount Code Requirements:**
- Must exist in Shopify admin
- Must be active and not expired
- Must be eligible for subscription purchases
- Usage limits must not be exceeded

**Use Cases:**
- Allow customers to apply promotional codes to existing subscriptions
- Customer service applying retention discounts
- Reward program integration with discount codes
- Referral program discount application
- Seasonal promotion code application
- Win-back campaign discount codes

**Returns:** Updated subscription contract object with discount applied

**Authentication:** Requires API key authentication via X-API-Key header or api_key parameter



## OpenAPI

````yaml /memberships/admin-api-swagger.json put /api/external/v2/subscription-contracts-apply-discount
openapi: 3.0.1
info:
  description: >-
    Comprehensive API documentation for managing memberships, payments, and
    related operations. These APIs allow you to programmatically manage
    membership lifecycles, handle payments, configure products, and integrate
    membership functionality into your applications.
  title: Admin APIs
  version: 0.0.1
servers:
  - url: https://membership-admin.appstle.com
security: []
tags:
  - description: >-
      APIs for managing Shopify delivery profiles, shipping rates, zones, and
      free shipping configuration for subscription memberships
    name: Shipping & Delivery Profiles
  - description: >-
      APIs for retrieving historical discount code usage and redemption
      information for membership contracts
    name: Customer Discount History
  - description: >-
      APIs for managing membership cancellation flow settings including
      retention offers, survey questions, and cancel confirmation screens
    name: Cancellation Flow Configuration
  - description: >-
      APIs for managing membership billing attempts, recurring orders, payment
      retries, order history, and order skipping
    name: Billing & Orders
  - description: >-
      APIs for managing one-time product additions to upcoming subscription
      orders, including adding, retrieving, and removing one-off items
    name: One-Time Add-Ons
  - description: >-
      APIs for managing membership/subscription plan groups, including creating
      plans, configuring discounts, billing intervals, and assigning products to
      plans
    name: Membership Plans
  - description: >-
      APIs for managing subscription product bundles, bundle configurations,
      item grouping, and bundle-specific discount codes
    name: Product Bundles
  - description: >-
      APIs for retrieving custom CSS styles applied to subscription widgets and
      customer portal for theme customization
    name: Custom CSS Styling
  - description: >-
      APIs for managing customer portal settings including UI customization,
      text labels, feature toggles, and branding options for the member
      self-service portal
    name: Customer Portal Configuration
  - description: >-
      APIs for managing membership/subscription contracts including creation,
      updates, status changes, line items, discounts, and billing operations
    name: Membership Contracts
  - description: >-
      APIs for managing subscription bundle configuration settings including
      bundle behavior, pricing rules, and display options
    name: Bundle Settings
  - description: >-
      APIs for managing customer payment methods, payment tokens, and payment
      method retrieval for subscriptions
    name: Customer Payment Methods
  - description: >-
      APIs for retrieving product swap/substitution options allowing members to
      exchange subscription items based on configured swap rules and variant
      groups
    name: Product Swap Rules
  - description: >-
      APIs for retrieving product catalog, variants, pricing, and inventory
      information for subscription memberships.
    name: Product & Inventory Data
  - description: >-
      APIs for managing shop-level membership settings, configuration, and
      general store information.
    name: Shop Settings
  - description: >-
      APIs for performing bulk/mass operations on multiple membership contracts
      including status updates, product replacements, and billing date changes.
    name: Bulk Operations
paths:
  /api/external/v2/subscription-contracts-apply-discount:
    put:
      tags:
        - Membership Contracts
      summary: Apply discount code to subscription
      description: >-
        Applies an existing Shopify discount code to a subscription contract.
        The discount code must already exist in Shopify and be valid for
        subscription usage.


        **Discount Application Process:**

        - **Code Validation**: Verifies discount code exists in Shopify

        - **Eligibility Check**: Ensures code is valid for subscription use

        - **Contract Update**: Applies discount to subscription contract

        - **Price Recalculation**: Updates subscription pricing with discount
        applied

        - **Activity Logging**: Records discount application event


        **Key Features:**

        - **Existing Code Support**: Uses Shopify discount codes already created
        in admin

        - **Automatic Validation**: Checks code validity and subscription
        eligibility

        - **Immediate Application**: Discount applies to next billing cycle

        - **Contract Synchronization**: Keeps Shopify contract in sync with
        discount


        **Discount Code Requirements:**

        - Must exist in Shopify admin

        - Must be active and not expired

        - Must be eligible for subscription purchases

        - Usage limits must not be exceeded


        **Use Cases:**

        - Allow customers to apply promotional codes to existing subscriptions

        - Customer service applying retention discounts

        - Reward program integration with discount codes

        - Referral program discount application

        - Seasonal promotion code application

        - Win-back campaign discount codes


        **Returns:** Updated subscription contract object with discount applied


        **Authentication:** Requires API key authentication via X-API-Key header
        or api_key parameter
      operationId: applyDiscountCodeV2
      parameters:
        - description: Subscription contract ID to apply discount to
          example: 123456789
          in: query
          name: contractId
          required: true
          schema:
            format: int64
            type: integer
        - description: API Key (Deprecated - Use Header X-API-Key instead)
          in: query
          name: api_key
          required: false
          schema:
            type: string
        - in: header
          name: X-API-Key
          required: false
          schema:
            type: string
        - description: Shopify discount code to apply
          example: SUMMER2024
          in: query
          name: discountCode
          required: true
          schema:
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SubscriptionContract'
          description: Discount code successfully applied to subscription
        '400':
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SubscriptionContract'
          description: Invalid discount code or not eligible for subscriptions
        '401':
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SubscriptionContract'
          description: Authentication required - invalid or missing API key
        '404':
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SubscriptionContract'
          description: Subscription contract or discount code not found
        '500':
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/SubscriptionContract'
          description: Shopify API error during discount application
components:
  schemas:
    SubscriptionContract:
      properties:
        billingAttempts:
          $ref: '#/components/schemas/BillingAttempts'
        billingPolicy:
          $ref: '#/components/schemas/BillingPolicy'
        createdAt:
          type: object
        customAttributes:
          items:
            $ref: '#/components/schemas/CustomAttribute1'
          type: array
        customer:
          $ref: '#/components/schemas/Customer'
        customerPaymentMethod:
          $ref: '#/components/schemas/CustomerPaymentMethod'
        deliveryMethod:
          $ref: '#/components/schemas/DeliveryMethod'
        deliveryPolicy:
          $ref: '#/components/schemas/DeliveryPolicy'
        deliveryPrice:
          $ref: '#/components/schemas/DeliveryPrice'
        discounts:
          $ref: '#/components/schemas/Discounts'
        get__typename:
          type: string
        id:
          type: string
        lastPaymentStatus:
          enum:
            - SUCCEEDED
            - FAILED
            - $UNKNOWN
          type: string
        lines:
          $ref: '#/components/schemas/Lines'
        nextBillingDate:
          type: object
        note:
          type: string
        originOrder:
          $ref: '#/components/schemas/OriginOrder'
        status:
          enum:
            - ACTIVE
            - PAUSED
            - CANCELLED
            - EXPIRED
            - FAILED
            - $UNKNOWN
          type: string
        updatedAt:
          type: object
      type: object
    BillingAttempts:
      properties:
        get__typename:
          type: string
        nodes:
          items:
            $ref: '#/components/schemas/Node3'
          type: array
      type: object
    BillingPolicy:
      properties:
        anchors:
          items:
            $ref: '#/components/schemas/Anchor'
          type: array
        get__typename:
          type: string
        interval:
          enum:
            - DAY
            - WEEK
            - MONTH
            - YEAR
            - $UNKNOWN
          type: string
        intervalCount:
          format: int32
          type: integer
        maxCycles:
          format: int32
          type: integer
        minCycles:
          format: int32
          type: integer
      type: object
    CustomAttribute1:
      properties:
        get__typename:
          type: string
        key:
          type: string
        value:
          type: string
      type: object
    Customer:
      properties:
        displayName:
          type: string
        email:
          deprecated: true
          type: string
        firstName:
          type: string
        get__typename:
          type: string
        id:
          type: string
        lastName:
          type: string
        phone:
          deprecated: true
          type: string
      type: object
    CustomerPaymentMethod:
      properties:
        get__typename:
          type: string
        id:
          type: string
        instrument:
          $ref: '#/components/schemas/Instrument'
        revokedAt:
          type: object
        revokedReason:
          enum:
            - AUTHORIZE_NET_GATEWAY_NOT_ENABLED
            - AUTHORIZE_NET_RETURNED_NO_PAYMENT_METHOD
            - FAILED_TO_UPDATE_CREDIT_CARD
            - STRIPE_API_AUTHENTICATION_ERROR
            - STRIPE_API_INVALID_REQUEST_ERROR
            - STRIPE_GATEWAY_NOT_ENABLED
            - STRIPE_RETURNED_NO_PAYMENT_METHOD
            - STRIPE_PAYMENT_METHOD_NOT_CARD
            - BRAINTREE_API_AUTHENTICATION_ERROR
            - BRAINTREE_GATEWAY_NOT_ENABLED
            - BRAINTREE_RETURNED_NO_PAYMENT_METHOD
            - BRAINTREE_PAYMENT_METHOD_NOT_CARD
            - PAYMENT_METHOD_VERIFICATION_FAILED
            - THREE_D_SECURE_FLOW_IN_VERIFICATION_NOT_IMPLEMENTED
            - MANUALLY_REVOKED
            - FAILED_TO_RETRIEVE_BILLING_ADDRESS
            - MERGED
            - CUSTOMER_REDACTED
            - TOO_MANY_CONSECUTIVE_FAILURES
            - CVV_ATTEMPTS_LIMIT_EXCEEDED
            - $UNKNOWN
          type: string
      type: object
    DeliveryMethod:
      properties:
        additionalInformation:
          $ref: '#/components/schemas/AdditionalInformation'
        brandedPromise:
          $ref: '#/components/schemas/BrandedPromise'
        get__typename:
          type: string
        id:
          type: string
        maxDeliveryDateTime:
          type: object
        methodType:
          enum:
            - SHIPPING
            - PICK_UP
            - NONE
            - RETAIL
            - LOCAL
            - PICKUP_POINT
            - $UNKNOWN
          type: string
        minDeliveryDateTime:
          type: object
        serviceCode:
          type: string
      type: object
    DeliveryPolicy:
      properties:
        anchors:
          items:
            $ref: '#/components/schemas/Anchor1'
          type: array
        get__typename:
          type: string
        interval:
          enum:
            - DAY
            - WEEK
            - MONTH
            - YEAR
            - $UNKNOWN
          type: string
        intervalCount:
          format: int32
          type: integer
      type: object
    DeliveryPrice:
      properties:
        amount:
          type: object
        currencyCode:
          enum:
            - USD
            - EUR
            - GBP
            - CAD
            - AFN
            - ALL
            - DZD
            - AOA
            - ARS
            - AMD
            - AWG
            - AUD
            - BBD
            - AZN
            - BDT
            - BSD
            - BHD
            - BIF
            - BYN
            - BZD
            - BMD
            - BTN
            - BAM
            - BRL
            - BOB
            - BWP
            - BND
            - BGN
            - MMK
            - KHR
            - CVE
            - KYD
            - XAF
            - CLP
            - CNY
            - COP
            - KMF
            - CDF
            - CRC
            - HRK
            - CZK
            - DKK
            - DJF
            - DOP
            - XCD
            - EGP
            - ERN
            - ETB
            - FKP
            - XPF
            - FJD
            - GIP
            - GMD
            - GHS
            - GTQ
            - GYD
            - GEL
            - GNF
            - HTG
            - HNL
            - HKD
            - HUF
            - ISK
            - INR
            - IDR
            - ILS
            - IRR
            - IQD
            - JMD
            - JPY
            - JEP
            - JOD
            - KZT
            - KES
            - KID
            - KWD
            - KGS
            - LAK
            - LVL
            - LBP
            - LSL
            - LRD
            - LYD
            - LTL
            - MGA
            - MKD
            - MOP
            - MWK
            - MVR
            - MRU
            - MXN
            - MYR
            - MUR
            - MDL
            - MAD
            - MNT
            - MZN
            - NAD
            - NPR
            - ANG
            - NZD
            - NIO
            - NGN
            - NOK
            - OMR
            - PAB
            - PKR
            - PGK
            - PYG
            - PEN
            - PHP
            - PLN
            - QAR
            - RON
            - RUB
            - RWF
            - WST
            - SHP
            - SAR
            - RSD
            - SCR
            - SLL
            - SGD
            - SDG
            - SOS
            - SYP
            - ZAR
            - KRW
            - SSP
            - SBD
            - LKR
            - SRD
            - SZL
            - SEK
            - CHF
            - TWD
            - THB
            - TJS
            - TZS
            - TOP
            - TTD
            - TND
            - TRY
            - TMT
            - UGX
            - UAH
            - AED
            - UYU
            - UZS
            - VUV
            - VES
            - VND
            - XOF
            - YER
            - ZMW
            - USDC
            - BYR
            - STD
            - STN
            - VED
            - VEF
            - XXX
            - $UNKNOWN
          type: string
        get__typename:
          type: string
      type: object
    Discounts:
      properties:
        get__typename:
          type: string
        nodes:
          items:
            $ref: '#/components/schemas/Node2'
          type: array
        pageInfo:
          $ref: '#/components/schemas/PageInfo2'
      type: object
    Lines:
      properties:
        get__typename:
          type: string
        nodes:
          items:
            $ref: '#/components/schemas/Node'
          type: array
        pageInfo:
          $ref: '#/components/schemas/PageInfo'
      type: object
    OriginOrder:
      properties:
        fulfillmentOrders:
          $ref: '#/components/schemas/FulfillmentOrders'
        get__typename:
          type: string
        id:
          type: string
        name:
          type: string
      type: object
    Node3:
      properties:
        completedAt:
          type: object
        createdAt:
          type: object
        get__typename:
          type: string
        id:
          type: string
        idempotencyKey:
          type: string
        ready:
          deprecated: true
          type: boolean
      type: object
    Anchor:
      properties:
        cutoffDay:
          format: int32
          type: integer
        day:
          format: int32
          type: integer
        get__typename:
          type: string
        month:
          format: int32
          type: integer
        type:
          enum:
            - WEEKDAY
            - MONTHDAY
            - YEARDAY
            - $UNKNOWN
          type: string
      type: object
    Instrument:
      properties:
        get__typename:
          type: string
      type: object
    AdditionalInformation:
      properties:
        get__typename:
          type: string
        instructions:
          type: string
      type: object
    BrandedPromise:
      properties:
        get__typename:
          type: string
        handle:
          type: string
        name:
          type: string
      type: object
    Anchor1:
      properties:
        cutoffDay:
          format: int32
          type: integer
        day:
          format: int32
          type: integer
        get__typename:
          type: string
        month:
          format: int32
          type: integer
        type:
          enum:
            - WEEKDAY
            - MONTHDAY
            - YEARDAY
            - $UNKNOWN
          type: string
      type: object
    Node2:
      properties:
        createdAt:
          type: object
        deliveredAt:
          type: object
        displayStatus:
          enum:
            - ATTEMPTED_DELIVERY
            - CANCELED
            - CONFIRMED
            - DELAYED
            - DELIVERED
            - FAILURE
            - FULFILLED
            - CARRIER_PICKED_UP
            - IN_TRANSIT
            - LABEL_PRINTED
            - LABEL_PURCHASED
            - LABEL_VOIDED
            - MARKED_AS_FULFILLED
            - NOT_DELIVERED
            - OUT_FOR_DELIVERY
            - READY_FOR_PICKUP
            - PICKED_UP
            - SUBMITTED
            - $UNKNOWN
          type: string
        estimatedDeliveryAt:
          type: object
        get__typename:
          type: string
        id:
          type: string
        inTransitAt:
          type: object
        name:
          type: string
        requiresShipping:
          type: boolean
        service:
          $ref: '#/components/schemas/Service'
        status:
          enum:
            - PENDING
            - OPEN
            - SUCCESS
            - CANCELLED
            - ERROR
            - FAILURE
            - $UNKNOWN
          type: string
        trackingInfo:
          items:
            $ref: '#/components/schemas/TrackingInfo'
          type: array
      type: object
    PageInfo2:
      properties:
        endCursor:
          type: string
        get__typename:
          type: string
        hasNextPage:
          type: boolean
        hasPreviousPage:
          type: boolean
        startCursor:
          type: string
      type: object
    Node:
      properties:
        get__typename:
          type: string
      type: object
    PageInfo:
      properties:
        endCursor:
          type: string
        get__typename:
          type: string
        hasNextPage:
          type: boolean
        hasPreviousPage:
          type: boolean
        startCursor:
          type: string
      type: object
    FulfillmentOrders:
      properties:
        get__typename:
          type: string
        nodes:
          items:
            $ref: '#/components/schemas/Node'
          type: array
        pageInfo:
          $ref: '#/components/schemas/PageInfo2'
      type: object
    Service:
      properties:
        get__typename:
          type: string
        handle:
          type: string
        serviceName:
          type: string
        type:
          enum:
            - GIFT_CARD
            - MANUAL
            - THIRD_PARTY
            - $UNKNOWN
          type: string
      type: object
    TrackingInfo:
      properties:
        company:
          type: string
        get__typename:
          type: string
        number:
          type: string
        url:
          type: object
      type: object

````