Backend API
Account credits are a form of currency that is stored on a customer's account. This balance can be awarded through actions such as refunds, or it can additionally be increased by the redemption of gift cards. Customers can apply their account credit balance towards purchases during checkout.
Fields
Unique identifier for the credit.
Credit amount denominated in currency. Minimum of 0.01.
The ID of the parent customer.
Expandable list of the customer’s credit transactions.
ID of the credit applied to the customer's account.
Three-letter ISO currency code in uppercase. Defaults to the store's base currency.
Date and time the credit was created.
Date and time the credit was last updated.
ID of the gift card used to make the payment, if applicable.
Expandable link to the gift card that generated the credit, if applicable.
Expandable link to the invoice the credit was applied to, if applicable.
ID of the invoice the credit was applied to, if applicable.
Unique incremental number assigned automatically each time an account credit is created.
Expandable link to the parent customer.
Expandable link to the payment.
Unique identifier for the payment.
The reason for the refund.
A brief message describing the reason for the refund.
Expandable list of refunds that apply to the credit.
ID of the refund the credit was applied to.
The account credit model
{
"parent_id": "5ffd413300b58e2a4a017831",
"payment_id": "61e78cbed7e71014da0f1b2c",
"amount": 100,
"reason": "promo",
"reason_message": "Found a bag of gold in a tree stump."
"currency": "USD",
"date_created": "2022-01-19T03:59:58.816Z",
"number": "101082",
"id": "61e78cbed7e71014da0f1b87"
}Create a new customer account credit.
Arguments
Account credit value. Must be greater than zero.
Unique identifier for the parent account.
Unique identifier for the account credit.
Automatically generated field that gets incremented each time an account credit is created.
Expandable list of account credits.
ID of the credit applied to the customer's account.
Three-letter ISO currency code in uppercase. Defaults to the store's base currency.
Date and time the credit was created.
Date and time the credit was last updated.
ID of the gift card used to make the payment, if applicable.
Expandable link to the invoice the credit was applied to, if applicable.
ID of the invoice the credit was applied to, if applicable.
Expandable link to the parent account.
Expandable link to the payment.
Unique identifier for the payment.
The reason for the refund.
A brief message describing the reason for the refund.
Expandable list of refunds that apply to the credit.
ID of the refund the credit was applied to.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.post('/accounts:credits', {
parent_id: '621e53a6213eaf013d1fa6b2',
amount: 17,
reason: 'refund'
});Response
{
"parent_id": "621e53a6213eaf013d1fa6b2",
"amount": 17,
"reason": "refund",
"currency": "USD",
"date_created": "2022-07-08T20:27:40.199Z",
"number": "100003",
"id": "62c8933c5f4ffe00136039f2"
}Retrieve an existing account credit using the ID that was returned when created.
Arguments
Unique identifier for the credit.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.get('/accounts:credits/{id}', {
id: '61e78cbed7e71014da0f1b87'
});Response
{
"parent_id": "5ffd413300b58e2a4a017831",
"payment_id": "61e78cbed7e71014da0f1b2c",
"amount": -19.55,
"currency": "USD",
"date_created": "2022-01-19T03:59:58.816Z",
"number": "101082",
"id": "61e78cbed7e71014da0f1b87"
}Update an existing account credit using the ID that was returned when created.
Arguments
Unique identifier for the credit.
Credit amount denominated in currency. Minimum of 0.01.
The ID of the parent customer.
Three-letter ISO currency code in uppercase. Defaults to the store's base currency.
ID of the credit applied to the customer's account.
Unique incremental number assigned automatically each time an account credit is created.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.put('/accounts:credits/{id}', {
id: '62c8933c5f4ffe00136039f2',
amount: 25
});
Response
{
"parent_id": "621e53a6213eaf013d1fa6b2",
"amount": 25,
"reason": "refund",
"currency": "USD",
"date_created": "2022-07-08T20:27:40.199Z",
"number": "100003",
"date_updated": "2022-07-12T16:02:14.965Z",
"id": "62c8933c5f4ffe00136039f2"
}Return a list of customer account credits.
Arguments
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.
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 one or more arbitrary queries in the response which are potentially related to the main query.
See including for more details.
Limit the number of records returned, ranging between 1 and 1000. Defaults to 15.
The page number of results to return given the specified or default limit.
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.
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.
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.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.get('/accounts:credits/', {
});Response
{
"count": 3,
"results": [
{
"parent_id": "621e53a6213eaf013d1fa6b2",
"amount": 17,
"reason": "refund",
"currency": "USD",
"date_created": "2022-07-08T20:27:40.199Z",
"number": "100003",
"date_updated": "2022-07-12T16:02:14.965Z",
"id": "62c8933c5f4ffe00136039f2"
},
{
"parent_id": "621506e39c5e9e013dac45a0",
"amount": 15,
"giftcard_id": "62166e0072c71f013d0b3216",
"currency": "USD",
"date_created": "2022-02-23T17:25:25.101Z",
"number": "100002",
"id": "62166e056050eb01329b8cce"
},
{
"parent_id": "621506e39c5e9e013dac45a0",
"amount": 10,
"giftcard_id": "6206da29178ab8013d86c6aa",
"currency": "USD",
"date_created": "2022-02-23T17:24:28.605Z",
"number": "100001",
"id": "62166dcc6050eb01329a4359"
}
],
"page": 1
}Delete a customer account credit permanently.
Arguments
Unique identifier of the account credit.
const { swell } = require('swell-node');
swell.init('store-id', 'secret-key');
await swell.delete('/accounts:credits/{id}', {
id: '62c8933c5f4ffe00136039f2'
});Response
{
"parent_id": "621e53a6213eaf013d1fa6b2",
"amount": 17,
"reason": "refund",
"currency": "USD",
"date_created": "2022-07-08T20:27:40.199Z",
"number": "100003",
"date_updated": "2022-07-12T16:02:14.965Z",
"id": "62c8933c5f4ffe00136039f2"
}