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

idobjectId

Unique identifier for the coupon codes generated.

countintrequired

Specifies the number of codes to be generated and limit for generations is 10,000. For example, count=100 would generate 100 coupon codes.

parent_idobjectIdrequired

Unique identifier of the parent coupon.

codesarray of link

An array of coupon codes to be generated.

date_createddateauto

Date the coupon code is generated.

date_updateddateauto

Date the coupon code was last updated.

parentCoupon

Expandable link to the parent coupon.

patternstring

Specifies the code pattern for generated coupons.

pattern_typeenum

Determines the pattern type for the codes generated, which can be either default or custom. Specify the pattern when using custom.

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

idobjectId

ID of the coupon generation.

countintrequired

The number of coupon codes generated in the generation. Minimum of 0 and maximum of 1000.

parent_idobjectIdrequired

ID of the parent coupon.

codesCoupon code

Expandable link to the coupon code.

completeboolean

Indicates that the coupon code generation is complete.

date_createddateauto

Date and time the coupon generation was created.

date_updateddateauto

Date and time the coupon generation was last updated.

errorstring

Indicates if there was an error with the coupon code generation.

parentCoupon

Expandable link to the parent coupon.

patternstring

Specifies the code pattern for generated coupons.

pattern_typestring

Determines the pattern type for the codes generated, which can be either default or custom. Specify the pattern when using custom.

POST/coupons:generations
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

idobjectIdrequired

The ID of the coupon generation to retrieve.

GET/coupons:generations/:id
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

idobjectIdrequired

Unique identifier for the coupon generation.

countint
PUT/coupons:generations/:id
const 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

expandstring

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.

fieldsstring

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.
includeobject

Include one or more arbitrary queries in the response which are potentially related to the main query.

See including for more details.

limitint

Limit the number of records returned, ranging between 1 and 1000. Defaults to 15.

pageint

The page number of results to return given the specified or default limit.

searchstring

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.

sortstring

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.

whereobject

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.

GET/coupons:generations
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

idobjectIdrequired

The ID of the coupon generation to delete.

DELETE/coupons:generations/:id
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"
},