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

objectId

Unique identifier for the coupon codes generated.

codes

Coupon code

An array of coupon codes to be generated.

count

intrequired

Specifies 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

dateauto

Date the coupon code is generated.

date_updated

dateauto

Date the coupon code was last updated.

parent

Coupon

Expandable link to the parent coupon.

parent_id

objectIdrequired

Unique identifier of the parent coupon.

pattern

string

Specifies the code pattern for generated coupons.

pattern_type

enum

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

Possible enum values:

defaultcustom
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

objectId

ID of the coupon generation.

count

intrequired

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

parent_id

objectIdrequired

ID of the parent coupon.

codes

Coupon code

Expandable link to the coupon code.

complete

boolean

Indicates that the coupon code generation is complete.

date_created

dateauto

Date and time the coupon generation was created.

date_updated

dateauto

Date and time the coupon generation was last updated.

error

string

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

parent

Coupon

Expandable link to the parent coupon.

pattern

string

Specifies the code pattern for generated coupons.

pattern_type

string

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

id

objectIdrequired

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

id

objectIdrequired

Unique identifier for the coupon generation.

count

int
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

expand

string

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.

fields

string

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.

include

object

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

See including for more details.

limit

int

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

page

int

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

search

string

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.

sort

string

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.

where

object

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

id

objectIdrequired

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"
},