Backend API
Coupons are a way to offer customers a discount with a coupon code. A coupon can have several discounts and exceptions. For example, a coupon discount can apply to a whole order, to particular categories, to individual products, or to shipping methods. A coupon can be limited to a maximum number of uses, by specific customer groups, by expiration date, and more.
Fields
id
objectIdUnique identifier for the coupon.
name
stringrequiredA short descriptive name of the coupon.
active
booleanIndicates the coupon is currently active. Note: this is not affected by `date_valid` and `date_expired`.
active_generations
Coupon generationList of coupon generations that are active.
codes
array of CodesExpandable list of codes used to identify the coupon.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
date_created
dateDate and time the coupon was created.
date_expired
dateDate the coupon is considered expired and no longer available for use. When defined, the coupon will not be valid after this date.
date_updated
dateDate and time the coupon was last updated.
date_valid
dateDate the coupon is first available for use. When defined, the coupon will not be valid until after this date and before date_expired.
description
stringA brief description of the coupon, as it may be displayed to customers.
discount_group
stringID of the discount group the coupon 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.
.type
enumType of discount to apply. Can be total, product, category, or shipment.
Possible enum values:
.value_type
enumrequiredType of value to calculate discount amount. Can be fixed or percent.
Possible enum values:
.category_id
objectIdID of the category to discount, if applicable.
.category
categoryExpandable link to the discounted category, if applicable.
.exclude_category_ids
array of child_scalarrequiredList of category IDs to exclude from discount, applicable to category discounts when several categories overlap.
.exclude_categories
exclude_categoriesrequiredExpandable list of excluded categories, if applicable.
.price_min
currencyMinimum product price required for the rule to apply, applicable for category and product discounts.
.product_id
objectIdID of the product to discount, if applicable.
.product
productExpandable link to the discounted product, if applicable.
.quantity_add
intQuantity of the product to add to cart, if applicable.
.quantity_max
intMaximum product quantity required for the rule to 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
stringrequiredID of the shipping service to discount, if applicable.
.total_min
currencyMinimum order total required for the rule to apply.
.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.
.variant
variantrequiredExpandable link to the discounted variant, if applicable.
.buy_items
array of objectItems required to be purchased in order to receive the coupon.
.product_id
objectIdUnique identifier for the product.
.product
productExpandable link to the product.
.category_id
objectIdUnique identifier for the category.
.category
categoryrequiredExpandable link to the category.
.get_items
array of objectEligible discounted items available once a coupon's buy_items requirements are met.
.product_id
objectIdUnique identifier for the product.
.product
productExpandable link to the product.
.category_id
objectIdUnique identifier for the category.
.category
categoryExpandable link to the category.
.get_total
booleanIndicates whether the get_items promotion requirements have been met.
.discount_max
currencyMaximum redeemable discount amount for the coupon.
generations
array of GenerationsList of coupon generations.
limit_code_uses
intMaximum number of times each coupon code can be applied. Mainly used with multiple codes.
limit_uses
intMaximum number of times the coupon can be applied across all customers.
limit_account_uses
intMaximum number of times the coupon can be used by each customer account.
limit_account_groups
array of account_groupsList of customer account groups allowed to use the coupon.
limit_subscription_uses
intMaximum number of invoices the promotion may be applied to for a subscription.
multi_codes
booleanIndicates the coupon is identified by multiple coupon codes.
orders
OrderExpandable list of orders that have applied the coupon.
subscriptions
SubscriptionExpandable list of subscriptions that have applied the coupon.
use_count
intNumber of times the coupon has been used.
uses
array of UsesExpandable list of coupon code usage records.
The coupon model
{
"id": "60f199509111e70000000015",
"name": "10% Off Winter Jacket Sale",
"active": true,
"codes": [
{
"code": "WINTER10"
}
],
"currency": "USD",
"date_created": "2021-07-16T14:36:00.100Z",
"date_expired": "2018-03-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.100Z",
"date_valid": "2018-11-01T00:00:00.000Z",
"description": "Save 10% on all Winter Jackets for a limited time only.",
"discount_group": null,
"discounts": [
{
"type": "category",
"category_id": "5a97242bc65396a875c2d381",
"value_type": "percent",
"value_fixed": 10
}
],
"limit_account_uses": 3,
"limit_code_uses": 10,
"limit_uses": 300,
"multi_codes": false,
"use_count": 184
}
Create a new coupon. 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 coupon.
active
booleanIndicates the coupon is currently active. Note: this is not affected by `date_valid` and `date_expired`.
codes
array of CodesrequiredExpandable list of codes used to identify the coupon.
date_expired
dateDate the coupon is considered expired and no longer available for use. When defined, the coupon will not be valid after this date.
description
stringA brief description of the coupon, as it may be displayed to customers.
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.
.quantity_add
intQuantity of the product to add to cart, if applicable.
.shipment_service
stringID of the shipping service to discount, if applicable.
.category_id
objectIdUnique identifier for the category.
.exclude_category_ids
array of child_scalarList of category IDs excluded by the coupon.
.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 link to categories excluded from the promotion, if applicable.
.buy_items
array of objectItems required to be purchased in order to receive the coupon.
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 a coupon'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
booleanmulti_codes
booleanIndicates the coupon is identified by multiple coupon codes.
active_generations
Coupon generationList of coupon generations that are active.
currency
stringThree-letter ISO currency code in uppercase. Defaults to base currency.
date_valid
dateDate the coupon is first available for use. When defined, the coupon will not be valid until after this date and before `date_expired`.
discount_group
stringID of the discount group the coupon 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.
generations
array of GenerationsList of coupon generations.
limit_account_groups
array of child_scalarList of customer account groups allowed to use the coupon.
limit_account_segments
array of child_scalarList of account segments for which the coupon is avaialble.
limit_account_uses
intMaximum number of times the coupon can be used by each customer account.
limit_code_uses
intMaximum number of times each coupon code can be applied. Mainly used with multiple codes.
limit_subscription_uses
intMaximum number of invoices the promotion may be applied to for a subscription.
limit_uses
intMaximum number of times the coupon can be applied across all customers.
orders
OrderExpandable list of orders that have applied the coupon.
subscriptions
SubscriptionExpandable list of subscriptions that have applied the coupon.
use_count
intNumber of times the coupon has been used.
uses
Promotion UseExpandable list of coupon code usage records.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.post('/coupons', {
codes: [
{
code: 'WINTER10'
}
],
discounts: [
{
type: 'category',
category_id: '5a97242bc65396a875c2d381',
value_type: 'percent',
value_fixed: 10
}
],
name: '10% Off Winter Jacket Sale',
active: true,
date_expired: '2018-03-01T00:00:00.000Z',
description: 'Save 10% on all Winter Jackets for a limited time only.',
multi_codes: false
});
Response
{
"id": "60f199509111e70000000015",
"name": "10% Off Winter Jacket Sale",
"active": true,
"codes": [
{
"code": "WINTER10"
}
],
"currency": "USD",
"date_created": "2021-07-16T14:36:00.100Z",
"date_expired": "2018-03-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.100Z",
"date_valid": "2018-11-01T00:00:00.000Z",
"description": "Save 10% on all Winter Jackets for a limited time only.",
"discount_group": null,
"discounts": [
{
"type": "category",
"category_id": "5a97242bc65396a875c2d381",
"value_type": "percent",
"value_fixed": 10
}
],
"limit_account_uses": 3,
"limit_code_uses": 10,
"limit_uses": 300,
"multi_codes": false,
"use_count": 184
}
Retrieve an existing coupon using the ID that was returned when created.
Arguments
id
objectIdrequiredThe ID of the coupon 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('/coupons/{id}', {
id: '60f199509111e70000000018'
});
Response
{
"id": "60f199509111e7000000001b",
"name": "10% Off Winter Jacket Sale",
"active": true,
"codes": [
{
"code": "WINTER10"
}
],
"currency": "USD",
"date_created": "2021-07-16T14:36:00.100Z",
"date_expired": "2018-03-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.100Z",
"date_valid": "2018-11-01T00:00:00.000Z",
"description": "Save 10% on all Winter Jackets for a limited time only.",
"discount_group": null,
"discounts": [
{
"type": "category",
"category_id": "5a97242bc65396a875c2d381",
"value_type": "percent",
"value_fixed": 10
}
],
"limit_account_uses": 3,
"limit_code_uses": 10,
"limit_uses": 300,
"multi_codes": false,
"use_count": 184
}
Update an existing coupon using the ID that was returned when created.
Arguments
id
objectIdrequiredUnique identifier for the coupon.
active
booleanIndicates the coupon is currently active. Note: this is not affected by date_valid and date_expired.
date_expired
dateDate the coupon is considered expired and no longer available for use. When defined, the coupon will not be valid after this date.
name
stringA short descriptive name of the coupon.
codes
array of CodesrequiredExpandable list of codes used to identify the coupon.
currency
stringThree-letter ISO currency code in uppercase. Defaults to base currency.
date_valid
dateDate the coupon is first available for use. When defined, the coupon will not be valid until after this date and before `date_expired`.
description
stringA brief description of the coupon, as it may be displayed to customers.
discount_group
stringID of the discount group the coupon 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 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.
.quantity_add
intQuantity of the product to add to cart, if applicable.
.shipment_service
stringID of the shipping service to discount, if applicable.
.category_id
objectId.exclude_category_ids
array of child_scalar.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 link to categories excluded from the promotion, 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
booleanlimit_account_groups
array of child_scalarList of customer account groups allowed to use the coupon.
limit_account_uses
intMaximum number of times the coupon can be used by each customer account.
limit_subscription_uses
intMaximum number of invoices the promotion may be applied to for a subscription.
limit_code_uses
intMaximum number of times each coupon code can be applied. Mainly used with multiple codes.
limit_uses
intMaximum number of times the coupon can be applied across all customers.
multi_codes
booleanIndicates the coupon is identified by multiple coupon codes.
use_count
intNumber of times the coupon has been used.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.put('/coupons/{id}', {
id: '60f199509111e70000000015',
limit_uses: 300,
active: true
});
Response
{
"id": "60f199509111e70000000015",
"name": "10% Off Winter Jacket Sale",
"active": true,
"codes": [
{
"code": "WINTER10"
}
],
"currency": "USD",
"date_created": "2021-07-16T14:36:00.100Z",
"date_expired": "2018-03-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.100Z",
"date_valid": "2018-11-01T00:00:00.000Z",
"description": "Save 10% on all Winter Jackets for a limited time only.",
"discount_group": null,
"discounts": [
{
"type": "category",
"category_id": "5a97242bc65396a875c2d381",
"value_type": "percent",
"value_fixed": 10
}
],
"limit_account_uses": 3,
"limit_code_uses": 10,
"limit_uses": 300,
"multi_codes": false,
"use_count": 184
}
Return a list of coupons.
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('/coupons', {
where: {
active: true
},
limit: 25,
page: 1
});
Response
{
"count": 51,
"results": [
{
"id": "60f199509111e70000000015",
"name": "10% Off Winter Jacket Sale",
"active": true,
"codes": [
{
"code": "WINTER10"
}
],
"currency": "USD",
"date_created": "2021-07-16T14:36:00.100Z",
"date_expired": "2018-03-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.100Z",
"date_valid": "2018-11-01T00:00:00.000Z",
"description": "Save 10% on all Winter Jackets for a limited time only.",
"discount_group": null,
"discounts": [
{
"type": "category",
"category_id": "5a97242bc65396a875c2d381",
"value_type": "percent",
"value_fixed": 10
}
],
"limit_account_uses": 3,
"limit_code_uses": 10,
"limit_uses": 300,
"multi_codes": false,
"use_count": 184
},
{...},
{...}
],
"page": 1,
"pages": {
"1": {
"start": 1,
"end": 25
},
"2": {
"start": 26,
"end": 50
},
"2": {
"start": 51,
"end": 51
}
}
}
Delete a coupon permanently.
Arguments
id
objectIdrequiredThe ID of the coupon to delete.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.delete('/coupons/{id}', {
id: '60f199509111e7000000001e'
});
Response
{
"id": "60f199509111e70000000021",
"name": "10% Off Winter Jacket Sale",
"active": true,
"codes": [
{
"code": "WINTER10"
}
],
"currency": "USD",
"date_created": "2021-07-16T14:36:00.100Z",
"date_expired": "2018-03-01T00:00:00.000Z",
"date_updated": "2021-07-16T14:36:00.100Z",
"date_valid": "2018-11-01T00:00:00.000Z",
"description": "Save 10% on all Winter Jackets for a limited time only.",
"discount_group": null,
"discounts": [
{
"type": "category",
"category_id": "5a97242bc65396a875c2d381",
"value_type": "percent",
"value_fixed": 10
}
],
"limit_account_uses": 3,
"limit_code_uses": 10,
"limit_uses": 300,
"multi_codes": false,
"use_count": 184
}