Backend API
Promotions are a way to offer customers a discount without a coupon code, by automatically applying discounts to their cart. A promotion can have several discounts and exceptions. For example, a promotion discount can apply to a whole order, to particular categories, to individual products, or to shipping methods. A promotion can be limited to a maximum number of uses, by specific customer groups, and more.
Fields
id
objectIdUnique identifier for the promotion.
name
stringrequiredA short descriptive name of the promo.
active
booleanIndicates the promo is currently active. Note: this is not affected by date_start and date_end.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
date_created
dateautoDate and time the promotion was created.
date_end
daterequiredDate the promo ends and is no longer available. When defined, the promo will not be applied after this date.
date_start
dateDate the promo is first available. When defined, the promo will not be valid until after this date and before date_end.
date_updated
dateautoDate and time the promotion was last updated.
description
stringA brief description of the promo, as it may be displayed to customers.
discount_group
stringID of the discount group the promo belongs to, if applicable, as defined in discount settings. Used to ensure only one set of discount rules can apply across a number of coupons and promotions.
discounts
array of objectList of discount rules to apply.
.buy_items
array of objectItems required to be purchased in order to receive the promotion.
.category_id
objectIdUnique identifier for the category.
.category
categoryExpandable link to the category.
.product_id
objectIdUnique identifier for the product.
.product
productExpandable link to the product.
.category
categoryExpandable link to the discounted category, if applicable.
.category_id
objectIdID of the category to discount, if applicable.
.discount_max
currencyMaximum redeemable discount amount for the coupon.
.exclude_categories
exclude_categoriesExpandable list of excluded categories, if applicable.
.exclude_category_ids
array of category_idList of category IDs to exclude from discount, applicable to category discounts when several categories overlap.
.get_items
array of objectEligible discounted items available once promotion's buy_items requirements are met.
.category_id
objectIdUnique identifier for the category.
.category
categoryExpandable link to the category.
.product_id
objectIdUnique identifier for the product.
.product
productExpandable link to the product.
.get_total
booleanIndicates whether the get_items promotion requirements have been met.
.price_min
currencyMinimum product price required for the rule to apply, applicable for category and product discounts.
.product
productExpandable link to the discounted product, if applicable.
.product_id
objectIdID of the product to discount, if applicable.
.quantity_max
intMaximum product quantity for which the rule will apply, applicable for category and product discounts.
.quantity_min
intMinimum product quantity required for the rule to apply, applicable for category and product discounts.
.shipment_service
stringID of the shipping service to discount, if applicable.
.total_min
currencyMinimum order total required for the rule to apply.
.type
enumType of discount to apply. Can be total, product, category or shipment.
Possible enum values:
.value_fixed
currencyFixed discount applied when value_type=fixed.
.value_percent
floatPercentage discount applied when value_type=percent.
.variant_id
objectIdID of the variant to discount, if applicable.
.value_type
enumrequiredType of discount amount to calculate. Can be fixed or percent.
Possible enum values:
.variant
variantExpandable link to the discounted variant, if applicable.
exclusions
array of objectList of exclusions considered when the promo is applied.
.category_id
objectIdID of the category to exclude from the promo.
.category
categoryExpandable link to the category excluded from the promo.
.product_id
objectIdID of the product to exclude from the promo.
.product
productExpandable link to the product excluded from the promo.
.type
enumrequiredType of exclusion. Can be product or category.
Possible enum values:
limit_account_groups
array of account_groupsList of customer account for which the promo will apply.
limit_account_uses
intMaximum number of times the promo will be applied by each customer account.
limit_uses
intMaximum number of times the promo will be applied across all customers.
orders
OrderExpandable list of orders that have applied the promo.
subscriptions
SubscriptionExpandable list of subscriptions that have applied the promo.
use_count
intautoNumber of times the promo has been applied.
uses
array of UsesExpandable list of promotion use records.
The promotion model
{
"id": "60f199509111e7000000006b",
"name": "15% Off Store Wide Sale",
"active": true,
"currency": "USD",
"date_created": "2021-07-16T14:36:00.386Z",
"date_end": "2018-03-01T00:00:00.000Z",
"date_start": "2018-11-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.386Z",
"description": "Save 15% store wide for a limited time only.",
"discounts": [
{
"type": "total",
"value_type": "percent",
"value_fixed": 15
}
],
"limit_account_uses": 3,
"limit_uses": 300,
"use_count": 142
}
Create a new promotion. If you wish to generate your own unique ID for the record, it must use BSON ObjectID format for compatibility.
Arguments
name
stringrequiredA short descriptive name of the promo.
description
stringA brief description of the promo, as it may be displayed to customers.
active
booleanIndicates the promo is currently active. Note: this is not affected by date_start and date_end.
date_start
dateDate the promo is first available. When defined, the promo will not be valid until after this date and before date_end.
date_end
dateDate the promo ends and is no longer available. When defined, the promo will not be applied after this date.
discounts
array of objectrequiredList of discount rules to apply.
.type
enumType of discount to apply. Can be total, product, category, or shipment.
Possible enum values:
.value_type
enumrequiredType of discount amount to calculate. Can be fixed or percent.
Possible enum values:
.value_fixed
currencyFixed discount applied when value_type=fixed.
.value_percent
floatPercentage discount applied when value_type=percent.
.total_min
currencyMinimum order total required for the rule to apply.
.discount_max
currencyThe maximum amount of a discount that can be redeemed.
.price_min
currencyThe minimum amount of a discount that can be redeemed.
.quantity_min
intMinimum product quantity required for the rule to apply, applicable for category and product discounts.
.quantity_max
intMaximum product quantity for which the rule will apply, applicable for category and product discounts.
.product_id
objectIdID of the product to discount, if applicable.
.variant_id
objectIdID of the variant to discount, if applicable.
.shipment_service
stringID of the shipping service to discount, if applicable.
.category_id
objectIdID of the category to discount, if applicable.
.exclude_category_ids
array of child_scalarList of category IDs to exclude from discount, applicable to category discounts when several categories overlap.
.product
productExpandable link to the discounted product, if applicable.
.variant
variantExpandable link to the discounted variant, if applicable.
.category
categoryExpandable link to the discounted category, if applicable.
.exclude_categories
exclude_categoriesExpandable list of excluded categories, if applicable.
.buy_items
array of objectItems required to be purchased in order to receive the promotion.
.product_id
objectIdID of the product that is tied to the promotion eligibility, if applicable.
.product
productExpandable link to the promotion-eligible product, if applicable.
.category_id
objectIdID of the category that is tied to the promotion eligibility, if applicable.
.category
categoryExpandable link to the promotion-eligible category, if applicable.
.get_items
array of objectEligible discounted items available once promotion's buy_items requirements are met.
.product_id
objectIdID of the product to discount, if applicable.
.product
productExpandable link to the discounted product, if applicable.
.category_id
objectIdID of the discounted category, if applicable.
.category
categoryExpandable link to the discounted category, if applicable.
.get_total
booleanIndicates whether the get_items promotion requirements have been met.
use_count
intNumber of times the promo has been applied.
limit_uses
intMaximum number of times the promo will be applied across all customers.
limit_account_uses
intMaximum number of times the promo will be applied by each customer account.
limit_account_groups
array of child_scalarList of customer account for which the promo will apply.
discount_group
stringID of the discount group the promo belongs to, if applicable, as defined in discount settings. Used to ensure only one set of discount rules can apply across a number of coupons and promotions.
exclusions
array of objectList of exclusions considered when the promo is applied.
.type
enumrequiredThe type of exclusion for the promotion. Can be either product or category.
Possible enum values:
.product_id
objectIdID of the product to exclude from the discount, if applicable.
.category_id
objectIdID of the category to exclude from the discount, if applicable.
.product
productExpandable link to the excluded product, if applicable.
.category
categoryExpandable link to the excluded category, if applicable.
uses
Promotion UseExpandable list of promo usage records.
orders
OrderExpandable list of orders that have applied the promo.
subscriptions
SubscriptionExpandable list of subscriptions that have applied the promo.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
limit_account_segments
array of child_scalarconst swell = require('swell-node').init('store-id', 'secret-key');
await swell.post('/promotions', {
discounts: [
{
type: 'total',
value_type: 'percent',
value_fixed: 15
}
],
name: '15% Off Store Wide Sale',
active: true,
date_end: '2018-03-01T00:00:00.000Z',
date_start: '2018-11-01T00:00:00.000Z',
description: 'Save 15% store wide for a limited time only.'
});
Response
{
"id": "60f199509111e7000000006b",
"name": "15% Off Store Wide Sale",
"active": true,
"currency": "USD",
"date_created": "2021-07-16T14:36:00.386Z",
"date_end": "2018-03-01T00:00:00.000Z",
"date_start": "2018-11-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.386Z",
"description": "Save 15% store wide for a limited time only.",
"discounts": [
{
"type": "total",
"value_type": "percent",
"value_fixed": 15
}
],
"limit_account_uses": 3,
"limit_uses": 300,
"use_count": 142
}
Retrieve an existing promotion using the ID that was returned when created.
Arguments
id
objectIdrequiredThe ID of the promotion 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('/promotions/{id}', {
id: '60f199509111e7000000006e'
});
Response
{
"id": "60f199509111e70000000071",
"name": "15% Off Store Wide Sale",
"active": true,
"currency": "USD",
"date_created": "2021-07-16T14:36:00.386Z",
"date_end": "2018-03-01T00:00:00.000Z",
"date_start": "2018-11-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.386Z",
"description": "Save 15% store wide for a limited time only.",
"discounts": [
{
"type": "total",
"value_type": "percent",
"value_fixed": 15
}
],
"limit_account_uses": 3,
"limit_uses": 300,
"use_count": 142
}
Update an existing promotion using the ID that was returned when created.
Arguments
id
objectIdrequiredUnique identifier for the promotion.
active
booleanIndicates the promo is currently active. Note: this is not affected by date_start and date_end.
date_end
dateDate the promo ends and is no longer available. When defined, the promo will not be applied after this date.
name
stringA short descriptive name of the promo.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
date_start
dateDate the promo is first available. When defined, the promo will not be valid until after this date and before date_end.
description
stringA brief description of the promo, as it may be displayed to customers.
discount_group
stringID of the discount group the promo belongs to, if applicable, as defined in discount settings. Used to ensure only one set of discount rules can apply across a number of coupons and promotions.
discounts
array of objectrequiredList of discount rules to apply.
.type
enumType of discount to apply. Can be total, product, category, or shipment.
Possible enum values:
.value_type
enumrequiredType of discount amount to calculate. Can be fixed or percent.
Possible enum values:
.value_fixed
currencyFixed discount applied when value_type=fixed.
.value_percent
floatPercentage discount applied when value_type=percent.
.total_min
currencyMinimum order total required for the rule to apply.
.discount_max
currencyThe maximum amount of a discount that can be redeemed.
.price_min
currencyThe mimimum amount of a discount that can be redeemed.
.quantity_min
intMinimum product quantity required for the rule to apply, applicable for category and product discounts.
.quantity_max
intMaximum product quantity for which the rule will apply, applicable for category and product discounts.
.product_id
objectIdID of the product to discount, if applicable.
.variant_id
objectIdID of the variant to discount, if applicable.
.shipment_service
stringID of the shipping service to discount, if applicable.
.category_id
objectIdID of the category to discount, if applicable.
.exclude_category_ids
array of child_scalarList of category IDs to exclude from discount, applicable to category discounts when several categories overlap.
.product
productExpandable link to the discounted product, if applicable.
.variant
variantExpandable link to the discounted variant, if applicable.
.category
categoryExpandable link to the discounted category, if applicable.
.exclude_categories
exclude_categoriesExpandable list of excluded categories, if applicable.
.buy_items
array of objectList of items that need to be purchased before the promotion becomes eligible.
.product_id
objectIdID of the product that is tied to the promotion eligibility, if applicable.
.product
productExpandable link to the promotion-eligible product, if applicable.
.category_id
objectIdID of the category that is tied to the promotion eligibility, if applicable.
.category
categoryExpandable link to the promotion-eligible category, if applicable.
.get_items
array of objectList of items eligible for promotion after designated products have been purchased.
product_id
objectIdID of the product to discount, if applicable.
product
productExpandable link to the discounted product, if applicable.
category_id
objectIdID of the discounted category, if applicable.
category
categoryExpandable link to the discounted category, if applicable.
.get_total
booleanexclusions
array of objectList of exclusions considered when the promo is applied.
.type
enumrequiredThe type of exclusion for the promotion. Can be either product or category.
Possible enum values:
.product_id
objectIdID of the product to exclude from the discount, if applicable.
.category_id
objectIdID of the category to exclude from the discount, if applicable.
.product
productExpandable link to the excluded product, if applicable.
.category
categoryExpandable link to the excluded category, if applicable.
use_count
intNumber of times the promo has been applied.
limit_uses
intMaximum number of times the promo will be applied across all customers.
limit_account_uses
intMaximum number of times the promo will be applied by each customer account.
limit_account_groups
array of child_scalarList of customer account for which the promo will apply.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.put('/promotions/{id}', {
id: '60f199509111e7000000006b',
limit_uses: 300,
active: true
});
Response
{
"id": "60f199509111e7000000006b",
"name": "15% Off Store Wide Sale",
"active": true,
"currency": "USD",
"date_created": "2021-07-16T14:36:00.386Z",
"date_end": "2018-03-01T00:00:00.000Z",
"date_start": "2018-11-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.386Z",
"description": "Save 15% store wide for a limited time only.",
"discounts": [
{
"type": "total",
"value_type": "percent",
"value_fixed": 15
}
],
"limit_account_uses": 3,
"limit_uses": 300,
"use_count": 142
}
Return a list of promotions.
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('/promotions', {
where: {
active: true
},
limit: 25,
page: 1
});
Response
{
"count": 51,
"results": [
{
"id": "60f199509111e7000000006b",
"name": "15% Off Store Wide Sale",
"active": true,
"currency": "USD",
"date_created": "2021-07-16T14:36:00.386Z",
"date_end": "2018-03-01T00:00:00.000Z",
"date_start": "2018-11-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.386Z",
"description": "Save 15% store wide for a limited time only.",
"discounts": [
{
"type": "total",
"value_type": "percent",
"value_fixed": 15
}
],
"limit_account_uses": 3,
"limit_uses": 300,
"use_count": 142
},
{...},
{...}
],
"page": 1,
"pages": {
"1": {
"start": 1,
"end": 25
},
"2": {
"start": 26,
"end": 50
},
"2": {
"start": 51,
"end": 51
}
}
}
Delete a promotion permanently.
Arguments
id
objectIdrequiredThe id of the promotion to delete.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.delete('/promotions/{id}', {
id: '60f199509111e70000000074'
});
Response
{
"id": "60f199509111e70000000077",
"name": "15% Off Store Wide Sale",
"active": true,
"currency": "USD",
"date_created": "2021-07-16T14:36:00.386Z",
"date_end": "2018-03-01T00:00:00.000Z",
"date_start": "2018-11-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.386Z",
"description": "Save 15% store wide for a limited time only.",
"discounts": [
{
"type": "total",
"value_type": "percent",
"value_fixed": 15
}
],
"limit_account_uses": 3,
"limit_uses": 300,
"use_count": 142
}