Backend API
Subscription plans is the recurring order for which
The subscription model represents the recurring order (plan) that is associated with a user's account and billed at regular intervals.
Fields
id
objectIdUnique identifier for the subscription.
account_id
objectIdID of the subscribed customer's account.
account
AccountExpandable link to the subscribed customer's account.
product_id
objectIdID of the subscription plan product.
product
ProductExpandable link to the subscription plan product.
active
booleanIndicates the subscription is currently active.
billing
objectSubscription billing details.
billing.name
stringBilling full name. If first_name or last_name are updated, then name will be automatically updated as a combination of first/last.
billing.first_name
stringBilling first name. If name is updated, then first_name will be automatically updated as the first word of the name.
billing.last_name
stringBilling last name. If name is updated, then last_name will be automatically updated as the first word of the name.
billing.address1
stringBilling address line 1: street address/PO box/company name.
billing.address2
stringBilling address line 2: apartment/suite/unit/building.
billing.city
stringBilling city/district/suburb/town/village.
billing.state
stringBilling state/county/province/region.
billing.zip
stringBilling zip/postal code.
billing.country
stringTwo-letter ISO code country code.
billing.phone
stringBilling phone number.
billing.method
stringMethod of payment. Can be card, account, amazon, paypal, or any one of the manual methods defined in payment settings.
billing.card
objectcard.token
stringrequiredToken generated by Swell Checkout or Stripe.js.
card.exp_month
intTwo-digit number representing the credit card expiration month.
card.exp_year
intFour-digit number representing the credit card expiration year.
card.brand
stringCredit card brand. Can be American Express, Diners Club, Discover, JCB, MasterCard, UnionPay, Visa, or Unknown.
card.last4
stringLast four digits of the card number.
card.gateway
stringID of the payment gateway that should be used to process payments.
card.test
booleanIndicates this is a test card.
card.address_check
stringWhen used with a payment gateway that performs address checks and address1 was provided, can be pass, fail, unavailable, or unchecked.
card.zip_check
stringWhen used with a payment gateway that performs address checks and zip was provided, can be pass, fail, unavailable, or unchecked.
card.cvc_check
stringWhen used with a payment gateway that performs CVC code checks and cvc was provided, can be pass, fail, unavailable, or unchecked.
billing.intent
objectStores the necessary information about the payment. This is typically the payment ID returned by the gateway after payment is initialized.
billing.default
booleanIndicates billing details represent the customer's default payment method.
billing.use_account
booleanWhen true, inherits the address tied to the user's account.
billing.account_card_id
objectIdID of the customer's credit card on file, if applicable.
billing.account_card
account_cardExpandable link to the customer's credit card on file, if applicable.
billing_schedule
objectBilling schedule for subscription plan.
billing_schedule.interval
enumSubscription plan billing interval. Can be daily, weekly, monthly, or yearly.
Possible enum values:
billing_schedule.interval_count
intMultiplier for billing interval. For example, to make the billing cycle once every two weeks, set interval=weekly and interval_count=2.
billing_schedule.trial_days
intNumber of days offered as a free trial on the subscription plan before the customer is billed. If a subscription is canceled by the last day of the trial period, an invoice won't be issued.
billing_schedule.limit
intSpecifies a limit to the number of billing cycles for the subscription plan. For example, "limit"=10 would stop billing the customer after the tenth billing cycle.
billing_schedule.limit_current
intCurrent number of billing cycles that have occured.
billing_schedule.date_limit_end
dateLimit date for marking the end of the billing cycle.
bundle_item_id
objectIdID of the corresponding bundle item, if applicable.
cancel_at_end
booleanWhen true, indicates the subscription was or will be canceled at the end of the billing period.
cancel_reason
stringA brief message describing the reason the subscription was canceled, if applicable.
canceled
booleanIndicates the subscription was canceled.
complete
booleanIndicates the subscription plan has completed all cycles.
coupon
CouponExpandable link to the coupon applied to the subscription.
coupon_code
stringCoupon code applied to the subscription. See coupons for details.
coupon_id
objectIdID of the coupon applied to the subscription.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
currency_rate
floatCurrency rate used in calculating the fixed amount.
date_canceled
dateDate the subscription was canceled, if applicable.
date_created
dateautoDate and time the subscription was created.
date_order_cycle_start
dateStart date fo the subscription order cycle.
date_order_period_end
dateEnd date for the subscription order period.
date_order_period_start
dateStart date for the subscription order period.
date_pause_end
dateDate the subscription was unpaused, if applicable.
date_paused
dateDate the subscription was paused, if applicable.
date_payment_expiring
dateautoDate when the customer's current default credit card will expire, used to notify the customer to update their payment information before their card expires.
date_payment_failed
dateDate when the last automated payment failed, if applicable.
date_payment_retry
dateautoWhen automated payment has failed, this is the date when the system will automatically retry.
date_period_end
dateautoEnd date of the current billing period.
date_period_start
dateStart date of the current billing period.
date_prorated
dateDate the subscription was last prorated, if applicable. Used to calculate the charge or credit applied when the subscription is prorated.
date_resumed
dateThe date a subscription was resumed.
date_trial_end
dateDate the trial period did end in the past or will end in the future. Changing this value can be used to update the billing period of a subscription with or without a trial. For example, to set the monthly billing date to the 1st of the month, update date_trial_end to the first of the next month.
date_trial_start
dateDate the trial period started, if applicable.
date_updated
dateautoDate and time the subscription was last updated.
discount_total
currencyTotal discount amount.
discounts
array of objectList of all discounts applied to the subscription.
id
stringUnique identifier for the object.
amount
currencyFixed discount amount.
rule
objectObject describing the discount rule details. Custom discounts don't require this value.
type
enumType of discount. Can be coupon or sale referring to the source of the discount. Custom discounts don't require this value.
Possible enum values:
draft
booleanIndicates the subscription is a draft.
grand_total
currencyGrand total of the next invoice including line items and taxes.
invoice_total
currencyAmount invoiced for the last billing period.
invoices
InvoiceExpandable list of all invoices created by the subscription.
item_discount
currencyautoTotal discount applied to line items.
item_tax
currencyTotal taxes applied to line items.
item_total
currencyautoAmount invoiced for the last billing period.
items
array of objectList of invoice line items added to the subscription. Recurring items are charged repeatedly, otherwise they are charged on the next invoice and then removed from the subscription.
id
objectIdautoUnique identifier for the object.
bundle_items
array of objectList of products sold as a bundle. Applicable only when bundle=true.
id
objectIdUnique identifier for the bundle item.
product_id
objectIdID of the bundled product.
product
productExpandable link to the bundled product.
quantity
intQuantity of the bundled product. Defaults to 1.
variant_id
objectIdID of the bundled variant, if applicable.
variant
variantExpandable link to the bundled product variant, if applicable.
quantity_total
intTotal quantity of bundle items.
date_created
dateautoDate and time the object was created.
description
stringA long-form description of the options. May contain HTML or other markup languages.
discount_each
currencyTotal discount amount divided by quantity.
discount_total
currencyTotal discount applied to the item.
discounts
array of objectList of discounts applied to the line item by coupons.
id
stringUnique identifier for the object.
amount
currencyFixed discount amount.
options
array of objectItem options matching one or more of product.options, if applicable. When setting this value, specify either option id or name (case-insensitive) to identify the option.
id
stringUnique identifier for the object.
name
stringName of the option. Populated automatically when adding an option by ID.
price
currencyPrice of the option added to plan price when selected.
shipment_weight
floatIf specified, shipping is calculated using this weight. Otherwise, Swell assumes 1 lb/oz/kg — depending on store's default weight unit.
value
stringName value of the option. When setting this value, specify either the product option value id or name (case-insensitive) to identify the value.
variant
booleanIndicates the option refers to a variant aspect.
value_id
objectIdprice
currencyPrice of the line item. Defaults to product price, if applicable. A negative value will be subtracted from the plan total and credited to the customer on their next invoice.
price_total
currencyTotal price of the line item (price * quantity).
product_id
objectIdID of the item product, if applicable.
product
productExpandable link to the item product, if applicable.
proration
booleanIndicates the item represents a proration charge or credit.
quantity
intQuantity of the line item.
recurring
booleanIndicates the item will remain on the subscription after the next invoice is created.
recurring_discount_each
currencyTotal recurring discount amount divided by quantity, if applicable.
recurring_discount_total
currencyTotal recurring discount applied to the item, if applicable.
recurring_price
currencyRecurring price of the item, if applicable.
recurring_price_total
currencyTotal recurring price of the item (price * quantity), if applicable.
recurring_tax_each
currencyTotal recurring tax amount divided by quantity, if applicable.
recurring_tax_total
currencyTotal recurring tax applied to the item, if applicable.
tax_each
currencyTotal tax amount divided by quantity.
tax_total
currencyTotal tax applied to the item.
taxes
array of objectList of tax rules applied to the item based on tax settings.
id
stringUnique identifier for the object.
amount
currencyFixed tax amount.
variant_id
objectIdID of the item variant, if applicable.
variant
variantExpandable link to the item variant, if applicable.
delivery
enumDelivery frequency for the item.
Possible enum values:
proration_product_id
objectIdnotes
stringInternal admin notes. These are not visible to the customer.
number
stringautoThe order number for the subscription, based on the store order number format.
options
array of objectPlan options matching one or more of product.options. When setting this value, specify either option id or name (case-insensitive) to identify the option.
id
stringUnique identifier for the object.
name
stringName of the plan option. Populated automatically when adding an option by ID.
price
currencyPrice of the option added to plan price when selected.
value
stringName value of the plan option. When setting this value, specify either value id or name (case-insensitive) to identify the value.
variant
booleanIndicates the option refers to a variant aspect.
value_id
objectIdshipment_weight
floatorder_id
objectIdID of the order that originated the subscription, if applicable.
order_item_id
objectIdID of the line item from the order that originated the subscription, if applicable.
order_schedule
objectOrder schedule for the subscription plan.
order_schedule.interval
enumOrder interval for subscription plan. Can be monthly, daily, weekly, and yearly.
Possible enum values:
order_schedule.interval_count
intMultiplier for order interval. For example, to generate the subscription order once every two weeks, set interval=weekly and interval_count=2.
order_schedule.limit
intSpecifies a limit to the number of orders created. For example, "limit"=10 would stop creating orders after the tenth order.
order_schedule.date_limit_end
dateDesignates the end date of the order cycle.
order_schedule.limit_current
intordering
booleanIndicates the subscription is actively placing orders.
orders
OrderExpandable list of all orders created by the subscription plan. This happens when a plan contains physical products as bundle_items.
paid
booleanautoIndicates the last invoice was fully paid.
payment_balance
currencyautoBalance of payments on the invoice for the last billing period. A negative number indicates payment is owed, while a positive balance indicates refund is due. Zero balance indicates the invoice was fully paid.
payment_total
currencyTotal amount of payments for the last billing period.
payments
PaymentExpandable list of all payments made on behalf of the subscription.
pending_invoices
InvoiceExpandable list of invoices that haven't been fully paid.
plan_id
objectIdID of the subscription plan.
plan_name
stringName of the subscription plan.
price
currencyPrice of the plan. Plan price can be overridden when creating or updating a subscription.
price_total
currencyautoTotal price of the plan (price * quantity).
product_discount_each
currencyautoTotal discount amount of the subscription plan, divided by quantity.
product_discount_total
currencyautoTotal discount applied to the subscription plan.
product_discounts
array of objectList of discounts applied to the subscription plan by coupons.
id
stringID of the coupon applied for a discount.
amount
currencyDiscount amount.
product_name
stringThis field is a copy of the item's product.name.
product_tax_each
currencyautoTotal tax amount of the subscription plan, divided by quantity.
product_tax_total
currencyautoTotal tax applied to the subscription plan.
product_taxes
array of objectautoList of tax rules applied to the subscription plan based on tax settings.
id
stringUnique identifier for the object. Refers to one of the ids in the subscription taxes object.
amount
currencyFixed tax amount.
prorated
booleanWhen false, indicates the subscription should not be prorated if the plan product is changed, otherwise a prorated charge or credit will be added at the appropriate time.
quantity
intQuantity of the plan to charge.
recurring_discount_total
currencyautoTotal recurring discount applied to the subscription including line items.
recurring_item_discount
currencyautoTotal discount applied to recurring line items.
recurring_item_tax
currencyautoTotal taxes applied to recurring line items.
recurring_item_total
currencyautoSum of all recurring line items before discounts and taxes.
recurring_tax_included_total
currencyautoTotal of taxes applied separately from the subscription plan and recurring line items.
recurring_tax_total
currencyautoTotal taxes applied to the subscription including recurring line items.
recurring_total
currencyautoRecurring total of the subscription including line items and taxes.
refund_total
currencyTotal amount of refunds for the last billing period.
refunds
RefundExpandable list of all refunds made on behalf of the subscription.
status
enumautoCurrent status of the subscription. Can be pending, active, trial, pastdue, unpaid, canceled, or paid.
Possible enum values:
sub_total
currencyautoSum of all line items before discounts and taxes.
tax_included
booleanautoIndicates the subscription plan price includes taxes.
tax_included_total
currencyautoTotal of taxes applied separately from the subscription plan and line items.
tax_total
currencyautoTotal taxes applied to the subscription including line items.
taxes
array of objectautoList of taxes applied to the subscription.
id
stringUnique identifier for the object.
amount
currencyFixed tax amount.
name
stringName of the tax rule. For example "NY Sales Tax".
priority
intPriority indicates the order in which a tax rule was applied. Higher priority rules are added on top of other tax rules with a lower priority. Rules with the same priority are calculated excluding each other.
rate
floatTax percentage used in calculating the fixed amount.
taxes_fixed
booleanWhen true, taxes are not applied to the subscription. When false, taxes are calculated and applied to the subscription.
trial
booleanautoIndicates the subscription is in a trial period and the first invoice will be issued on date_trial_end.
unpaid
booleanautoIndicates the last invoice was marked as unpaid. This occurs automatically after all payment attempts are exhausted, as configured in subscription settings.
variant
Product variantExpandable link to the subscription plan variant, if applicable.
variant_id
objectIdID of the subscription plan variant, if applicable.
Create a subscription plan for a product with a subscription purchase option.
Arguments
account_id
objectIdrequiredID of the subscribed customer's account.
product_id
objectIdrequiredID of the subscription plan product. When changing the subscription product, the difference in price is prorated by adding a line item. The customer will be charged or credited the difference on their next invoice.
billing
objectSubscription billing details.
billing.name
stringBilling full name. If first_name or last_name are updated, then name will be automatically updated as a combination of first/last.
billing.first_name
stringBilling first name. If name is updated, then first_name will be automatically updated as the first word of the name.
billing.last_name
stringBilling last name. If name is updated, then last_name will be automatically updated as the first word of the name.
billing.address1
stringBilling address line 1: street address/PO box/company name.
billing.address2
stringBilling address line 2: apartment/suite/unit/building.
billing.city
stringBilling city/district/suburb/town/village.
billing.state
stringBilling state/county/province/region.
billing.zip
stringBilling zip/postal code.
billing.country
stringTwo-letter ISO code country code.
billing.phone
stringBilling phone number.
billing.method
stringMethod of payment. Can be card, account, amazon, paypal, or any one of the manual methods defined in payment settings.
billing.card
objectcard.token
stringToken generated by Swell Checkout or Stripe.js.
card.exp_month
intTwo-digit number representing the credit card expiration month.
card.exp_year
intFour-digit number representing the credit card expiration year.
card.brand
stringCredit card brand. Can be American Express, Diners Club, Discover, JCB, MasterCard, UnionPay, Visa, or Unknown.
card.last4
stringLast four digits of the card number.
card.gateway
stringID of the payment gateway that should be used to process payments.
card.test
booleanIndicates this is a test card.
card.address_check
stringWhen used with a payment gateway that performs address checks and address1 was provided, can be pass, fail, unavailable, or unchecked.
card.zip_check
stringWhen used with a payment gateway that performs address checks and zip was provided, can be pass, fail, unavailable, or unchecked.
card.cvc_check
stringWhen used with a payment gateway that performs CVC code checks and cvc was provided, can be pass, fail, unavailable, or unchecked.
billing.intent
objectStores the necessary information about the payment. This is typically the payment ID returned by the gateway after payment is initialized.
billing.default
booleanIndicates billing details represent the customer's default payment method.
billing.use_account
booleanWhen true, inherits the address tied to the user's account.
billing.account_card_id
objectIdID of the customer's credit card on file, if applicable.
billing.account_card
account_cardExpandable link to the customer's credit card on file, if applicable.
options
array of objectPlan options matching one or more of `product.options`. When setting this value, specify either option `id` or `name` (case-insensitive) to identify the option.
id
stringname
stringvalue
stringvalue_id
objectIdvariant
booleanprice
currencyshipment_weight
floataccount
AccountExpandable link to the subscribed customer's account.
active
booleanIndicates the subscription is currently active.
billing_schedule
objectBilling schedule for subscription plan.
billing_schedule.interval
enumSubscription plan billing interval. Can be daily, weekly, monthly, or yearly.
Possible enum values:
billing_schedule.interval_count
intMultiplier for billing interval. For example, to make the billing cycle once every two weeks, set interval=weekly and interval_count=2.
billing_schedule.trial_days
intNumber of days offered as a free trial on the subscription plan before the customer is billed. If a subscription is canceled by the last day of the trial period, an invoice won't be issued.
billing_schedule.limit
intSpecifies a limit to the number of billing cycles for the subscription plan. For example, "limit"=10 would stop billing the customer after the tenth billing cycle.
billing_schedule.limit_current
intCurrent number of billing cycles that have occured.
billing_schedule.date_limit_end
dateLimit date for marking the end of the billing cycle.
bundle_item_id
objectIdID of the corresponding bundle item, if applicable.
cancel_at_end
booleanWhen `true`, indicates the subscription was or will be canceled at the end of the billing period.
cancel_reason
stringA brief message describing the reason the subscription was canceled, if applicable.
canceled
booleanIndicates the subscription was canceled.
complete
booleanIndicates the subscription plan has completed all cycles.
coupon
CouponExpandable link to the coupon applied to the subscription.
coupon_code
stringCoupon code applied to the subscription. See coupons for details.
coupon_id
objectIdID of the coupon applied to the subscription.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
currency_rate
floatCurrency rate used in calculating the fixed amount.
date_canceled
dateDate the subscription was canceled, if applicable.
date_order_cycle_start
dateStart date fo the subscription order cycle.
date_order_period_end
dateEnd date for the subscription order period.
date_order_period_start
dateStart date of the subscription order cycle.
date_pause_end
dateDate the subscription was unpaused, if applicable.
date_paused
dateDate the subscription was paused, if applicable.
date_payment_expiring
dateautoDate when the customer's current default credit card will expire, used to notify the customer to update their payment information before their card expires.
date_payment_failed
dateDate when the last automated payment failed, if applicable.
date_payment_retry
dateautoWhen automated payment has failed, this is the date when the system will automatically retry.
date_period_end
dateautoEnd date of the current billing period.
date_period_start
dateStart date of the current billing period.
date_prorated
dateDate the subscription was last prorated, if applicable. Used to calculate the charge or credit applied when the subscription is prorated.
date_resumed
dateThe date a subscription was resumed.
date_trial_end
dateDate the trial period did end in the past, or will end in the future. Changing this value can be used to update the billing period of a subscription with or without a trial. For example, to set the monthly billing date to the 1st of the month, update `date_trial_end` to the first of the next month.
date_trial_start
dateDate the trial period started, if applicable.
discount_total
currencyTotal discount amount.
discounts
array of objectList of all discounts applied to the subscription.
id
stringtype
enumPossible enum values:
rule
objectamount
currencydraft
booleanIndicates the subscription is a draft.
grand_total
currencyGrand total of the next invoice including line items and taxes.
invoice_total
currencyAmount invoiced for the last billing period.
invoices
InvoiceExpandable list of all invoices created by the subscription.
item_discount
currencyautoTotal discount applied to line items.
item_tax
currencyTotal taxes applied to line items.
item_total
currencyautoAmount invoiced for the last billing period.
items
array of objectList of invoice line items added to the subscription. Recurring items are charged repeatedly, otherwise they are charged on the next invoice and then removed from the subscription.
id
objectIdautodate_created
dateautoquantity
intprice
currencyprice_total
currencydescription
stringdelivery
enumPossible enum values:
options
array of objectid
stringname
stringvalue
stringvalue_id
objectIdvariant
booleanprice
currencyshipment_weight
floatbundle_items
array of objectid
objectIdquantity
intquantity_total
intproduct_id
objectIdproduct
productvariant_id
objectIdvariant
variantproration
booleanproration_product_id
objectIdrecurring
booleanrecurring_price
currencyrecurring_price_total
currencydiscounts
array of objectid
stringamount
currencydiscount_total
currencydiscount_each
currencyrecurring_discount_total
currencyrecurring_discount_each
currencytaxes
array of objectid
stringamount
currencytax_total
currencytax_each
currencyrecurring_tax_total
currencyrecurring_tax_each
currencyproduct_id
objectIdproduct
productvariant_id
objectIdvariant
variantnotes
stringInternal admin notes. These are not visible to the customer.
number
stringautoThe order number for the subscription, based on the store order number format.
order_id
objectIdID of the order that originated the subscription, if applicable.
order_item_id
objectIdID of the line item from the order that originated the subscription, if applicable.
order_schedule
objectOrder schedule for the subscription plan.
order_schedule.interval
enumOrder interval for subscription plan. Can be monthly, daily, weekly, and yearly.
Possible enum values:
order_schedule.interval_count
intMultiplier for order interval. For example, to generate the subscription order once every two weeks, set interval=weekly and interval_count=2.
order_schedule.limit
intSpecifies a limit to the number of orders created. For example, "limit"=10 would stop creating orders after the tenth order.
order_schedule.date_limit_end
dateDesignates the end date of the order cycle.
order_schedule.limit_current
intordering
booleanIndicates the subscription is actively placing orders.
orders
OrderExpandable list of all orders created by the subscription plan. This happens when a plan contains physical products as bundle_items.
paid
booleanautoIndicates the last invoice was fully paid.
payment_balance
currencyautoBalance of payments on the invoice for the last billing period. A negative number indicates payment is owed, while a positive balance indicates refund is due. Zero balance indicates the invoice was fully paid.
payment_total
currencyTotal amount of payments for the last billing period.
payments
PaymentExpandable list of all payments made on behalf of the subscription.
pending_invoices
InvoiceExpandable list of invoices that haven't been fully paid.
plan_id
objectIdID of the subscription plan.
plan_name
stringName of the subscription plan.
price
currencyPrice of the plan. Plan price can be overridden when creating or updating a subscription.
price_total
currencyautoTotal price of the plan (price * quantity).
product
ProductExpandable link to the subscription plan product.
product_discount_each
currencyautoTotal discount amount of the subscription plan, divided by quantity.
product_discount_total
currencyautoTotal discount applied to the subscription plan.
product_discounts
array of objectList of discounts applied to the subscription plan by coupons.
id
stringamount
currencyproduct_name
stringThis field is a copy of the item's product.name.
product_tax_each
currencyautoTotal tax amount of the subscription plan, divided by quantity.
product_tax_total
currencyautoTotal tax applied to the subscription plan.
product_taxes
array of objectautoList of tax rules applied to the subscription plan based on tax settings.
id
stringamount
currencyprorated
booleanWhen `false`, indicates the subscription should not be prorated if the plan product is changed, otherwise a prorated charge or credit will be added at the appropriate time.
quantity
intQuantity of the plan to charge.
recurring_discount_total
currencyautoTotal recurring discount applied to the subscription including line items.
recurring_item_discount
currencyautoTotal discount applied to recurring line items.
recurring_item_tax
currencyautoTotal taxes applied to recurring line items.
recurring_item_total
currencyautoSum of all recurring line items before discounts and taxes.
recurring_tax_included_total
currencyautoTotal of taxes applied separately from the subscription plan and recurring line items.
recurring_tax_total
currencyautoTotal taxes applied to the subscription including recurring line items.
recurring_total
currencyautoRecurring total of the subscription including line items and taxes.
refund_total
currencyTotal amount of refunds for the last billing period.
refunds
RefundExpandable list of all refunds made on behalf of the subscription.
status
enumautoCurrent status of the subscription. Can be pending, active, trial, pastdue, unpaid, canceled, or paid.
Possible enum values:
sub_total
currencyautoSum of all line items before discounts and taxes.
tax_included
booleanautoIndicates the subscription plan price includes taxes.
tax_included_total
currencyautoTotal of taxes applied separately from the subscription plan and line items.
tax_total
currencyautoTotal taxes applied to the subscription including line items.
taxes
array of objectautoList of taxes applied to the subscription.
id
stringname
stringpriority
intrate
floatamount
currencytaxes_fixed
booleanWhen true, taxes are not applied to the subscription. When false, taxes are calculated and applied to the subscription.
trial
booleanautoIndicates the subscription is in a trial period and the first invoice will be issued on date_trial_end.
unpaid
booleanautoIndicates the last invoice was marked as unpaid. This occurs automatically after all payment attempts are exhausted, as configured in subscription settings.
variant
Product variantExpandable link to the subscription plan variant, if applicable.
variant_id
objectIdID of the subscription plan variant, if applicable.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.post('/products', {
body: {
billing: {
first_name: 'John',
last_name: 'Doe',
address1: '123 Main Street',
address2: 'Apt. 100',
city: 'Anytown',
state: 'CA',
zip: 12345,
country: 'US',
phone: '123-456-7890',
method: 'credit_card'
},
product_id: '62b1e30767145000197b2bbf',
product: {
model: 'products'
},
product_name: 'Skooma',
variant_id: '62b1e30767145000197b2bc0',
variant: {
},
price: 75,
quantity: 1,
price_total: 75,
options: [
{
id: 'Monthly',
value: 99
}
]
}
};
The subscription model
{
"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"
}
Retrieving a subscription plan with the ID that was returned when created.
Arguments
id
objectIdrequiredThe id of the subscription to retrieve.
expand
stringExpanding link fields and child collections is performed using the expand argument.
- For example, expand=account would return a related customer account if one exists.
When the field represents a collection, you can specify the query limit.
- For example, expand=variants:10 would return up to 10 records of the variants collection.
See expanding for more details.
fields
stringReturn only the specified fields in the result. For example fields=name,slug would return only the fields name and slug in the response. Supports nested object and array fields using dot-notation, for example, items.product_id. The category id is always returned.
include
stringInclude one or more arbitrary queries in the response, possibly related to the main query.
See including for more details.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/subscriptions/{id}', {
});
The subscription model
{
"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"
}
Update an existing subscription using the ID that was returned when created. Updating performs a merge operation. To explicitly override values such as arrays, use the $set operator.
Arguments
billing
objectSubscription billing details.
billing.name
stringBilling full name. If first_name or last_name are updated, then name will be automatically updated as a combination of first/last.
billing.first_name
stringBilling first name. If name is updated, then first_name will be automatically updated as the first word of the name.
billing.last_name
stringBilling last name. If name is updated, then last_name will be automatically updated as the first word of the name.
billing.address1
stringBilling address line 1: street address/PO box/company name.
billing.address2
stringBilling address line 2: apartment/suite/unit/building.
billing.city
stringBilling city/district/suburb/town/village.
billing.state
stringBilling state/county/province/region.
billing.zip
stringBilling zip/postal code.
billing.country
stringTwo-letter ISO code country code.
billing.phone
stringBilling phone number.
billing.method
stringMethod of payment. Can be card, account, amazon, paypal, or any one of the manual methods defined in payment settings.
billing.card
objectcard.token
stringToken generated by Swell Checkout or Stripe.js.
card.exp_month
intTwo-digit number representing the credit card expiration month.
card.exp_year
intFour-digit number representing the credit card expiration year.
card.brand
stringCredit card brand. Can be American Express, Diners Club, Discover, JCB, MasterCard, UnionPay, Visa, or Unknown.
card.last4
stringLast four digits of the card number.
card.gateway
stringID of the payment gateway that should be used to process payments.
card.test
booleanIndicates this is a test card.
card.address_check
stringWhen used with a payment gateway that performs address checks and address1 was provided, can be pass, fail, unavailable, or unchecked.
card.zip_check
stringWhen used with a payment gateway that performs address checks and zip was provided, can be pass, fail, unavailable, or unchecked.
card.cvc_check
stringWhen used with a payment gateway that performs CVC code checks and cvc was provided, can be pass, fail, unavailable, or unchecked.
billing.intent
objectStores the necessary information about the payment. This is typically the payment ID returned by the gateway after payment is initialized.
billing.default
booleanIndicates billing details represent the customer's default payment method.
billing.use_account
booleanWhen true, inherits the address tied to the user's account.
billing.account_card_id
objectIdID of the customer's credit card on file, if applicable.
billing.account_card
account_cardExpandable link to the customer's credit card on file, if applicable.
cancel_at_end
booleanWhen true, indicates the subscription was or will be canceled at the end of the billing period.
cancel_reason
stringA brief message describing the reason the subscription was canceled, if applicable.
canceled
booleanIndicates the subscription was canceled.
coupon_code
stringCoupon code applied to the subscription. See coupons for details.
date_trial_end
dateDate the trial period did end in the past, or will end in the future. Changing this value can be used to update the billing period of a subscription with or without a trial. For example, to set the monthly billing date to the 1st of the month, update `date_trial_end` to the first of the next month.
product_id
objectIdrequiredID of the subscription plan product. When changing the subscription product, the difference in price is prorated by adding a line item. The customer will be charged or credited the difference on their next invoice.
status
enumautoCurrent status of the subscription. Can be pending, active, trial, pastdue, unpaid, canceled, or paid.
Possible enum values:
account
AccountExpandable link to the subscribed customer's account.
account_id
objectIdrequiredID of the subscribed customer's account.
active
booleanIndicates the subscription is currently active.
billing_schedule
objectBilling schedule for subscription plan.
billing_schedule.interval
enumSubscription plan billing interval. Can be daily, weekly, monthly, or yearly.
Possible enum values:
billing_schedule.interval_count
intMultiplier for billing interval. For example, to make the billing cycle once every two weeks, set interval=weekly and interval_count=2.
billing_schedule.trial_days
intNumber of days offered as a free trial on the subscription plan before the customer is billed. If a subscription is canceled by the last day of the trial period, an invoice won't be issued.
billing_schedule.limit
intSpecifies a limit to the number of billing cycles for the subscription plan. For example, "limit"=10 would stop billing the customer after the tenth billing cycle.
billing_schedule.limit_current
intCurrent number of billing cycles that have occured.
billing_schedule.date_limit_end
dateLimit date for marking the end of the billing cycle.
bundle_item_id
objectIdID of the corresponding bundle item, if applicable.
complete
booleanIndicates the subscription plan has completed all cycles.
coupon
CouponExpandable link to the coupon applied to the subscription.
coupon_id
objectIdID of the coupon applied to the subscription.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
currency_rate
floatCurrency rate used in calculating the fixed amount.
date_canceled
dateDate the subscription was canceled, if applicable.
date_order_cycle_start
dateStart date fo the subscription order cycle.
date_order_period_end
dateEnd date for the subscription order period.
date_order_period_start
dateStart date for the subscription order period.
date_pause_end
dateDate the subscription was unpaused, if applicable.
date_paused
dateDate the subscription was paused, if applicable.
date_payment_expiring
dateautoDate when the customer's current default credit card will expire, used to notify the customer to update their payment information before their card expires.
date_payment_failed
dateDate when the last automated payment failed, if applicable.
date_payment_retry
dateautoWhen automated payment has failed, this is the date when the system will automatically retry.
date_period_end
dateautoEnd date of the current billing period.
date_period_start
dateStart date of the current billing period.
date_prorated
dateDate the subscription was last prorated, if applicable. Used to calculate the charge or credit applied when the subscription is prorated.
date_resumed
dateThe date a subscription was resumed.
date_trial_start
dateDate the trial period started, if applicable.
discount_total
currencyTotal discount amount.
discounts
array of objectList of all discounts applied to the subscription.
id
stringtype
enumPossible enum values:
rule
objectamount
currencydraft
booleanIndicates the subscription is a draft.
grand_total
currencyGrand total of the next invoice including line items and taxes.
id
objectIdrequiredUnique identifier for the subscription.
invoice_total
currencyAmount invoiced for the last billing period.
invoices
InvoiceExpandable list of all invoices created by the subscription.
item_discount
currencyautoTotal discount applied to line items.
item_tax
currencyTotal taxes applied to line items.
item_total
currencyautoAmount invoiced for the last billing period.
items
array of objectList of invoice line items added to the subscription. Recurring items are charged repeatedly, otherwise they are charged on the next invoice and then removed from the subscription.
id
objectIdautodate_created
dateautoquantity
intprice
currencyprice_total
currencydescription
stringdelivery
enumPossible enum values:
options
array of objectid
stringname
stringvalue
stringvalue_id
objectIdvariant
booleanprice
currencyshipment_weight
floatbundle_items
array of objectid
objectIdquantity
intquantity_total
intproduct_id
objectIdproduct
productvariant_id
objectIdvariant
variantproration
booleanproration_product_id
objectIdrecurring
booleanrecurring_price
currencyrecurring_price_total
currencydiscounts
array of objectid
stringamount
currencydiscount_total
currencydiscount_each
currencyrecurring_discount_total
currencyrecurring_discount_each
currencytaxes
array of objectid
stringamount
currencytax_total
currencytax_each
currencyrecurring_tax_total
currencyrecurring_tax_each
currencyproduct_id
objectIdproduct
productvariant_id
objectIdvariant
variantnotes
stringInternal admin notes. These are not visible to the customer.
number
stringautoThe order number for the subscription, based on the store order number format.
options
array of objectPlan options matching one or more of `product.options`. When setting this value, specify either option `id` or `name` (case-insensitive) to identify the option.
id
stringname
stringvalue
stringvalue_id
objectIdvariant
booleanprice
currencyshipment_weight
floatorder_id
objectIdID of the order that originated the subscription, if applicable.
order_item_id
objectIdID of the line item from the order that originated the subscription, if applicable.
order_schedule
objectOrder schedule for the subscription plan.
order_schedule.interval
enumOrder interval for subscription plan. Can be monthly, daily, weekly, and yearly.
Possible enum values:
order_schedule.interval_count
intMultiplier for order interval. For example, to generate the subscription order once every two weeks, set interval=weekly and interval_count=2.
order_schedule.limit
intSpecifies a limit to the number of orders created. For example, "limit"=10 would stop creating orders after the tenth order.
order_schedule.date_limit_end
dateDesignates the end date of the order cycle.
order_schedule.limit_current
intordering
booleanIndicates the subscription is actively placing orders.
orders
OrderExpandable list of all orders created by the subscription plan. This happens when a plan contains physical products as bundle_items.
paid
booleanautoIndicates the last invoice was fully paid.
payment_balance
currencyautoBalance of payments on the invoice for the last billing period. A negative number indicates payment is owed, while a positive balance indicates refund is due. Zero balance indicates the invoice was fully paid.
payment_total
currencyTotal amount of payments for the last billing period.
payments
PaymentExpandable list of all payments made on behalf of the subscription.
pending_invoices
InvoiceExpandable list of invoices that haven't been fully paid.
plan_id
objectIdID of the subscription plan.
plan_name
stringName of the subscription plan.
price
currencyPrice of the plan. Plan price can be overridden when creating or updating a subscription.
price_total
currencyautoTotal price of the plan (price * quantity).
product
ProductExpandable link to the subscription plan product.
product_discount_each
currencyautoTotal discount amount of the subscription plan, divided by quantity.
product_discount_total
currencyautoTotal discount applied to the subscription plan.
product_discounts
array of objectList of discounts applied to the subscription plan by coupons.
id
stringamount
currencyproduct_name
stringThis field is a copy of the item's product.name.
product_tax_each
currencyautoTotal tax amount of the subscription plan, divided by quantity.
product_tax_total
currencyautoTotal tax applied to the subscription plan.
product_taxes
array of objectautoList of tax rules applied to the subscription plan based on tax settings.
id
stringamount
currencyprorated
booleanWhen `false`, indicates the subscription should not be prorated if the plan product is changed, otherwise a prorated charge or credit will be added at the appropriate time.
quantity
intQuantity of the plan to charge.
recurring_discount_total
currencyautoTotal recurring discount applied to the subscription including line items.
recurring_item_discount
currencyautoTotal discount applied to recurring line items.
recurring_item_tax
currencyautoTotal taxes applied to recurring line items.
recurring_item_total
currencyautoSum of all recurring line items before discounts and taxes.
recurring_tax_included_total
currencyautoTotal of taxes applied separately from the subscription plan and recurring line items.
recurring_tax_total
currencyautoTotal taxes applied to the subscription including recurring line items.
recurring_total
currencyautoRecurring total of the subscription including line items and taxes.
refund_total
currencyTotal amount of refunds for the last billing period.
refunds
RefundExpandable list of all refunds made on behalf of the subscription.
sub_total
currencyautoSum of all line items before discounts and taxes.
tax_included
booleanautoIndicates the subscription plan price includes taxes.
tax_included_total
currencyautoTotal of taxes applied separately from the subscription plan and line items.
tax_total
currencyautoTotal taxes applied to the subscription including line items.
taxes
array of objectautoList of taxes applied to the subscription.
id
stringname
stringpriority
intrate
floatamount
currencytaxes_fixed
booleanWhen true, taxes are not applied to the subscription. When false, taxes are calculated and applied to the subscription.
trial
booleanautoIndicates the subscription is in a trial period and the first invoice will be issued on date_trial_end.
unpaid
booleanautoIndicates the last invoice was marked as unpaid. This occurs automatically after all payment attempts are exhausted, as configured in subscription settings.
variant
Product variantExpandable link to the subscription plan variant, if applicable.
variant_id
objectIdID of the subscription plan variant, if applicable.
const request = require('request');
const url = 'https://api.swell.store/subscritpions/{id}';
const data = {
purchase_options: {
subscription: {
active: true,
plans: [{
name: encodeURIComponent('Weekly'),
price: 105,
billing_schedule: {
interval: encodeURIComponent('weekly'),
trial_days: 0
}
}]
}
}
};
const encodedData = JSON.stringify(data);
request({
url,
method: 'POST',
body: encodedData
});
The subscription model
{
"name": "Skooma",
"purchase_options": {
"subscription": {
"active": true,
"plans": [
{
"name": "Weekly",
"description": null,
"price": 105,
"billing_schedule": {
"interval": "weekly",
"interval_count": 1,
"limit": null,
"trial_days": 0
},
"id": "64e799c1307e48001237eef5",
"active": true,
"$locale": {
"en-US": {
"name": "Monthly",
"description": null
}
}
}
]
}
},
"currency": "USD",
"slug": "skooooma",
"price": 75,
"type": "standard",
"delivery": "shipment",
"tax_class": "standard",
"date_created": "2023-08-24T17:56:17.162Z",
"active": false,
"stock_status": null,
"id": "64e799c1307e48001237eef4",
"$locale": {
"en-US": {
"name": "Skooma"
}
}
}
Return a list of subscriptions.
Fields
expand
stringExpand link fields and child collections by using the expand argument.
- For example, expand=account would return a related customer account if one exists.
When the field represents a collection, you can specify the query limit.
- For example, expand=variants:10 would return up to 10 records of the variants collection.
See expanding for more details.
fields
stringReturns only the specified fields in the result.
- For example fields=name,slug would return only the fields name and slug in the response.
Supports nested object and array fields using dot-notation.
- For example, items.product_id. The product id is always returned.
include
objectInclude one or more arbitrary queries in the response which are potentially related to the main query.
See including for more details.
limit
intLimit the number of records returned, ranging between 1 and 1000. Defaults to 15.
page
intThe page number of results to return given the specified or default limit.
search
stringA text search is performed using the search argument. Searchable fields are defined by the model.
- For example, search=red would return records containing the word "red" anywhere in the defined text fields.
See searching for more details.
sort
stringExpression to sort results by using a format similar to a SQL sort statement.
- For example, sort=name asc would return records sorted by name ascending.
See sorting for more details.
where
objectAn object with criteria to filter the result.
- For example, active=true would return records containing a field active with the value true.
It's also possible to use query operators, for example, $eq, $ne, $gt, and more.
See querying for more details.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/subscriptions', {
limit: 25,
page: 1,
}
);
The subscription model
{
"count": 54,
"page_count": 25,
"page": 1,
"results": [
{
"currency": "USD",
"account_id": "62acbadb3edcc300128d4178",
"billing": {
"first_name": "Wandering",
"last_name": "Traveller",
"company": null,
"address1": null,
"address2": null,
"city": null,
"zip": null,
"country": null,
"state": null,
"phone": null,
"name": "Wandering Traveller",
"card": {
"brand": "Visa",
"last4": "4242",
"exp_month": 7,
"exp_year": 2024,
"token": "card_s4FQeFxdb8ErigKVxS9cR3js",
"address_check": "unchecked",
"zip_check": "unchecked",
"cvc_check": "unchecked",
"fingerprint": "883f20e8bc00d0f9e1c42967b39a4f22",
"date_created": "2022-06-21T18:44:14.767Z"
},
"method": "card",
"account_card_id": "62b2117ed9dce40019a6587b",
"use_account": true
},
"shipping": {
"first_name": "Wandering",
"last_name": "Traveller",
"company": "Urbul gro-Orkulg's crew",
"address1": "1234 City Isle",
"address2": "Cyrodiil",
"city": "Heartlands",
"zip": null,
"country": "US",
"state": null,
"phone": null,
"name": "Wandering Traveller",
"account_address_id": "62acbbe0d69a3b0012c7eae5",
"use_account": true,
"price": null
},
"shipment_rating": {
"date_created": "2022-06-27T17:51:05.110Z",
"fingerprint": "08f0fbfe821509fe87fd4f4ed6c14666",
"services": [
{
"id": "standard",
"name": "Standard Shipping",
"price": 5,
"description": "Standard shipping service"
},
{
"id": "express",
"name": "Express Shipping",
"price": 15,
"description": "Express shipping service"
}
]
},
"order_id": "62b9ee09e342a30012319601",
"order_item_id": "62b9f12391fed80013478224",
"product_id": "62b1e30767145000197b2bbf",
"variant_id": null,
"options": null,
"price": 75,
"quantity": 1,
"billing_schedule": {
"interval": "monthly",
"interval_count": 1,
"limit": null,
"trial_days": 0
},
"order_schedule": null,
"coupon_code": null,
"coupon_id": null,
"coupon_use_count": null,
"discounts": [],
"tax_included": false,
"shipment_tax_included": false,
"display_currency": null,
"items": [],
"product_name": "Skooma",
"price_total": 75,
"payment_balance": -81,
"trial": false,
"paid": false,
"unpaid": true,
"product_discount_total": 0,
"product_discount_each": 0,
"product_tax_total": 0,
"product_tax_each": 0,
"shipment_price": 0,
"shipment_total": 0,
"shipment_tax_included_total": 0,
"date_period_end": "2023-09-27T18:14:53.861Z",
"item_total": 0,
"recurring_item_total": 0,
"sub_total": 75,
"item_discount": 0,
"recurring_item_discount": 0,
"item_tax": 0,
"recurring_item_tax": 0,
"discount_total": 0,
"recurring_discount_total": 0,
"tax_total": 0,
"recurring_tax_total": 0,
"tax_included_total": 0,
"recurring_tax_included_total": 0,
"grand_total": 75,
"recurring_total": 75,
"ordering": true,
"plan_id": null,
"plan_name": null,
"interval": "monthly",
"interval_count": 1,
"trial_days": 0,
"taxes": null,
"active": true,
"date_period_start": "2023-08-27T18:14:53.861Z",
"test": true,
"date_created": "2022-06-27T18:14:53.887Z",
"status": "unpaid",
"number": "100004",
"date_updated": "2023-08-27T18:15:01.146Z",
"invoices": "62b9f1d191fed8001347822a",
"invoice_total": 81,
"payment_total": 0,
"date_payment_expiring": "2024-07-01T00:00:00.000Z",
"notified_payment_expiring": false,
"date_payment_retry": null,
"payment_error": "Unable to complete payment, invoice not found",
"retry_resolve": "unpaid",
"date_payment_failed": "2023-01-27T18:15:03.450Z",
"id": "62b9f39d8b9a9a00133b7784"
},
. . .
Delete a subscription permanently.
Arguments
id
objectIdrequiredThe id of the subscription to delete.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.delete('/subscriptions/{id}', {
});
The subscription model
{
"id": "60f199509111e700000000c7",
"account_id": "60f199509111e700000000c8",
"product_id": "60f199509111e700000000c9",
"active": true,
"cancel_at_end": false,
"cancel_reason": null,
"canceled": false,
"currency": "USD",
"date_canceled": null,
"date_created": "2021-07-16T14:36:00.483Z",
"date_payment_expiring": "2031-01-01T08:00:00.000Z",
"date_payment_failed": null,
"date_payment_retry": null,
"date_period_end": "2019-03-24T04:28:12.962Z",
"date_period_start": "2019-02-24T04:28:12.962Z",
"date_trial_end": "2019-02-24T04:28:12.962Z",
"date_trial_start": "2019-01-24T04:28:12.962Z",
"date_updated": "2021-07-16T14:36:00.483Z",
"discount_total": 0,
"discounts": null,
"grand_total": 148.8946,
"interval": "monthly",
"interval_count": 1,
"invoice_total": 99,
"item_discount": 0,
"item_tax": 0,
"item_total": 49.8946,
"items": [
{
"id": "5ca537326a0ec32a521139dd",
"date_created": "2019-03-24T22:56:33.467Z",
"description": "Remaining time on Example Subscription",
"proration": true,
"quantity": 1,
"price": 49.8946,
"price_total": 49.8946,
"recurring_price": 0,
"recurring_price_total": 0,
"discount_total": 0,
"discount_each": 0,
"recurring_discount_total": 0,
"recurring_discount_each": 0,
"tax_total": 0,
"tax_each": 0,
"recurring_tax_total": 0,
"recurring_tax_each": 0
}
],
"notes": null,
"options": [
{
"id": "5becb84fac207653a4816ee5",
"name": "Plan",
"value": "Monthly"
}
],
"order_id": "60f199509111e7000000009d",
"order_item_id": "60f199509111e7000000009e",
"paid": true,
"payment_balance": 0,
"payment_total": 99,
"price": 99,
"price_total": 99,
"product_discount_each": 0,
"product_discount_total": 0,
"product_discounts": null,
"product_tax_each": 0,
"product_tax_total": 0,
"product_taxes": null,
"quantity": 1,
"recurring_discount_total": 0,
"recurring_item_discount": 0,
"recurring_item_tax": 0,
"recurring_item_total": 0,
"recurring_tax_included_total": 0,
"recurring_tax_total": 0,
"recurring_total": 99,
"refund_total": 0,
"status": "active",
"sub_total": 148.8946,
"tax_included_total": 0,
"tax_total": 0,
"taxes": null,
"trial": false,
"trial_days": 14,
"unpaid": false,
"variant_id": "60f199509111e7000000009f"
}