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

idobjectId

Unique identifier for the gift card.

amountcurrencyrequired

Initial gift card value. Minimum of 0.01.

account_idobjectId

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

accountAccount

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

amount_spentcurrencyauto

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

balancecurrencyauto

Remaining balance on the gift card.

bulk_descriptionstringauto

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

codestring

Unique code to identify the gift card.

code_formattedstring

Formatted gift card code for display purposes.

code_patternstring

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

currencystring

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

currency_ratefloat

Currency percentage used in calculating the fixed amount.

date_bulk_generateddateauto

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

date_createddateauto

Date and time the gift card was created.

date_expireddate

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_updateddateauto

Date and time the gift card was last updated.

debitsarray of Debits

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

disabledboolean

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

last4stringauto

Last four digits of the gift card code.

orderOrder

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

order_idobjectIdauto

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

order_item_idobjectIdauto

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

product_idobjectIdauto

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

redeemedbooleanauto

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

send_emailstring

Email address of the gift card recipient, if applicable.

send_notestring

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.

Arguments

amountcurrencyrequired

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

idobjectIdrequired

ID of the gift card to retrieve.

expandstring

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.

fieldsstring

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.

includestring

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

idobjectIdrequired

Unique identifier for the gift card.

amountcurrency

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

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

idobjectIdrequired

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
}