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
objectIdUnique identifier for the gift card.
account
AccountExpandable link to an account where the value was redeemed as account credit, if applicable.
account_id
objectIdID of an account where the value was redeemed as account credit, if applicable.
amount
currencyrequiredInitial gift card value. Minimum of 0.01.
amount_spent
currencyautoAmount of the gift card that has been spent on orders.
balance
currencyautoRemaining balance on the gift card.
bulk_description
stringautoA brief description of the occasion for generating a batch of gift cards.
bundle_item_id
objectIdID of the associated bundle item, if applicable.
code
stringUnique code to identify the gift card.
code_formatted
stringFormatted gift card code for display purposes.
code_pattern
stringString pattern used to display the code in a human-friendly format.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
currency_rate
floatCurrency percentage used in calculating the fixed amount.
date_bulk_generated
dateautoIf the gift card was generated in bulk, this will be the date it was generated.
date_created
dateautoDate and time the gift card was created.
date_expired
dateDate 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
dateautoDate and time the gift card was last updated.
debits
array of DebitsExpandable list of debit transactions created when the gift card is spent.
disabled
booleanIndicates the gift card is disabled and can't be spent or redeemed further.
last4
stringautoLast four digits of the gift card code.
order
OrderExpandable link to the order that originated the gift card, if applicable.
order_id
objectIdautoID of the order that originated the gift card, if applicable.
order_item_id
objectIdautoID of the order item that originated the gift card, if applicable.
product_id
objectIdautoID of the product that originated the gift card, if applicable.
redeemed
booleanautoIndicates the gift card was fully redeemed for account credit to account_id.
send_email
stringEmail address of the gift card recipient, if applicable.
send_note
stringCustomer 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
currencyrequiredInitial gift card value. Minimum of 0.01.
account
AccountExpandable link to an account where the value was redeemed as account credit, if applicable.
account_id
objectIdID of an account where the value was redeemed as account credit, if applicable.
amount_spent
currencyautoAmount of the gift card that has been spent on orders.
balance
currencyautoRemaining balance on the gift card.
bulk_description
stringautoA brief description of the occasion for generating a batch of gift cards.
bundle_item_id
objectIdID of the associated bundle item, if applicable.
code
stringUnique code to identify the gift card.
code_formatted
stringFormatted gift card code for display purposes.
code_pattern
stringString pattern used to display the code in a human-friendly format.
currency
stringThree-letter ISO currency code in uppercase. Defaults to the store's base currency.
currency_rate
floatCurrency percentage used in calculating the fixed amount.
date_bulk_generated
dateautoIf the gift card was generated in bulk, this will be the date it was generated.
date_expired
dateDate the gift card will expire and can no longer be spent or redeemed. Defaults to the time period defined in gift card settings.
debits
array of DebitsExpandable list of debit transactions created when the gift card is spent.
disabled
booleanIndicates the gift card is disabled and can't be spent or redeemed further.
last4
stringautoLast four digits of the gift card code.
order
OrderExpandable link to the order that originated the gift card, if applicable.
order_id
objectIdautoID of the order that originated the gift card, if applicable.
order_item_id
objectIdautoID of the order item that originated the gift card, if applicable.
product_id
objectIdautoID of the product that originated the gift card, if applicable.
redeemed
booleanautoIndicates the gift card was fully redeemed for account credit to `account_id`.
send_email
stringEmail address of the gift card recipient, if applicable.
send_note
stringCustomer note sent to the gift card recipient by email, if applicable.
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
objectIdrequiredID of the gift card to retrieve.
expand
stringExpanding 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
stringReturn 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
stringInclude one or more arbitrary queries in the response, possibly related to the main query.
See including for more details.
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
objectIdrequiredUnique identifier for the gift card.
amount
currencyGift card value. Must be greater than zero.
account_id
objectIdID of an account to redeem the value as account credit.
code
stringWhen creating a gift card, code will be generated automatically if this field is left blank.
code_formatted
stringFormatted gift card code for display purposes.
code_pattern
stringString pattern used to display the code in a human-friendly format. The default code pattern can be configured from the Swell dashboard.
currency
stringThree-letter ISO currency code in uppercase. Defaults to store's base currency.
date_expired
dateDate the gift card will expire and can no longer be spent or redeemed. Defaults to the time period defined in gift card settings.
disabled
booleanIndicates the gift card is disabled and can't be spent or redeemed further.
send_email
stringEmail address of the gift card recipient, if applicable.
send_note
stringCustomer note sent to the gift card recipient by email, if applicable.
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
stringExpand 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
stringReturns 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
objectInclude one or more arbitrary queries in the response which are potentially related to the main query.
See including for more details.
limit
intLimit the number of records returned, ranging between 1 and 1000. Defaults to 15.
page
intThe page number of results to return given the specified or default limit.
search
stringA 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
stringExpression 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
objectAn 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.
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
objectIdrequiredThe ID of the gift card to delete.
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
}