Backend API
The promotion uses collection tracks each use of a promotion to ensure that promotion restrictions such as usage limits are maintained. Each promotion use relates the account and order to the promotion.
Fields
id
objectIdrequiredUnique identifier for the promotion use.
account_id
objectIdrequiredID of the customer's account.
date_created
daterequiredautoDate and time the promotion use was created.
date_updated
daterequiredautoDate and time the promotion use was last updated.
order
OrderrequiredExpandable link to the order the promotion was applied to.
order_id
objectIdrequiredID of the order that used the promotion.
parent
CouponrequiredExpandable link to the parent promotion.
parent_id
objectIdrequiredID of the parent promotion.
subscription
SubscriptionrequiredExpandable link to the subscription that spawned the promotion use, if applicable.
subscription_id
objectIdrequiredID of the subscription that spawned the promotion use, if applicable.
code
stringrequiredcode_id
objectIdrequiredThe promotion use model
{
"parent_id": "6285746dd0fc72001a6a2f4e",
"account_id": "628fb3c90f42a10014f04787",
"order_id": "62a09d0317f83f001975b491",
"date_created": "2022-06-08T13:08:10.445Z",
"id": "62a09f3a17f83f001975b4d1"
},
Create a new promotion use.
Arguments
parent_id
objectIdrequiredUnique identifier of the parent promotion.
id
objectIdID of the promotion use.
order_id
objectIdUnique identifier for the order that the promotion use is applied to.
subscription_id
objectIdID of the subscription plan.
account_id
objectIdID of the account connected to the promotion use.
date_created
dateDate and time the promotion use was created.
date_updated
dateDate and time the promotion use was last updated.
order
Orderparent
Promotionsubscription
Subscriptionconst swell = require('swell-node').init('store-id', 'secret-key');
await swell.post('/promotions:uses', {
order_id: '62bf11bb4b738e00141c51d6'
});
The promotion use model
{
"parent_id": "6285746dd0fc72001a6a2f4e",
"account_id": "628fb3c90f42a10014f04787",
"order_id": "62a09d0317f83f001975b491",
"date_created": "2022-06-08T13:08:10.445Z",
"id": "62a09f3a17f83f001975b4d1"
},
Retrieve an existing promotion use using the ID that was returned when created.
Arguments
id
objectIdThe ID of the promotion use to retrieve.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/promotions:uses/{id}', {
});
Response
{
"parent_id": "6285746dd0fc72001a6a2f4e",
"account_id": "628fb3c90f42a10014f04787",
"order_id": "62a09d0317f83f001975b491",
"date_created": "2022-06-08T13:08:10.445Z",
"id": "62a09f3a17f83f001975b4d1"
}
Return a list of promotion 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('/promotions:uses', {
where: {
active: true
},
limit: 25,
page: 1
});
The promotion use model
{
"count": 3,
"results": [
{
"parent_id": "6285746dd0fc72001a6a2f4e",
"account_id": "628fb3c90f42a10014f04787",
"order_id": "62a09d0317f83f001975b491",
"date_created": "2022-06-08T13:08:10.445Z",
"id": "62a09f3a17f83f001975b4d1"
},
{
"parent_id": "6285746dd0fc72001a6a2f4e",
"account_id": "6296b0ad8f4d1100129e16c3",
"order_id": "6296b2aa50a04b0012bc64c6",
"date_created": "2022-06-01T00:28:26.103Z",
"id": "6296b2aa50a04b0012bc64c7"
},
{
"parent_id": "6285746dd0fc72001a6a2f4e",
"account_id": "628fb3c90f42a10014f04787",
"order_id": "628fb3e10f42a10014f0478d",
"date_created": "2022-05-26T17:07:45.415Z",
"id": "628fb3e10f42a10014f0478e"
}
]
}
Delete a promotion use permanently.
Arguments
id
objectIdrequiredThe ID of the promotion use to delete.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.delete('/promotions:uses/{id}', {
id: '60f199509111e70000000074'
});
The promotion use model
{
"parent_id": "6285746dd0fc72001a6a2f4e",
"account_id": "628fb3c90f42a10014f04787",
"order_id": "62a09d0317f83f001975b491",
"date_created": "2022-06-08T13:08:10.445Z",
"id": "62a09f3a17f83f001975b4d1"
},