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

idobjectIdrequired

Unique identifier for the promotion use.

parent_idobjectIdrequired

ID of the parent promotion.

parentPromotionrequired

Expandable link to the parent promotion.

date_createddateautorequired

Date and time the promotion use was created.

date_updateddateautorequired

Date and time the promotion use was last updated.

account_idobjectIdrequired

ID of the customer's account.

order_idobjectIdrequired

ID of the order that used the promotion.

orderOrderrequired

Expandable link to the order the promotion was applied to.

subscription_idobjectIdrequired

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

subscriptionSubscriptionrequired

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

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_idobjectIdrequired

Unique identifier of the parent promotion.

idobjectId

ID of the promotion use.

order_idobjectId

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

subscription_idobjectId

ID of the subscription plan.

account_idobjectId

ID of the account connected to the promotion use.

date_createddate

Date and time the promotion use was created.

date_updateddate

Date and time the promotion use was last updated.

orderOrder
parentPromotion
subscriptionSubscription
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

idobjectId

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

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/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

idobjectIdrequired

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