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)

Methods to create, update, and pause a subscription.

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
    }
  ]
})

Pauses a subscription indefinitely or skips a billing cycle.

Pause a subscription
await swell.subscriptions.update(subscription.id, {
  status: 'paused',
  date_pause_end: null
})

Cancel a single subscription.

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

Methods to add, update, and remove an invoice item on a subscription.

Returns the updated subscriptions object.

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

Returns the updated subscriptions object.

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

Returns the updated subscriptions object.

Remove invoice item(s) from a subscription
await swell.subscriptions.removeItem('5c15505200c7d14d851e510f', '<item_id>')