Frontend API

Manage subscriptions associated with the logged-in customer's account.

Return a list of active and canceled subscriptions for an account.

Returns all subscriptions, with offset pagination using limit and page.

List subscriptions
await swell.subscriptions.list()

Return a single subscription by ID.

Get a subscription
await swell.subscriptions.get(id)

Subscribe the customer to a new product for recurring billing.

Create a new subscription
await swell.subscriptions.create({
  product_id: '5c15505200c7d14d851e510f',
  // the following parameters are optional
  variant_id: '5c15505200c7d14d851e510g',
  quantity: 1,
  coupon_code: '10PERCENTOFF',
  items: [
    {
      product_id: '5c15505200c7d14d851e510h',
      quantity: 1
    }
  ]
})

Updates a single subscription.

Update a subscription
await swell.subscriptions.update('5c15505200c7d14d851e510f', {
  // the following parameters are optional
  quantity: 2,
  coupon_code: '10PERCENTOFF',
  items: [
    {
      product_id: '5c15505200c7d14d851e510h',
      quantity: 1
    }
  ]
})

Changes a single subscription plan.

Change subscription plan
await swell.subscriptions.update('5c15505200c7d14d851e510f', {
  product_id: '5c15505200c7d14d851e510g',
  variant_id: '5c15505200c7d14d851e510h', // optional
  quantity: 2
})

Pauses a subscription indefinitely or skip a billing cycle.

Pause a subscription
// Pause immediately and indefinitely
await swell.subscriptions.update(subscription.id, {
    paused: true,
    date_pause_end: null,
})

// Skip a subscription cycle
await swell.subscriptions.update(subscription.id, {
    paused: true,
    date_pause_end: dateToResumeSubscription,
})

Cancel a single subscription.

Cancel a subscription
await swell.subscriptions.update('5c15505200c7d14d851e510f', {
  canceled: true
})

Add an invoice item to a subscription.

Add an invoice item
await swell.subscriptions.addItem('5c15505200c7d14d851e510f', {
  product_id: '5c15505200c7d14d851e510f',
  quantity: 1,
  options: [
    {
      id: 'color',
      value: 'Blue'
    }
  ]
})

Update an invoice item on a subscription.

Update an invoice item
await swell.subscriptions.updateItem('5c15505200c7d14d851e510f', '<item_id>', {
  quantity: 2
})

Update all invoice items on a subscription.

Update all invoice items
await swell.subscriptions.setItems('5c15505200c7d14d851e510e', [
  {
    id: '5c15505200c7d14d851e510f',
    quantity: 2,
    options: [
      {
        id: 'color',
        value: 'Blue'
      }
    ]
  },
  {
    id: '5c15505200c7d14d851e510g',
    quantity: 3,
    options: [
      {
        id: 'color',
        value: 'Red'
      }
    ]
  },
  {
    id: '5c15505200c7d14d851e510h',
    quantity: 4,
    options: [
      {
        id: 'color',
        value: 'White'
      }
    ]
  }
])

Remove an item from a subscription.

Remove an item
await swell.subscriptions.removeItem('5c15505200c7d14d851e510f', '<item_id>')

Remove all items from a subscription.

Remove all items
await swell.subscriptions.removeItem('5c15505200c7d14d851e510f', '<item_id>')