Backend API
Coupon codes are a collection of eligible codes that can be redeemed by a customer to receive the discount associated with the coupon. Codes are generated in batches and are stored on the coupon. Codes are associated with their generation instance and are also tracked with coupon uses.
Fields
id
objectIdUnique identifier for the coupon code.
code
stringautoGift card code to apply. A validation error will be returned if the code is not valid.
date_created
dateautoDate and time the coupon code was created.
date_updated
dateautoDate and time the coupon code was last updated.
gen_id
objectIdUnique ID corresponding to a coupon code generation.
orders
OrderExpandable list of orders that have applied the coupon code.
parent_id
objectIdrequiredID of the parent coupon, if applicable.
parent
CouponExpandable link to the parent coupon.
subscriptions
SubscriptionExpandable list of subscriptions that have applied the coupon code.
use_count
intNumber 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
parent_id
objectIdrequiredID of the parent coupon.
id
objectIdID of the coupon code.
code
stringUnique code to identify the coupon.
date_created
dateautoDate and time the coupon code was created.
date_updated
dateautoDate and time the coupon code was last updated.
gen_id
objectIdThe ID of the generation instance for a particular coupon code.
orders
Orderparent
CouponExpandable link to the parent coupon.
subscriptions
Subscriptionuse_count
intuse_total
intconst swell = require('swell-node').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
objectIdrequiredID of the coupon code.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/coupons:codes/{id}', {
});
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
id
objectIdrequiredUnique identifier for the coupon code.
code
stringconst swell = require('swell-node').init('store-id', 'secret-key');
await swell.put('/coupons:codes/{id}', {
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
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: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
objectIdrequiredID of the coupon code.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.delete('/coupons:codes/{id}', {
});
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"
}