Filter
What would you like to search for?
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
Unique identifier for the coupon.
A short descriptive name of the coupon.
Indicates the coupon is currently active. Note: this is not affected by `date_valid` and `date_expired`.
Expandable list of codes used to identify the coupon.
Three-letter ISO currency code in uppercase. Defaults to the store's base currency.
Date and time the coupon was created.
Date the coupon is considered expired and no longer available for use. When defined, the coupon will not be valid after this date.
Date and time the coupon was last updated.
Date the coupon is first available for use. When defined, the coupon will not be valid until after this date and before date_expired.
A brief description of the coupon, as it may be displayed to customers.
ID 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.
List of discount rules to apply.
Type of discount to apply. Can be total, product, category, or shipment.
Type of value to calculate discount amount. Can be fixed or percent.
ID of the category to discount, if applicable.
Expandable link to the discounted category, if applicable.
List of category IDs to exclude from discount, applicable to category discounts when several categories overlap.
Expandable list of excluded categories, if applicable.
Minimum product price required for the rule to apply, applicable for category and product discounts.
ID of the product to discount, if applicable.
Expandable link to the discounted product, if applicable.
Quantity of the product to add to cart, if applicable.
Maximum product quantity required for the rule to apply, applicable for category and product discounts.
Minimum product quantity required for the rule to apply, applicable for category and product discounts.
ID of the shipping service to discount, if applicable.
Minimum order total required for the rule to apply.
Fixed discount applied when value_type=fixed.
Percentage discount applied when value_type=percent.
ID of the variant to discount, if applicable.
Expandable link to the discounted variant, if applicable.
Items required to be purchased in order to receive the coupon.
Unique identifier for the product.
Expandable link to the product.
Unique identifier for the category.
Expandable link to the category.
Eligible discounted items available once a coupon's buy_items requirements are met.
Unique identifier for the product.
Expandable link to the product.
Unique identifier for the category.
Expandable link to the category.
Indicates whether the get_items promotion requirements have been met.
Maximum redeemable discount amount for the coupon.
Maximum number of times each coupon code can be applied. Mainly used with multiple codes.
Maximum number of times the coupon can be applied across all customers.
Maximum number of times the coupon can be used by each customer account.
List of customer account groups allowed to use the coupon.
Indicates the coupon is identified by multiple coupon codes.
Expandable list of orders that have applied the coupon.
Expandable list of subscriptions that have applied the coupon.
Number of times the coupon has been used.
Expandable list of coupon code usage records.
List of coupon generations.
List of coupon generations that are active.
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.
Arguments
A short descriptive name of the coupon.
A brief description of the coupon, as it may be displayed to customers.
Indicates the coupon is currently active. Note: this is not affected by `date_valid` and `date_expired`.
Date the coupon is considered expired and no longer available for use. When defined, the coupon will not be valid after this date.
List of discount rules to apply.
Type of discount to apply. Can be total, product, category, or shipment.
Type of discount amount to calculate. Can be fixed or percent.
Fixed discount applied when value_type=fixed.
Percentage discount applied when value_type=percent.
Minimum order total required for the rule to apply.
The maximum amount of a discount that can be redeemed.
The minimum amount of a discount that can be redeemed.
Minimum product quantity required for the rule to apply, applicable for category and product discounts.
Maximum product quantity for which the rule will apply, applicable for category and product discounts.
ID of the product to discount, if applicable.
ID of the variant to discount, if applicable.
Quantity of the product to add to cart, if applicable.
ID of the shipping service to discount, if applicable.
Unique identifier for the category.
List of category IDs excluded by the coupon.
Expandable link to the discounted product, if applicable.
Expandable link to the discounted variant, if applicable.
Expandable link to the discounted category, if applicable.
Expandable link to categories excluded from the promotion, if applicable.
Items required to be purchased in order to receive the coupon.
ID of the product that is tied to the promotion eligibility, if applicable.
Expandable link to the promotion-eligible product, if applicable.
ID of the category that is tied to the promotion eligibility, if applicable.
Expandable link to the promotion-eligible category, if applicable.
Eligible discounted items available once a coupon's buy_items requirements are met.
ID of the product to discount, if applicable.
Expandable link to the discounted product, if applicable.
ID of the discounted category, if applicable.
Expandable link to the discounted category, if applicable.
Expandable list of codes used to identify the coupon.
Indicates the coupon is identified by multiple coupon codes.
Date the coupon is first available for use. When defined, the coupon will not be valid until after this date and before `date_expired`.
Number of times the coupon has been used.
Maximum number of times the coupon can be applied across all customers.
Maximum number of times each coupon code can be applied. Mainly used with multiple codes.
Maximum number of times the coupon can be used by each customer account.
List of customer account groups allowed to use the coupon.
ID 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.
Expandable list of coupon code usage records.
Expandable list of orders that have applied the coupon.
Expandable list of subscriptions that have applied the coupon.
Three-letter ISO currency code in uppercase. Defaults to base currency.
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
The ID of the coupon to retrieve.
Expanding 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.
Return 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 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
Unique identifier for the coupon.
Indicates the coupon is currently active. Note: this is not affected by date_valid and date_expired.
Date the coupon is considered expired and no longer available for use. When defined, the coupon will not be valid after this date.
A short descriptive name of the coupon.
Expandable list of codes used to identify the coupon.
Three-letter ISO currency code in uppercase. Defaults to base currency.
Date the coupon is first available for use. When defined, the coupon will not be valid until after this date and before `date_expired`.
A brief description of the coupon, as it may be displayed to customers.
ID 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.
List of discount rules to apply.
Type of discount to apply. Can be total, product, category, or shipment.
Type of discount amount to calculate. Can be fixed or percent.
Fixed discount applied when value_type=fixed.
Percentage discount applied when value_type=percent.
Minimum order total required for the rule to apply.
The maximum amount of a discount that can be redeemed.
The minimum amount of a discount that can be redeemed.
Minimum product quantity required for the rule to apply, applicable for category and product discounts.
Maximum product quantity for which the rule will apply, applicable for category and product discounts.
ID of the product to discount, if applicable.
ID of the variant to discount, if applicable.
Quantity of the product to add to cart, if applicable.
ID of the shipping service to discount, if applicable.
Expandable link to the discounted product, if applicable.
Expandable link to the discounted variant, if applicable.
Expandable link to the discounted category, if applicable.
Expandable link to categories excluded from the promotion, if applicable.
List of items that need to be purchased before the promotion becomes eligible.
ID of the product that is tied to the promotion eligibility, if applicable.
Expandable link to the promotion-eligible product, if applicable.
ID of the category that is tied to the promotion eligibility, if applicable.
Expandable link to the promotion-eligible category, if applicable.
List of items eligible for promotion after designated products have been purchased.
ID of the product to discount, if applicable.
Expandable link to the discounted product, if applicable.
ID of the discounted category, if applicable.
Expandable link to the discounted category, if applicable.
List of customer account groups allowed to use the coupon.
Maximum number of times the coupon can be used by each customer account.
Maximum number of times each coupon code can be applied. Mainly used with multiple codes.
Maximum number of times the coupon can be applied across all customers.
Indicates the coupon is identified by multiple coupon codes.
Number 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 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.
Returns 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 one or more arbitrary queries in the response which are potentially related to the main query.
See including for more details.
Limit the number of records returned, ranging between 1 and 1000. Defaults to 15.
The page number of results to return given the specified or default limit.
A 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.
Expression 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.
An 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
The 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
}