Backend API
Purchase links allow you to configure a pre-selected group of products within a cart and direct a customer to its checkout through a designated URL. Once enabled, the URL will be active and will direct anyone who clicks the link to an instance of the checkout, pre-populated with the products associated with that link.
Fields
id
stringautoThe unique identifier for the purchase link.
name
stringrequiredHuman-friendly name of the purchase link.
active
booleanautoThe active status of the purchase link is automatically set to off and must be toggled on to activate, share, and use.
coupon
CouponExpandable link to the coupon applied to purchase link items.
coupon_id
objectIdID of the coupon applied to purchase link items.
currency
stringThree-letter ISO currency code in uppercase. Defaults to your store's base currency.
date_created
dateautoDate the purchase link was created.
date_updated
dateautoDate the purchase link was last updated.
discount_total
currencyTotal discount amount.
discounts
array of objectDiscounts applied to purchase link items.
id
stringUnique identifier for the object.
type
stringType of discount. Can be coupon or promo-<id> referring to the source of the discount. Custom discounts don't require this value.
rule
objectObject describing the discount rule details. Custom discounts don't require this value.
amount
currencyFixed discount amount.
source_id
objectIdgrand_total
currencyautoGrand total including items, shipping, and taxes.
item_discount
currencyTotal discount applied to line items.
items
array of objectList of line items describing the products ordered.
id
objectIdautoUnique identifier for the item.
quantity
intQuantity of the bundle item being ordered. Defaults to 1.
price
currencyPrice of the item. If a product price is reduced by a sale or price rule, this would be set to the reduced price automatically. Also, item price can be overridden when adding to a cart. Line item prices don't change unless explicitly edited by a store admin.
price_total
currencyTotal price added to sub total by multiplying quantity and price.
purchase_option
objectConfiguration of one or more purchase options for purchase link items. Can be standard for one-time purchases or subscription for a subscription plan. Products can support both purchase options simultaneously.
purchase_option.type
enumPossible enum values:
purchase_option.plan_id
objectIdID of the subscription plan.
options
array of objectOptions that allow for variations of the base product within the purchase link. If the option is part of a variant or required=true, an option value must be set for the product to be added to a purchase link cart.
id
stringUnique identifier for the object.
value
stringName value of the product option. When adding to the cart, specify either the product option value id or name (case-insensitive) to identify the value.
bundle_items
array of objectList of items offered as a bundle. Defaults to product.bundle_items.
id
objectIdUnique identifier for the object.
quantity
intQuantity of the bundle item being ordered. Defaults to 1.
product_id
objectIdrequiredID of the bundle item product.
product
productExpandable link to the bundle item product.
variant_id
objectIdID of the bundle item variant.
variant
variantExpandable link to the bundle item variant.
options
array of objectid
stringUnique identifier for the object.
value
stringName value of the product option. When adding to the cart, specify either the product option value id or name (case-insensitive) to identify the value.
amount_ratio
floatprice
currencydiscount_each
currencytax_each
currencyproduct_id
objectIdID of product in the purchase link.
product
productExpandable link to the product within the purchase link.
variant_id
objectIdID of the product variant, if applicable.
variant
variantExpandable link to the product variant.
discounts
array of objectList of discounts applied to the item by coupons, promotions, or custom logic.
id
stringUnique identifier for the object. Refers to one of the IDs in the cart discounts object.
amount
currencyFixed discount amount.
discount_total
currencyTotal discount applied to the item.
discount_each
currencyTotal discount amount divided by quantity.
metadata
objectArbitrary item data, typically set in a checkout flow to store custom values. See Storefront API for details.
metadata
objectArbitrary data, typically set in a checkout flow to store custom values. See Frontend API for more details.
promotion_ids
array of child_scalarArray of promotion ids associated to the purchase link.
promotions
PromotionLink to promotions associated to the purchase link.
sub_total
currencyThe subtotal of all of the items in a purchase link.
The purchase link model
{
"active": true,
"name": "Mythic Dawn Commentaries Collection",
"items": [
{
"product_id": "628ba6011869c10019b41f70",
"quantity": 1,
"price": 60,
"id": "628ba7241869c10019b41f7d",
"orig_price": 60,
"delivery": "shipment",
"shipment_weight": 0,
"price_total": 60,
"discount_total": 0,
"discount_each": 0
},
{
"product_id": "628ba67a1869c10019b41f76",
"quantity": 1,
"price": 60,
"id": "628ba728499bba0019b1a9c2",
"orig_price": 60,
"delivery": "shipment",
"shipment_weight": 0,
"price_total": 60,
"discount_total": 0,
"discount_each": 0
},
{
"product_id": "628ba6b7499bba0019b1a9b2",
"quantity": 1,
"price": 60,
"id": "628ba72b499bba0019b1a9c5",
"orig_price": 60,
"delivery": "shipment",
"shipment_weight": 0,
"price_total": 60,
"discount_total": 0,
"discount_each": 0
},
{
"product_id": "628ba701499bba0019b1a9bb",
"quantity": 1,
"price": 60,
"id": "628ba72d499bba0019b1a9c8",
"orig_price": 60,
"delivery": "shipment",
"shipment_weight": 0,
"price_total": 60,
"discount_total": 0,
"discount_each": 0
}
],
"shipment_delivery": true,
"currency": "USD",
"sub_total": 240,
"item_discount": 0,
"discount_total": 0,
"grand_total": 240,
"date_created": "2022-05-23T15:24:20.977Z",
"date_updated": "2022-05-23T15:24:32.137Z",
"id": "5wFVZQzV"
}
Create a purchase link. If you wish to generate your own unique ID for the record, it must use BSON ObjectID format for compatibility.
Arguments
name
stringrequiredHuman-friendly name of the purchase link.
items
array of objectList of line items describing the products ordered.
.bundle_items
array of objectList of items offered as a bundle. Defaults to product.bundle_items.
id
objectIdID of the bundle item product.
product_id
objectIdrequiredID of the bundle item product.
product
productExpandable link to the bundle product.
quantity
intQuantity of the bundle item being ordered. Defaults to 1.
shipment_weight
floatWeight to be used in shipping calculation, if applicable.
variant_id
objectIdID of the bundle item variant.
variant
variantExpandable link to the bundle variant.
.description
stringDescription used for custom line items, when product is not defined.
.discounts
array of objectList of discounts to apply to the item. Normally populated by applying a coupon or promotions.
id
stringrequiredUnique identifier for the object. Should refer to one of the IDs in the cart discounts object.
amount
currencyrequiredFixed discount amount.
.metadata
objectArbitrary item data, typically set in a checkout flow to store custom values. See Storefront API for details.
.options
array of objectItem options matching one or more of product.options. When adding to the cart, specify either option id or name (case-insensitive) to identify the option.
Gift card products have two special options that can be used when fulfilling gift cards by email. Use the option ID send_email and value as the recipient email address, and send_note as a custom message from the customer to the recipient sent by email.
.id
stringUnique identifier for the object.
.name
stringName of the product option. Populated automatically when adding an option by ID.
.price
currencyAdditional price added onto the base price of the product.
.shipment_weight
floatAdditional shipping weight added onto the base weight of the product.
.value
stringName value of the product option. When adding to the cart, specify either the product option value id or name (case-insensitive) to identify the value.
.variant
booleanIndicates the option refers to a variant aspect.
.delivery
enumMethod of delivery taken automatically from product.delivery
Possible enum values:
.price
currencyPrice of the item. Override this value to set a custom price. Defaults to product price or sale price.
.product_id
objectIdID of the item product.
.product
productExpandable link to the product, if applicable.
.quantity
intQuantity of the item being ordered. Defaults to 1.
.shipment_weight
floatWeight to be used in shipping calculation, if applicable.
.taxes
array of objectList of tax rules to apply to the item. Normally populated by tax settings.
id
stringrequiredUnique identifier for the object. Should refer to one of the IDs in the cart taxes object.
amount
currencyrequiredFixed tax amount.
.variant_id
objectIdID of the item variant, if applicable.
.variant
variantExpandable link to the variant, if applicable.
active
booleanIndicates the cart has been updated by a customer within the last 3 hours.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.post('/purchaselinks', {
name: 'Purchase link example',
active: true,
items: [
{
product_id: '626034d4e7b741001968292d',
quantity: 1,
}
],
});
Response
{
"active": true,
"name": "Purchase link example",
"items": [
{
"product_id": "626034d4e7b741001968292d",
"quantity": 1,
"price": 5,
"price_total": 5,
"discount_total": 0,
"discount_each": 0,
"id": "62681502ea4c3f00138da5ea"
}
],
"currency": "USD",
"sub_total": 5,
"item_discount": 0,
"discount_total": 0,
"grand_total": 5,
"date_created": "2022-04-26T15:51:30.324Z",
"date_updated": "2022-04-26T15:52:33.949Z",
"id": "DEEFRebs"
}
Retrieve a purchase link.
Arguments
id
objectIdrequiredThe id of the cart to retrieve.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/purchaselinks/{id}');
Response
{
"active": true,
"name": "Purchase link example",
"items": [
{
"product_id": "626034d4e7b741001968292d",
"quantity": 1,
"price": 5,
"price_total": 5,
"discount_total": 0,
"discount_each": 0,
"id": "62681502ea4c3f00138da5ea"
}
],
"currency": "USD",
"sub_total": 5,
"item_discount": 0,
"discount_total": 0,
"grand_total": 5,
"date_created": "2022-04-26T15:51:30.324Z",
"date_updated": "2022-04-26T15:52:33.949Z",
"id": "DEEFRebs"
}
Update a purchase link.
Arguments
id
objectIdrequiredUnique identifier for the cart.
name
objectIdHuman-friendly name of the purchase link.
active
booleanThe active status of the purchase link is automatically set to off and must be toggled on to activate, share, and use.
items
array of objectList of line items describing the products ordered.
bundle_items
array of objectList of items offered as a bundle. Defaults to product.bundle_items.
id
objectIdID of the bundle item product.
product_id
objectIdrequiredID of the bundle item product.
product
productExpandable link to the bundle product.
quantity
intQuantity of the bundle item being ordered. Defaults to 1.
shipment_weight
floatWeight to be used in shipping calculation, if applicable.
variant_id
objectIdID of the bundle item variant.
variant
variantExpandable link to the bundle variant.
description
stringDescription used for custom line items, when product is not defined.
discounts
array of objectList of discounts to apply to the item. Normally populated by applying a coupon or promotions.
id
stringrequiredUnique identifier for the object. Should refer to one of the IDs in the cart discounts object.
amount
currencyrequiredFixed discount amount.
metadata
objectArbitrary item data, typically set in a checkout flow to store custom values. See Storefront API for details.
options
array of objectItem options matching one or more of product.options. When adding to the cart, specify either option id or name (case-insensitive) to identify the option.
Gift card products have two special options that can be used when fulfilling gift cards by email. Use the option ID send_email and value as the recipient email address, and send_note as a custom message from the customer to the recipient sent by email.
id
stringUnique identifier for the object.
name
stringName of the product option. Populated automatically when adding an option by ID.
price
currencyAdditional price added onto the base price of the product.
shipment_weight
floatAdditional shipping weight added onto the base weight of the product.
value
stringName value of the product option. When adding to the cart, specify either the product option value id or name (case-insensitive) to identify the value.
variant
booleanIndicates the option refers to a variant aspect.
delivery
enumMethod of delivery taken automatically from product.delivery
Possible enum values:
price
currencyPrice of the item. Override this value to set a custom price. Defaults to product price or sale price.
product_id
objectIdID of the item product.
product
productExpandable link to the product, if applicable.
quantity
intQuantity of the item being ordered. Defaults to 1.
shipment_weight
floatWeight to be used in shipping calculation, if applicable.
taxes
array of objectList of tax rules to apply to the item. Normally populated by tax settings.
id
stringrequiredUnique identifier for the object. Should refer to one of the IDs in the cart taxes object.
amount
currencyrequiredFixed tax amount.
variant_id
objectIdID of the item variant, if applicable.
variant
variantExpandable link to the variant, if applicable.
coupon_code
stringCoupon code applied to the cart. See coupons for details.
promotion_ids
array of child_scalarList of promotion IDs applied to the cart.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.put('/purchaselinks/{id}', {
active: 'true',
});
Response
{
"active": true,
"name": "Purchase link example",
"items": [
{
"product_id": "626034d4e7b741001968292d",
"quantity": 1,
"price": 5,
"price_total": 5,
"discount_total": 0,
"discount_each": 0,
"id": "62681502ea4c3f00138da5ea"
}
],
"currency": "USD",
"sub_total": 5,
"item_discount": 0,
"discount_total": 0,
"grand_total": 5,
"date_created": "2022-04-26T15:51:30.324Z",
"date_updated": "2022-04-26T15:52:33.949Z",
"id": "DEEFRebs"
}
List all purchase links.
Arguments
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('/purchaselinks/');
Response
{
"count": 39,
"results": [
{
"active": true,
"name": "Purchase link example",
"items": [
{
"product_id": "626034d4e7b741001968292d",
"options": [
{
"id": "626034de60bd1a69a444f233",
"name": "Size20-04",
"value": "s",
"value_id": "626034ee60bd1a69a444f234",
"variant": true
}
],
"quantity": 1,
"price": 5,
"price_total": 5,
"discount_total": 0,
"discount_each": 0,
"id": "62681502ea4c3f00138da5ea"
}
],
"currency": "USD",
"sub_total": 5,
"item_discount": 0,
"discount_total": 0,
"grand_total": 5,
"date_created": "2022-04-26T15:51:30.324Z",
"date_updated": "2022-04-26T15:52:33.949Z",
"id": "DEEFRebs"
},
{
"active": true,
"name": "Test items",
"items": [
{
"product_id": "625daa41e6e0e30019c4a084",
"quantity": 1,
"price": 100,
"id": "625daa53e6e0e30019c4a2a3",
"orig_price": 100,
"delivery": "shipment",
"shipment_weight": 0,
"price_total": 100,
"discount_total": 50,
"discount_each": 50,
"discounts": [
{
"id": "coupon-0",
"amount": 50
}
]
}
],
"shipment_delivery": true,
"currency": "USD",
"sub_total": 100,
"item_discount": 50,
"discount_total": 50,
"grand_total": 50,
"date_created": "2022-04-18T17:51:34.937Z",
"date_updated": "2022-04-18T18:13:40.581Z",
"coupon_code": "SIMPLETEST",
"promotion_ids": [
null,
null,
null,
null,
null,
null,
null,
"625da6a2e6e0e30019c471dd"
],
"coupon_id": "625da691e6e0e30019c46fea",
"discounts": [
{
"type": "coupon",
"rule": {
"value_fixed": 50,
"type": "total",
"value_type": "fixed"
},
"amount": 50,
"id": "coupon-0"
}
],
"shipment_discount": null,
"id": "vASbh0zY"
},
{
"name": "NEW PURCHASE LINK",
"items": [
{
"purchase_option": {
"plan_id": "6256eb710c7aaf0012dd1731",
"billing_schedule": {
"interval": "weekly",
"interval_count": 1,
"trial_days": 0,
"limit": null
},
"type": "subscription",
"plan_name": "Weekly"
},
"quantity": 1,
"price": 65,
"product_id": "6256eb710c7aaf0012dd1722",
"id": "62599ad09a57a6001a8ca827",
"orig_price": 65,
"shipment_weight": 0,
"price_total": 65,
"discount_total": 0,
"discount_each": 0
}
],
"subscription_delivery": true,
"currency": "USD",
"sub_total": 65,
"item_discount": 0,
"discount_total": 0,
"grand_total": 65,
"date_created": "2022-04-15T16:18:24.644Z",
"active": true,
"date_updated": "2022-04-15T16:31:35.254Z",
"id": "midpIahm"
},
. . .
],
"page": 1,
"pages": {
"1": {
"start": 1,
"end": 15
},
"2": {
"start": 16,
"end": 30
},
"3": {
"start": 31,
"end": 39
}
}
}
Delete a purchase link.
Arguments
id
objectIdrequiredThe id for the purchase link to delete.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.delete('/purchaselinks/{id}', {
});
Response
{
"active": true,
"name": "Purchase link example",
"items": [
{
"product_id": "626034d4e7b741001968292d",
"quantity": 1,
"price": 5,
"price_total": 5,
"discount_total": 0,
"discount_each": 0,
"id": "62681502ea4c3f00138da5ea"
}
],
"currency": "USD",
"sub_total": 5,
"item_discount": 0,
"discount_total": 0,
"grand_total": 5,
"date_created": "2022-04-26T15:51:30.324Z",
"date_updated": "2022-04-26T15:52:33.949Z",
"id": "DEEFRebs"
}