Backend API

The promotion uses collection tracks each use of a promotion to ensure that promotion restrictions such as usage limits are maintained. Each promotion use relates the account and order to the promotion.

Fields

id

objectIdrequired

Unique identifier for the promotion use.

account_id

objectIdrequired

ID of the customer's account.

date_created

daterequiredauto

Date and time the promotion use was created.

date_updated

daterequiredauto

Date and time the promotion use was last updated.

order

Orderrequired

Expandable link to the order the promotion was applied to.

order_id

objectIdrequired

ID of the order that used the promotion.

parent

Couponrequired

Expandable link to the parent promotion.

parent_id

objectIdrequired

ID of the parent promotion.

subscription

Subscriptionrequired

Expandable link to the subscription that spawned the promotion use, if applicable.

subscription_id

objectIdrequired

ID of the subscription that spawned the promotion use, if applicable.

code

stringrequired

code_id

objectIdrequired
The promotion use model
{
  "parent_id": "6285746dd0fc72001a6a2f4e",
  "account_id": "628fb3c90f42a10014f04787",
  "order_id": "62a09d0317f83f001975b491",
  "date_created": "2022-06-08T13:08:10.445Z",
  "id": "62a09f3a17f83f001975b4d1"
},

Create a new promotion use.

Arguments

parent_id

objectIdrequired

Unique identifier of the parent promotion.

id

objectId

ID of the promotion use.

order_id

objectId

Unique identifier for the order that the promotion use is applied to.

subscription_id

objectId

ID of the subscription plan.

account_id

objectId

ID of the account connected to the promotion use.

date_created

date

Date and time the promotion use was created.

date_updated

date

Date and time the promotion use was last updated.

order

Order

parent

Promotion

subscription

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

await swell.post('/promotions:uses', {
  order_id: '62bf11bb4b738e00141c51d6'
});
The promotion use model
{
  "parent_id": "6285746dd0fc72001a6a2f4e",
  "account_id": "628fb3c90f42a10014f04787",
  "order_id": "62a09d0317f83f001975b491",
  "date_created": "2022-06-08T13:08:10.445Z",
  "id": "62a09f3a17f83f001975b4d1"
},

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

Arguments

id

objectId

The ID of the promotion use to retrieve.

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

await swell.get('/promotions:uses/{id}', {
});
Response
{
  "parent_id": "6285746dd0fc72001a6a2f4e",
  "account_id": "628fb3c90f42a10014f04787",
  "order_id": "62a09d0317f83f001975b491",
  "date_created": "2022-06-08T13:08:10.445Z",
  "id": "62a09f3a17f83f001975b4d1"
}

Return a list of promotion uses.

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

await swell.get('/promotions:uses', {
  where: {
    active: true
  },
  limit: 25,
  page: 1
});
The promotion use model
{
  "count": 3,
  "results": [
    {
      "parent_id": "6285746dd0fc72001a6a2f4e",
      "account_id": "628fb3c90f42a10014f04787",
      "order_id": "62a09d0317f83f001975b491",
      "date_created": "2022-06-08T13:08:10.445Z",
      "id": "62a09f3a17f83f001975b4d1"
    },
    {
      "parent_id": "6285746dd0fc72001a6a2f4e",
      "account_id": "6296b0ad8f4d1100129e16c3",
      "order_id": "6296b2aa50a04b0012bc64c6",
      "date_created": "2022-06-01T00:28:26.103Z",
      "id": "6296b2aa50a04b0012bc64c7"
    },
    {
      "parent_id": "6285746dd0fc72001a6a2f4e",
      "account_id": "628fb3c90f42a10014f04787",
      "order_id": "628fb3e10f42a10014f0478d",
      "date_created": "2022-05-26T17:07:45.415Z",
      "id": "628fb3e10f42a10014f0478e"
    }
  ]
}

Delete a promotion use permanently.

Arguments

id

objectIdrequired

The ID of the promotion use to delete.

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

await swell.delete('/promotions:uses/{id}', {
  id: '60f199509111e70000000074'
});
The promotion use model
{
  "parent_id": "6285746dd0fc72001a6a2f4e",
  "account_id": "628fb3c90f42a10014f04787",
  "order_id": "62a09d0317f83f001975b491",
  "date_created": "2022-06-08T13:08:10.445Z",
  "id": "62a09f3a17f83f001975b4d1"
},