Backend API
Coupon codes are a collection of eligible codes that can be applied to a cart, order or subscription, by a customer to receive the discount associated with the coupon.
For coupons with multiple codes, codes are generated in batches and are stored on the coupon. In this case, codes are associated with their generation instance and are also tracked with coupon uses.
When a coupon is applied, a validation error may be returned if the code is not considered valid or not applicable. The following are approximate error messages, but actual error message text may vary.
- Coupon code not found
- Coupon is not active
- Coupon is not valid (when date_valid > current).
- Coupon is expired (when date_expired < current)
- Coupon usage limit has been reached
- Coupon code usage limit has been reached
- Coupon is not applicable for this account
- Coupon account usage limit has been reached
Fields
Unique identifier for the coupon code.
Code used to apply the coupon to a cart, order or subscription. A validation error will be returned if the code is not valid.
Date and time the coupon code was created.
Date and time the coupon code was last updated.
Unique ID corresponding to a coupon code generation.
Expandable list of orders that have applied the coupon code.
ID of the parent coupon, if applicable.
Expandable link to the parent coupon.
Expandable list of subscriptions that have applied the coupon code.
Number of times the coupon code has been used.
The coupon code model
{
"gen_id": "62b5cdffd7ad010018c66249",
"parent_id": "62b5cdff2e40ab001ac27240",
"use_count": 0,
"date_created": "2022-06-24T14:45:20.941Z",
"use_total": 0,
"code": "PNB83100017",
"id": "62b5ce0079c5d80012fe5f65"
}Create a new coupon code.
Arguments
ID of the parent coupon.
ID of the coupon code.
Unique code to identify the coupon.
Date and time the coupon code was created.
Date and time the coupon code was last updated.
The ID of the generation instance for a particular coupon code.
Expandable link to the parent coupon.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.post('/coupons:codes', {
code: 'ALCHEMY25',
parent_id: '62cc86897ad4f100132c953d'
});The coupon code model
{
"gen_id": "62b5cdffd7ad010018c66249",
"parent_id": "62b5cdff2e40ab001ac27240",
"use_count": 0,
"date_created": "2022-06-24T14:45:20.941Z",
"use_total": 0,
"code": "PNB83100017",
"id": "62b5ce0079c5d80012fe5f65"
}Retrieve an existing coupon code using the ID that was returned when created.
Arguments
ID of the coupon code.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.get('/coupons:codes/{id}', {
id: '62cc86897ad4f100132c953e'
});The coupon code model
{
"gen_id": "62b5cdffd7ad010018c66249",
"parent_id": "62b5cdff2e40ab001ac27240",
"use_count": 0,
"date_created": "2022-06-24T14:45:20.941Z",
"use_total": 0,
"code": "PNB83100017",
"id": "62b5ce0079c5d80012fe5f65"
}Update an existing coupon code using the ID that was returned when created.
Arguments
Unique identifier for the coupon code.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.put('/coupons:codes/{id}', {
id: '62cc86897ad4f100132c953e',
code: 'SKOOMA15'
});The coupon code model
{
"gen_id": "62b5cdffd7ad010018c66249",
"parent_id": "62b5cdff2e40ab001ac27240",
"use_count": 0,
"date_created": "2022-06-24T14:45:20.941Z",
"use_total": 0,
"code": "PNB83100017",
"id": "62b5ce0079c5d80012fe5f65"
}Return a list of coupon codes.
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');
swell.init('store-id', 'secret-key');
await swell.get('/coupons:codes', {
});The coupon code model
{
"gen_id": "62b5cdffd7ad010018c66249",
"parent_id": "62b5cdff2e40ab001ac27240",
"use_count": 0,
"date_created": "2022-06-24T14:45:20.941Z",
"use_total": 0,
"code": "PNB83100017",
"id": "62b5ce0079c5d80012fe5f65"
}Delete a coupon code permanently.
Arguments
ID of the coupon code.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.delete('/coupons:codes/{id}', {
id: '62cc86897ad4f100132c953e'
});The coupon code model
{
"gen_id": "62b5cdffd7ad010018c66249",
"parent_id": "62b5cdff2e40ab001ac27240",
"use_count": 0,
"date_created": "2022-06-24T14:45:20.941Z",
"use_total": 0,
"code": "PNB83100017",
"id": "62b5ce0079c5d80012fe5f65"
}