Backend API

Promotions are a way to offer customers a discount without a coupon code, by automatically applying discounts to their cart. A promotion can have several discounts and exceptions. For example, a promotion discount can apply to a whole order, to particular categories, to individual products, or to shipping methods. A promotion can be limited to a maximum number of uses, by specific customer groups, and more.

Fields

id

objectId

Unique identifier for the promotion.

name

stringrequired

A short descriptive name of the promo.

active

boolean

Indicates the promo is currently active. Note: this is not affected by date_start and date_end.

currency

string

Three-letter ISO currency code in uppercase. Defaults to the store's base currency.

date_created

dateauto

Date and time the promotion was created.

date_end

daterequired

Date the promo ends and is no longer available. When defined, the promo will not be applied after this date.

date_start

date

Date the promo is first available. When defined, the promo will not be valid until after this date and before date_end.

date_updated

dateauto

Date and time the promotion was last updated.

description

string

A brief description of the promo, as it may be displayed to customers.

discount_group

string

ID of the discount group the promo belongs to, if applicable, as defined in discount settings. Used to ensure only one set of discount rules can apply across a number of coupons and promotions.

discounts

array of object

List of discount rules to apply.

exclusions

array of object

List of exclusions considered when the promo is applied.

limit_account_groups

array of account_groups

List of customer account for which the promo will apply.

limit_account_uses

int

Maximum number of times the promo will be applied by each customer account.

limit_uses

int

Maximum number of times the promo will be applied across all customers.

orders

Order

Expandable list of orders that have applied the promo.

subscriptions

Subscription

Expandable list of subscriptions that have applied the promo.

use_count

intauto

Number of times the promo has been applied.

uses

array of Uses

Expandable list of promotion use records.

The promotion model
{
  "id": "60f199509111e7000000006b",
  "name": "15% Off Store Wide Sale",
  "active": true,
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.386Z",
  "date_end": "2018-03-01T00:00:00.000Z",
  "date_start": "2018-11-01T00:00:00.000Z",
  "date_updated": "2021-07-16T14:36:00.386Z",
  "description": "Save 15% store wide for a limited time only.",
  "discounts": [
    {
      "type": "total",
      "value_type": "percent",
      "value_fixed": 15
    }
  ],
  "limit_account_uses": 3,
  "limit_uses": 300,
  "use_count": 142
}

Create a new promotion. If you wish to generate your own unique ID for the record, it must use BSON ObjectID format for compatibility.

Arguments

name

stringrequired

A short descriptive name of the promo.

description

string

A brief description of the promo, as it may be displayed to customers.

active

boolean

Indicates the promo is currently active. Note: this is not affected by date_start and date_end.

date_start

date

Date the promo is first available. When defined, the promo will not be valid until after this date and before date_end.

date_end

date

Date the promo ends and is no longer available. When defined, the promo will not be applied after this date.

discounts

array of objectrequired

List of discount rules to apply.

POST/promotions
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.post('/promotions', {
  discounts: [
    {
      type: 'total',
      value_type: 'percent',
      value_fixed: 15
    }
  ],
  name: '15% Off Store Wide Sale',
  active: true,
  date_end: '2018-03-01T00:00:00.000Z',
  date_start: '2018-11-01T00:00:00.000Z',
  description: 'Save 15% store wide for a limited time only.'
});
Response
{
  "id": "60f199509111e7000000006b",
  "name": "15% Off Store Wide Sale",
  "active": true,
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.386Z",
  "date_end": "2018-03-01T00:00:00.000Z",
  "date_start": "2018-11-01T00:00:00.000Z",
  "date_updated": "2021-07-16T14:36:00.386Z",
  "description": "Save 15% store wide for a limited time only.",
  "discounts": [
    {
      "type": "total",
      "value_type": "percent",
      "value_fixed": 15
    }
  ],
  "limit_account_uses": 3,
  "limit_uses": 300,
  "use_count": 142
}

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

Arguments

id

objectIdrequired

The ID of the promotion to retrieve.

expand

string

Expanding link fields and child collections is performed 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

Return 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 category id is always returned.

include

string

Include one or more arbitrary queries in the response, possibly related to the main query.

See including for more details.

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

await swell.get('/promotions/{id}', {
  id: '60f199509111e7000000006e'
});
Response
{
  "id": "60f199509111e70000000071",
  "name": "15% Off Store Wide Sale",
  "active": true,
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.386Z",
  "date_end": "2018-03-01T00:00:00.000Z",
  "date_start": "2018-11-01T00:00:00.000Z",
  "date_updated": "2021-07-16T14:36:00.386Z",
  "description": "Save 15% store wide for a limited time only.",
  "discounts": [
    {
      "type": "total",
      "value_type": "percent",
      "value_fixed": 15
    }
  ],
  "limit_account_uses": 3,
  "limit_uses": 300,
  "use_count": 142
}

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

Arguments

id

objectIdrequired

Unique identifier for the promotion.

active

boolean

Indicates the promo is currently active. Note: this is not affected by date_start and date_end.

date_end

date

Date the promo ends and is no longer available. When defined, the promo will not be applied after this date.

name

string

A short descriptive name of the promo.

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

await swell.put('/promotions/{id}', {
  id: '60f199509111e7000000006b',
  limit_uses: 300,
  active: true
});
Response
{
  "id": "60f199509111e7000000006b",
  "name": "15% Off Store Wide Sale",
  "active": true,
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.386Z",
  "date_end": "2018-03-01T00:00:00.000Z",
  "date_start": "2018-11-01T00:00:00.000Z",
  "date_updated": "2021-07-16T14:36:00.386Z",
  "description": "Save 15% store wide for a limited time only.",
  "discounts": [
    {
      "type": "total",
      "value_type": "percent",
      "value_fixed": 15
    }
  ],
  "limit_account_uses": 3,
  "limit_uses": 300,
  "use_count": 142
}

Return a list of promotions.

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

await swell.get('/promotions', {
  where: {
    active: true
  },
  limit: 25,
  page: 1
});
Response
{
  "count": 51,
  "results": [
    {
      "id": "60f199509111e7000000006b",
      "name": "15% Off Store Wide Sale",
      "active": true,
      "currency": "USD",
      "date_created": "2021-07-16T14:36:00.386Z",
      "date_end": "2018-03-01T00:00:00.000Z",
      "date_start": "2018-11-01T00:00:00.000Z",
      "date_updated": "2021-07-16T14:36:00.386Z",
      "description": "Save 15% store wide for a limited time only.",
      "discounts": [
        {
          "type": "total",
          "value_type": "percent",
          "value_fixed": 15
        }
      ],
      "limit_account_uses": 3,
      "limit_uses": 300,
      "use_count": 142
    },
    {...},
    {...}
  ],
  "page": 1,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "2": {
      "start": 51,
      "end": 51
    }
  }
}

Delete a promotion permanently.

Arguments

id

objectIdrequired

The id of the promotion to delete.

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

await swell.delete('/promotions/{id}', {
  id: '60f199509111e70000000074'
});
Response
{
  "id": "60f199509111e70000000077",
  "name": "15% Off Store Wide Sale",
  "active": true,
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.386Z",
  "date_end": "2018-03-01T00:00:00.000Z",
  "date_start": "2018-11-01T00:00:00.000Z",
  "date_updated": "2021-07-16T14:36:00.386Z",
  "description": "Save 15% store wide for a limited time only.",
  "discounts": [
    {
      "type": "total",
      "value_type": "percent",
      "value_fixed": 15
    }
  ],
  "limit_account_uses": 3,
  "limit_uses": 300,
  "use_count": 142
}