Backend API

Subscription plans are products with type=subscription. When creating a plan, consider whether it's needed to ship physical items or not.

Create a subscription plan without physical items.

Arguments

namestringrequired

Human-friendly name of the product.

optionsobjectrequired

Specify the billing options available on the plan.

typestringrequired

Set to subscription to indicate the product is a subscription plan.

POST/products
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.post('/products', {
  name: 'Pro plan',
  type: 'subscription',
  options: [
    {
      name: 'Plan',
      variant: true,
      subscription: true,
      values: [
        {
          name: 'Monthly',
          subscription_interval: 'monthly',
          price: 99,
        },
        {
          name: 'Yearly',
          subscription_interval: 'yearly',
          price: 999,
        },
      ],
    },
  ],
});
Response
{
  "id": "5cad15bc9b14d1990724663a",
  "delivery": "subscription"
  "name": "Pro plan",
  "options": [
    {
      "id": "5ca24ab32599d4179c24a624",
      "name": "Plan",
      "variant": true,
      "subscription": true,
      "values": [
        {
          "id": "5ca24ad59c077817e5fe2ba3",
          "name": "Monthly",
          "subscription_interval": "monthly",
          "price": 99
        },
        {
          "id": "5ca24ad59c077817e5fe2ba4",
          "name": "Yearly",
          "subscription_interval": "yearly",
          "price": 999
        }
      ]
    }
  ],
  "slug": "pro-plan",
  "type": "subscription"
}

In order to support shipping physical goods, create standard products with all the details needed for shipment, then create a subscription plan (product) and set the bundle_items with the products you want to have shipped when the subscription is charged.

Arguments

bundlebooleanrequired

Set true to indicate the plan has physical items.

bundle_itemsarray of object

Specify the items to be fulfilled when the plan is charged.

namestringrequired

Human-friendly name of the product.

optionsobjectrequired

Specify the billing options available on the plan.

typestringrequired

Set to subscription to indicate the product is a subscription plan.

POST/products
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.post('/products', {
  name: 'Coffee club',
  type: 'subscription',
  bundle_items: [
    {
      product_id: '5ca24abb9c077817e5fe2b36',
      quantity: 1
    }
  ],
  options: [
    {
      name: 'Plan',
      variant: true,
      subscription: true,
      values: [
        {
          name: 'Weekly',
          subscription_interval: 'weekly',
          price: 15,
        },
        {
          name: 'Monthly',
          subscription_interval: 'monthly',
          price: 19,
        },
      ],
    },
  ],
});
Response
{
  "id": "5cad15bc9b14d1990724663a",
  "delivery": "subscription"
  "name": "Coffee club",
  "bundle_items": [
    {
      "product_id": "5ca24abb9c077817e5fe2b36",
      "quantity": 1
    }
  ],
  "options": [
    {
      "id": "5ca24ab32599d4179c24a624",
      "name": "Plan",
      "variant": true,
      "subscription": true,
      "values": [
        {
          "id": "5ca24ad59c077817e5fe2ba3",
          "name": "Weekly",
          "subscription_interval": "weekly",
          "price": 15
        },
        {
          "id": "5ca24ad59c077817e5fe2ba3",
          "name": "Monthly",
          "subscription_interval": "monthly",
          "price": 19
        }
      ]
    }
  ],
  "slug": "coffee-club",
  "type": "subscription"
}