Backend API

Gift cards are a store of value that can be spent on purchases or redeemed for account credit. Gift cards can be created by ordering a gift card product and having it fulfilled as a gift card code sent to the customer by email, or alternatively sold a physical card shipped to a customer.

When selling physical gift cards, an admin would generate gift card codes from the Swell dashboard and export the codes for printing.

Fields

id

objectId

Unique identifier for the gift card.

account

Account

Expandable link to an account where the value was redeemed as account credit, if applicable.

account_id

objectId

ID of an account where the value was redeemed as account credit, if applicable.

amount

currencyrequired

Initial gift card value. Minimum of 0.01.

amount_spent

currencyauto

Amount of the gift card that has been spent on orders.

balance

currencyauto

Remaining balance on the gift card.

bulk_description

stringauto

A brief description of the occasion for generating a batch of gift cards.

bundle_item_id

objectId

ID of the associated bundle item, if applicable.

code

string

Unique code to identify the gift card.

code_formatted

string

Formatted gift card code for display purposes.

code_pattern

string

String pattern used to display the code in a human-friendly format.

currency

string

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

currency_rate

float

Currency percentage used in calculating the fixed amount.

date_bulk_generated

dateauto

If the gift card was generated in bulk, this will be the date it was generated.

date_created

dateauto

Date and time the gift card was created.

date_expired

date

Date the gift card will expire and can no longer be spent or redeemed. Defaults to the time period defined in gift card settings.

date_updated

dateauto

Date and time the gift card was last updated.

debits

array of Debits

Expandable list of debit transactions created when the gift card is spent.

disabled

boolean

Indicates the gift card is disabled and can't be spent or redeemed further.

last4

stringauto

Last four digits of the gift card code.

order

Order

Expandable link to the order that originated the gift card, if applicable.

order_id

objectIdauto

ID of the order that originated the gift card, if applicable.

order_item_id

objectIdauto

ID of the order item that originated the gift card, if applicable.

product_id

objectIdauto

ID of the product that originated the gift card, if applicable.

redeemed

booleanauto

Indicates the gift card was fully redeemed for account credit to account_id.

send_email

string

Email address of the gift card recipient, if applicable.

send_note

string

Customer note sent to the gift card recipient by email, if applicable.

The gift card model
{
  "id": "60f199509111e70000000022",
  "amount": 100,
  "amount_spent": 25,
  "balance": 75,
  "code": "C9X9L7D9Q3MAXC3P",
  "code_formatted": "C9X9 L7D9 Q3MA XC3P",
  "code_pattern": "{XXXX} {XXXX} {XXXX} {XXXX}",
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-16T14:36:00.142Z",
  "last4": "XC3P",
  "redeemed": false,
  "send_email": "friend@example.com",
  "send_note": null
}

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

Arguments

amount

currencyrequired

Initial gift card value. Minimum of 0.01.

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

await swell.post('/giftcards', {
  amount: 100
});
Response
{
  "id": "60f199509111e70000000022",
  "amount": 100,
  "amount_spent": 25,
  "balance": 75,
  "code": "C9X9L7D9Q3MAXC3P",
  "code_formatted": "C9X9 L7D9 Q3MA XC3P",
  "code_pattern": "{XXXX} {XXXX} {XXXX} {XXXX}",
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-16T14:36:00.142Z",
  "last4": "XC3P",
  "redeemed": false,
  "send_email": "friend@example.com",
  "send_note": null
}

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

Arguments

id

objectIdrequired

ID of the gift card 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 gift card 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/giftcards/{id}
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/giftcards/{id}', {
});
Response
{
  "id": "60f199509111e70000000028",
  "amount": 100,
  "amount_spent": 25,
  "balance": 75,
  "code": "C9X9L7D9Q3MAXC3P",
  "code_formatted": "C9X9 L7D9 Q3MA XC3P",
  "code_pattern": "{XXXX} {XXXX} {XXXX} {XXXX}",
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-16T14:36:00.142Z",
  "last4": "XC3P",
  "redeemed": false,
  "send_email": "friend@example.com",
  "send_note": null
}

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

Arguments

id

objectIdrequired

Unique identifier for the gift card.

amount

currency

Gift card value. Must be greater than zero.

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

await swell.put('/giftcards/{id}', {
  id: '60f199509111e70000000022'
});
Response
{
  "id": "60f199509111e70000000022",
  "amount": 100,
  "amount_spent": 25,
  "balance": 75,
  "code": "C9X9L7D9Q3MAXC3P",
  "code_formatted": "C9X9 L7D9 Q3MA XC3P",
  "code_pattern": "{XXXX} {XXXX} {XXXX} {XXXX}",
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-16T14:36:00.142Z",
  "last4": "XC3P",
  "redeemed": false,
  "send_email": "friend@example.com",
  "send_note": null
}

Return a list of gift cards.

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

await swell.put('/giftcards', {
});
Response
{
  "count": 51,
  "results": [
    {
      "id": "60f199509111e70000000022",
      "amount": 100,
      "amount_spent": 25,
      "balance": 75,
      "code": "C9X9L7D9Q3MAXC3P",
      "code_formatted": "C9X9 L7D9 Q3MA XC3P",
      "code_pattern": "{XXXX} {XXXX} {XXXX} {XXXX}",
      "currency": "USD",
      "date_created": "2021-07-16T14:36:00.142Z",
      "date_updated": "2021-07-16T14:36:00.142Z",
      "last4": "XC3P",
      "redeemed": false,
      "send_email": "friend@example.com",
      "send_note": null
    },
    {...},
    {...}
  ],
  "page": 1,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "2": {
      "start": 51,
      "end": 51
    }
  }
}

Delete a gift card permanently.

Arguments

id

objectIdrequired

The ID of the gift card to delete.

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

await swell.delete('/giftcards/{id}', {
  id: '60f199509111e7000000002b'
});
Response
{
  "id": "60f199509111e7000000002e",
  "amount": 100,
  "amount_spent": 25,
  "balance": 75,
  "code": "C9X9L7D9Q3MAXC3P",
  "code_formatted": "C9X9 L7D9 Q3MA XC3P",
  "code_pattern": "{XXXX} {XXXX} {XXXX} {XXXX}",
  "currency": "USD",
  "date_created": "2021-07-16T14:36:00.142Z",
  "date_updated": "2021-07-16T14:36:00.142Z",
  "last4": "XC3P",
  "redeemed": false,
  "send_email": "friend@example.com",
  "send_note": null
}