Backend API
The coupon uses collection tracks each use of a coupon to ensure that coupon restrictions such as usage limits are maintained. Each coupon use relates the account and order to the coupon.
Fields
id
objectIdrequiredUnique identifier for the coupon use.
parent_id
objectIdrequiredID of the parent coupon.
parent
CouponExpandable link to the parent coupon.
date_created
daterequiredautoDate and time the coupon use was created.
date_updated
daterequiredautoDate and time the coupon use was last updated.
account_id
objectIdID of the customer's account.
order_id
objectIdrequiredID of the order that used the coupon.
order
OrderExpandable link to the order the coupon was applied to.
subscription_id
objectIdID of the subscription that spawned the coupon use, if applicable.
subscription
SubscriptionrequiredExpandable link to the subscription that spawned the coupon use, if applicable.
The coupon use model
{
"parent_id": "59c189016094a888436aee7f",
"code": "DAGOTHWAVE",
"code_id": "59c2c4a4c339b09853c6799c",
"account_id": "60d61bd6575eaa344eab5c83",
"order_id": "624319a0178e7f6c57bb3c49",
"date_created": "2022-05-11T18:00:43.894Z",
"id": "627bf9cb6d9c840012204a8a"
},
Create a new coupon use.
Arguments
id
objectIdUnique identifier for the coupon use.
order_id
objectIdUnique identifier for the order.
subscription_id
objectIdID of the subscription that spawned the order, if applicable.
account_id
objectIdUnique identifier for the account.
parent_id
objectIdrequiredID of the parent coupon.
code
stringrequiredCoupon code applied to the use.
code_id
objectIdrequiredThe ID of the coupon code.
date_created
dateDate and time the coupon use was created.
date_updated
dateDate and time the coupon use was last updated.
order
OrderExpandable link to the order.
parent
CouponExpandable link to the coupon.
subscription
SubscriptionExpandable link to the subscription.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.post('/coupons:uses', {
parent_id: '59c189016094a888436aee7f',
code: 'WELLMET',
code_id: '59c2c4a4c339b09853c6799c',
account_id: '6081ae962717ed7a555e0d29',
subscription_id: '623b3c95e75dd3013d6eac48'
});
The coupon use model
{
"parent_id": "59c189016094a888436aee7f",
"code": "DAGOTHWAVE",
"code_id": "59c2c4a4c339b09853c6799c",
"account_id": "60d61bd6575eaa344eab5c83",
"order_id": "624319a0178e7f6c57bb3c49",
"date_created": "2022-05-11T18:00:43.894Z",
"id": "627bf9cb6d9c840012204a8a"
},
Retrieve an existing coupon use using the ID that was returned when created.
Arguments
id
objectIdrequiredThe ID of the coupon use to retrieve.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/coupons:uses/{id}', {
});
The coupon use model
{
"parent_id": "59c189016094a888436aee7f",
"code": "DAGOTHWAVE",
"code_id": "59c2c4a4c339b09853c6799c",
"account_id": "60d61bd6575eaa344eab5c83",
"order_id": "624319a0178e7f6c57bb3c49",
"date_created": "2022-05-11T18:00:43.894Z",
"id": "627bf9cb6d9c840012204a8a"
},
Return a list of coupon uses.
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:uses', {
});
The coupon use model
{
"parent_id": "59c189016094a888436aee7f",
"code": "DAGOTHWAVE",
"code_id": "59c2c4a4c339b09853c6799c",
"account_id": "60d61bd6575eaa344eab5c83",
"order_id": "624319a0178e7f6c57bb3c49",
"date_created": "2022-05-11T18:00:43.894Z",
"id": "627bf9cb6d9c840012204a8a"
},
Delete a coupon use permanently.
Arguments
id
objectIdID of the coupon use.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.delete('/coupons:uses/{id}', {
});
The coupon use model
{
"parent_id": "59c189016094a888436aee7f",
"code": "DAGOTHWAVE",
"code_id": "59c2c4a4c339b09853c6799c",
"account_id": "60d61bd6575eaa344eab5c83",
"order_id": "624319a0178e7f6c57bb3c49",
"date_created": "2022-05-11T18:00:43.894Z",
"id": "627bf9cb6d9c840012204a8a"
},