Backend API

Coupon codes are a collection of eligible codes that can be redeemed by a customer to receive the discount associated with the coupon. Codes are generated in batches and are stored on the coupon. Codes are associated with their generation instance and are also tracked with coupon uses.

Fields

id

objectId

Unique identifier for the coupon code.

code

stringauto

Gift card code to apply. A validation error will be returned if the code is not valid.

date_created

dateauto

Date and time the coupon code was created.

date_updated

dateauto

Date and time the coupon code was last updated.

gen_id

objectId

Unique ID corresponding to a coupon code generation.

orders

Order

Expandable list of orders that have applied the coupon code.

parent_id

objectIdrequired

ID of the parent coupon, if applicable.

parent

Coupon

Expandable link to the parent coupon.

subscriptions

Subscription

Expandable list of subscriptions that have applied the coupon code.

use_count

int

Number of times the coupon code has been used.

The coupon code model
{
 "gen_id": "62b5cdffd7ad010018c66249",
 "parent_id": "62b5cdff2e40ab001ac27240",
 "use_count": 0,
 "date_created": "2022-06-24T14:45:20.941Z",
 "use_total": 0,
 "code": "PNB83100017",
 "id": "62b5ce0079c5d80012fe5f65"
}

Create a new coupon code.

Arguments

parent_id

objectIdrequired

ID of the parent coupon.

id

objectId

ID of the coupon code.

code

string

Unique code to identify the coupon.

date_created

dateauto

Date and time the coupon code was created.

date_updated

dateauto

Date and time the coupon code was last updated.

gen_id

objectId

The ID of the generation instance for a particular coupon code.

orders

Order

parent

Coupon

Expandable link to the parent coupon.

subscriptions

Subscription

use_count

int

use_total

int
POST/coupons:codes
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.post('/coupons:codes', {
code: 'ALCHEMY25',
parent_id: '62cc86897ad4f100132c953d'
});
The coupon code model
{
 "gen_id": "62b5cdffd7ad010018c66249",
 "parent_id": "62b5cdff2e40ab001ac27240",
 "use_count": 0,
 "date_created": "2022-06-24T14:45:20.941Z",
 "use_total": 0,
 "code": "PNB83100017",
 "id": "62b5ce0079c5d80012fe5f65"
}

Retrieve an existing coupon code using the ID that was returned when created.

Arguments

id

objectIdrequired

ID of the coupon code.

GET/coupons:codes/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/coupons:codes/{id}', {
});
The coupon code model
{
 "gen_id": "62b5cdffd7ad010018c66249",
 "parent_id": "62b5cdff2e40ab001ac27240",
 "use_count": 0,
 "date_created": "2022-06-24T14:45:20.941Z",
 "use_total": 0,
 "code": "PNB83100017",
 "id": "62b5ce0079c5d80012fe5f65"
}

Update an existing coupon code using the ID that was returned when created.

Arguments

id

objectIdrequired

Unique identifier for the coupon code.

code

string
PUT/coupons:codes/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.put('/coupons:codes/{id}', {
code: 'SKOOMA15'
});
The coupon code model
{
 "gen_id": "62b5cdffd7ad010018c66249",
 "parent_id": "62b5cdff2e40ab001ac27240",
 "use_count": 0,
 "date_created": "2022-06-24T14:45:20.941Z",
 "use_total": 0,
 "code": "PNB83100017",
 "id": "62b5ce0079c5d80012fe5f65"
}

Return a list of coupon codes.

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:codes
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/coupons:codes', {
});
The coupon code model
{
 "gen_id": "62b5cdffd7ad010018c66249",
 "parent_id": "62b5cdff2e40ab001ac27240",
 "use_count": 0,
 "date_created": "2022-06-24T14:45:20.941Z",
 "use_total": 0,
 "code": "PNB83100017",
 "id": "62b5ce0079c5d80012fe5f65"
}

Delete a coupon code permanently.

Arguments

id

objectIdrequired

ID of the coupon code.

DELETE/coupons:codes/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.delete('/coupons:codes/{id}', {
});
The coupon code model
{
 "gen_id": "62b5cdffd7ad010018c66249",
 "parent_id": "62b5cdff2e40ab001ac27240",
 "use_count": 0,
 "date_created": "2022-06-24T14:45:20.941Z",
 "use_total": 0,
 "code": "PNB83100017",
 "id": "62b5ce0079c5d80012fe5f65"
}