Backend API
Coupon generations track the instances for which coupon codes are generated for a particular coupon. Each batch of generations is tied to an entry and is stored on the coupon model.
Fields
id
objectIdUnique identifier for the coupon codes generated.
codes
Coupon codeAn array of coupon codes to be generated.
count
intrequiredSpecifies the number of codes to be generated and limit for generations is 10,000. For example, count=100 would generate 100 coupon codes.
date_created
dateautoDate the coupon code is generated.
date_updated
dateautoDate the coupon code was last updated.
parent
CouponExpandable link to the parent coupon.
parent_id
objectIdrequiredUnique identifier of the parent coupon.
pattern
stringSpecifies the code pattern for generated coupons.
pattern_type
enumDetermines the pattern type for the codes generated, which can be either default or custom. Specify the pattern when using custom.
Possible enum values:
The coupon generation model
{
"complete": true,
"count": 1000,
"date_created": "2015-09-02T20:57:03.441Z",
"date_updated": "2015-09-02T20:57:20.033Z",
"parent_id": "559c5799bcb1de1d1c4821da",
"pattern": "TABATHA-{0000000}",
"pattern_type": "custom",
"id": "55e7629f5c0dfa1e3c2dd4c1"
},
Create a new coupon generation.
Arguments
id
objectIdID of the coupon generation.
count
intrequiredThe number of coupon codes generated in the generation. Minimum of 0 and maximum of 1000.
parent_id
objectIdrequiredID of the parent coupon.
codes
Coupon codeExpandable link to the coupon code.
complete
booleanIndicates that the coupon code generation is complete.
date_created
dateautoDate and time the coupon generation was created.
date_updated
dateautoDate and time the coupon generation was last updated.
error
stringIndicates if there was an error with the coupon code generation.
parent
CouponExpandable link to the parent coupon.
pattern
stringSpecifies the code pattern for generated coupons.
pattern_type
stringDetermines the pattern type for the codes generated, which can be either default or custom. Specify the pattern when using custom.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.post('/coupons:generations', {
pattern_type: default
count: 10
});
The coupon generation model
{
"complete": true,
"count": 1000,
"date_created": "2015-09-02T20:57:03.441Z",
"date_updated": "2015-09-02T20:57:20.033Z",
"parent_id": "559c5799bcb1de1d1c4821da",
"pattern": "TABATHA-{0000000}",
"pattern_type": "custom",
"id": "55e7629f5c0dfa1e3c2dd4c1"
},
Retrieve an existing coupon generation using the ID that was returned when created.
Arguments
id
objectIdrequiredThe ID of the coupon generation to retrieve.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.get('/coupons:generations/{id}', {
});
The coupon generation model
{
"complete": true,
"count": 1000,
"date_created": "2015-09-02T20:57:03.441Z",
"date_updated": "2015-09-02T20:57:20.033Z",
"parent_id": "559c5799bcb1de1d1c4821da",
"pattern": "TABATHA-{0000000}",
"pattern_type": "custom",
"id": "55e7629f5c0dfa1e3c2dd4c1"
},
Update an existing coupon generation using the ID that was returned when created.
Arguments
id
objectIdrequiredUnique identifier for the coupon generation.
count
intconst swell = require('swell-node').init('store-id', 'secret-key');
await swell.put('/coupons:generations/{id}', {
count: 10
});
The coupon generation model
{
"complete": true,
"count": 1000,
"date_created": "2015-09-02T20:57:03.441Z",
"date_updated": "2015-09-02T20:57:20.033Z",
"parent_id": "559c5799bcb1de1d1c4821da",
"pattern": "TABATHA-{0000000}",
"pattern_type": "custom",
"id": "55e7629f5c0dfa1e3c2dd4c1"
},
Return a list of coupon generations.
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:generations', {
});
The coupon generation model
{
"complete": true,
"count": 1000,
"date_created": "2015-09-02T20:57:03.441Z",
"date_updated": "2015-09-02T20:57:20.033Z",
"parent_id": "559c5799bcb1de1d1c4821da",
"pattern": "TABATHA-{0000000}",
"pattern_type": "custom",
"id": "55e7629f5c0dfa1e3c2dd4c1"
},
Delete a coupon generation permanently.
Arguments
id
objectIdrequiredThe ID of the coupon generation to delete.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.delete('/coupons:generations/{id}', {
});
The coupon generation model
{
"complete": true,
"count": 1000,
"date_created": "2015-09-02T20:57:03.441Z",
"date_updated": "2015-09-02T20:57:20.033Z",
"parent_id": "559c5799bcb1de1d1c4821da",
"pattern": "TABATHA-{0000000}",
"pattern_type": "custom",
"id": "55e7629f5c0dfa1e3c2dd4c1"
},