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

idobjectId

Unique identifier for the credit.

amountcurrencyrequired

Credit amount denominated in currency. Minimum of 0.01.

parent_idobjectIdrequired

The ID of the parent customer.

creditCredit Memo

Expandable list of the customer’s credit transactions.

credit_idobjectId

ID of the credit applied to the customer's account.

currencystring

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

date_createddateauto

Date and time the credit was created.

date_updateddateauto

Date and time the credit was last updated.

giftcard_idobjectId

ID of the gift card used to make the payment, if applicable.

invoiceInvoice

Expandable link to the invoice the credit was applied to, if applicable.

invoice_idobjectId

ID of the invoice the credit was applied to, if applicable.

numberstringauto

Unique incremental number assigned automatically each time an account credit is created.

parentAccount

Expandable link to the parent customer.

paymentPayment

Expandable link to the payment.

payment_idobjectId

Unique identifier for the payment.

reasonstring

The reason for the refund.

reason_messagestring

A brief message describing the reason for the refund.

refundRefund

Expandable list of refunds that apply to the credit.

refund_idobjectId

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

amountcurrencyrequired

Account credit value. Must be greater than zero.

parent_idobjectIdrequired

Unique identifier for the parent account.

POST/account-credits
const swell = require('swell-node').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

idobjectId

Unique identifier for the credit.

amountcurrencyrequired

Credit amount denominated in currency. Minimum of 0.01.

parent_idobjectIdrequired

The ID of the parent customer.

GET/accounts:credits/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/accounts:credits/{id}', {
});
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

idobjectId

Unique identifier for the credit.

amountcurrencyrequired

Credit amount denominated in currency. Minimum of 0.01.

parent_idobjectIdrequired

The ID of the parent customer.

currencystring

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

credit_idobjectId

ID of the credit applied to the customer's account.

numberstringauto

Unique incremental number assigned automatically each time an account credit is created.

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

await swell.put('/accounts:credits/{id}', {
  email: 'sheogorath@shiveringisles.com'
});
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"
}

Return a list of customer account credits.

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/accounts:credits
const swell = require('swell-node').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

idobjectId

Unique identifier of the account credit.

DELETE/accounts:credits/:id
const swell = require('swell-node').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"
    },