Apply discount code to subscription
Applies a Shopify discount code to an existing subscription contract. The discount will be applied to future orders generated by this subscription.
Key Features:
- Validates discount code through Shopify’s discount system
- Prevents duplicate discount code applications
- Uses database locking to prevent race conditions
- Automatically recalculates shipping prices if needed
- Creates audit trail through activity logs
- Returns updated subscription with discount details
Discount Code Validation:
- Must be an active Shopify discount code in the store
- Must be applicable to subscription orders
- Cannot be applied if already active on the subscription
- Subject to Shopify’s discount rules and restrictions
Customer Portal Restrictions: When called from customer portal context:
- If ‘enableAllowOnlyOneDiscountCode’ is enabled, customers cannot apply additional codes
- This restriction ensures single discount policy enforcement
- External API calls bypass this restriction
Concurrency Protection:
- Uses database-level locking on the subscription contract
- Prevents simultaneous discount applications
- Ensures data consistency in high-traffic scenarios
Post-Application Effects:
- Discount applies to all future orders from the subscription
- May trigger shipping price recalculation
- Creates ‘DISCOUNT_APPLIED’ activity log entry
- Updates subscription’s discount collection
Important Notes:
- Discount codes are case-sensitive
- Invalid or expired codes will return appropriate errors
- Discounts stack according to Shopify’s combination rules
- Some discounts may not be compatible with subscriptions
Authentication: Requires valid X-API-Key header
Headers
API Key for authentication
Query Parameters
Subscription contract ID to apply discount to. Provide the numeric ID without the gid:// prefix
x >= 1API Key (Deprecated - Use X-API-Key header instead)
Valid Shopify discount code to apply. Case-sensitive. Must be an active discount code in your Shopify store.
1 - 255^[A-Za-z0-9_-]+$Response
Discount code successfully applied
SUCCEEDED, FAILED, $UNKNOWN ACTIVE, PAUSED, CANCELLED, EXPIRED, FAILED, $UNKNOWN