# Stripe API Integration
URL: /docs/affiliate-promo-codes/stripe-api
Description: Use the Stripe API directly for promo code tracking

# Overview

For custom checkout flows or mobile apps, you can use the Stripe API directly to apply affiliate promo codes.

This approach is particularly useful for mobile apps where traditional affiliate link tracking may be restricted by app stores.

## Implementation Steps

### 1. Retrieve the Promo Code ID

When a user enters a promo code on your checkout screen, call the [Stripe Promotion Codes API](https://stripe.com/docs/api/promotion_codes/list) to get the promo code ID. Use `stripe.promotionCodes.list` with the code parameter set to the entered code.

### 2. Apply to Subscription

When [creating a subscription](https://docs.stripe.com/api/subscriptions/create), include the `promotion_code` parameter with the promo code ID you retrieved:

```javascript
const subscription = await stripe.subscriptions.create({
  customer: 'cus_Na6dX7aXxi11N4',
  items: [
    {
      price: 'price_1MowQULkdIwHu7ixraBm864M',
    },
  ],
  promotion_code: 'promo_1MiM6KLkdIwHu7ixrIaX4wgn',
});
```

## Alternative: Update Existing Subscription

You can also apply promo codes to existing subscriptions using the [subscription update API](https://docs.stripe.com/api/subscriptions/update) with the `promotion_code` parameter.

Referral attribution works identically whether you apply the code at creation or update time.