Backend API

The account cards collection houses a customer's card information used for payments and transactions—allowing for storing multiple cards on a customer account.

Fields

idobjectIdauto

The unique identifier for the card.

parent_idobjectIdrequired

The ID of the parent account.

tokenlinkrequired

Link to the associated payment token.

activeboolean

Indicated whether this card is active and available for use.

address_checkenum

Indicates results of the address check for the card: unchecked, pass, or fail.

billingobject

The customer's billing details. Defaults to account.billing. Updating billing will also update the corresponding account billing object.

brandstring

Name of card issuer. E.g., "visa".

cvc_checkenum

Indicates results of the CVC check for the card: unchecked, pass, or fail.

date_createddateauto

The date the card entry was created.

date_updateddateauto

Date the card entry was last updated.

exp_monthint

The expiration month on the card, 1 through 12.

exp_yearint

Four-digit card expiration year.

fingerprintstring

A hashed fingerprint generated using client_id, brand, and last4.

gatewaystring

Name of the payment gateway.

last4string

The last four digits of the card number.

parentAccount

Link to the parent account.

testboolean

Indicated the card is for testing purposes.

zip_checkenum

Indicates results of the zip check for the card: unchecked, pass, or fail.

The card model
{
  "parent_id": "627308bc32db26001276f091",
  "billing": {
    "name": "Glarthir",
    "first_name": "Glarthir",
    "last_name": null,
    "address1": "Glarthir's House",
    "address2": null,
    "city": "Skingrad",
    "state": "CA",
    "zip": "95051",
    "country": "US",
    "phone": null,
    "company": null
    },
  "brand": "Visa",
  "last4": "4242",
  "exp_month": 2,
  "exp_year": 2024,
  "token": "card_mgLMIJrqdFKjapNnKQXzbGSg",
  "address_check": "pass",
  "zip_check": "pass",
  "cvc_check": "pass",
  "fingerprint": "011778e5080632a4701cb5628266007d",
  "date_created": "2022-05-19T17:17:31.167Z",
  "active": true,
  "id": "62867bab67e544001a6a3218"
},

Create a new customer account card.

Arguments

idobjectIdauto

The unique identifier for the card.

parent_idobjectIdrequired

The ID of the parent account.

tokenlinkrequired

Link to the associated payment token.

activeboolean

Indicates whether this card is active and available for use.

address_checkenum

Indicates results of the address check for the card: unchecked, pass, or fail.

billingobject

The customer's billing details. Defaults to account.billing. Updating billing will also update the corresponding account billing object.

brandstring

Name of card issuer. E.g., "visa".

cvc_checkenum

Indicates results of the CVC check for the card: unchecked, pass, or fail.

date_createddateauto

The date the card entry was created.

date_updateddateauto

Date the card entry was last updated.

exp_monthint

The expiration month on the card, 1 through 12.

exp_yearint

Four-digit card expiration year.

fingerprintstring

A hashed fingerprint generated using client_id, brand, and last4.

gatewaystring

Name of the payment gateway.

last4string

The last four digits of the card number.

parentAccount

Link to the parent account.

testboolean

Indicated the card is for testing purposes.

zip_checkenum

Indicates results of the zip check for the card: unchecked, pass, or fail.

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

await swell.post('/accounts:cards', {
  first_name: 'Jarl',
	last_name: 'Balgruff',
	address1: '543 Castle Way',
	city: 'Whiterun',
	state: 'CA',
	country: 'US',
	brand: 'Visa',
	last4: '1234',
	exp_month: 10,
	exp_year: 2023,
});
Response
{
      "parent_id": "621e53a6213eaf013d1fa6b2",
      "billing": {
        "name": "Jarl Balgruff",
        "first_name": "Jarl",
        "last_name": "Balgruff",
        "address1": "543 Castle Way",
        "address2": null,
        "city": "Whiterun",
        "state": "CA",
        "zip": null,
        "country": "US",
        "phone": null,
        "company": null
      },
      "brand": "Visa",
      "last4": "1234",
      "exp_month": 10,
      "exp_year": 2023,
      "token": "card_QD5rOXP3I4bOmUCKlmLo7AzC",
      "address_check": "unchecked",
      "zip_check": "unchecked",
      "cvc_check": "unchecked",
      "fingerprint": "3628a7581fec797682e06740213c08f1",
      "date_created": "2022-07-13T15:52:53.253Z",
      "active": true,
      "id": "64ceea552fa37600132711f4"
    }

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

Arguments

idobjectIdrequired

ID of the customer account 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 customer account 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/accounts:cards/:id
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/accounts:cards/{id}', {
});
Response
{
      "parent_id": "621e53a6213eaf013d1fa6b2",
      "billing": {
        "name": "Jarl Balgruff",
        "first_name": "Jarl",
        "last_name": "Balgruff",
        "address1": "543 Castle Way",
        "address2": null,
        "city": "Whiterun",
        "state": "CA",
        "zip": null,
        "country": "US",
        "phone": null,
        "company": null
      },
      "brand": "Visa",
      "last4": "1234",
      "exp_month": 10,
      "exp_year": 2023,
      "token": "card_QD5rOXP3I4bOmUCKlmLo7BzC",
      "address_check": "unchecked",
      "zip_check": "unchecked",
      "cvc_check": "unchecked",
      "fingerprint": "3628a7581fec797682e06740213c08f1",
      "date_created": "2022-07-13T15:52:53.253Z",
      "active": true,
      "id": "64ceea552fa37600131711f3"
    }

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

Arguments

idobjectIdrequired

Unique identifier for the account card.

namestring

Full name of the customer. If first_name or last_name are updated, then name will be automatically updated as a combination of first/last.

first_namestring

Customer's first name. If name is updated, then first_name will be automatically updated as the first word of the name.

last_namestring

If name is updated, then last_name will be automatically updated as the last words of the name.

address1string

Billing address line 1: street address/PO box/company name.

address2string

Billing address line 2: apartment/suite/unit/building.

citystring

Billing city/district/suburb/town/village.

statestring

Billing state/county/province/region.

zipstring

Billing zip/postal code.

countrystring

Two-letter ISO country code.

brandstring

Credit card brand. Can be American Express, Diners Club, Discover, JCB, MasterCard, UnionPay, Visa, or Unknown.

exp_monthint

Two-digit number representing the credit card expiration month.

exp_yearint

Four-digit number representing the credit card expiration year.

last4string

Last four digits of the card number.

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

await swell.put('/accounts:cards/{id}', {
  email: 'sheogorath@shiveringisles.com'
});
Response
{
  "parent_id": "621e53a6213eaf013d1fa6b2",
  "billing": {
    "name": "Jarl Balgruff",
    "first_name": "Jarl",
    "last_name": "Balgruff",
    "address1": "543 Castle Way",
    "address2": null,
    "city": "Whiterun",
    "state": "CA",
    "zip": null,
    "country": "US",
    "phone": null,
    "company": null
  },
  "brand": "Visa",
  "last4": "1234",
  "exp_month": 10,
  "exp_year": 2023,
  "token": "card_QD4rOXP3I5bOmUCKlmLo8AzC",
  "address_check": "unchecked",
  "zip_check": "unchecked",
  "cvc_check": "unchecked",
  "fingerprint": "3618a9581fec797682e06740212c08f3",
  "date_created": "2022-07-13T15:52:53.253Z",
  "active": true,
  "date_updated": "2022-07-18T20:00:49.662Z",
  "email": "sheogorath@shiveringisles.com",
  "id": "62ceea552fa37600132911f6"
}

Return a list of customer account 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/accounts:cards
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/accounts:cards', {
  where: {
    order_count: {
      $gt: 1
    }
  },
  limit: 25,
  page: 1
});
Response
{
      "parent_id": "621e53a6213eaf013d1fa6b2",
      "billing": {
        "name": "Jarl Balgruff",
        "first_name": "Jarl",
        "last_name": "Balgruff",
        "address1": "543 Castle Way",
        "address2": null,
        "city": "Whiterun",
        "state": "CA",
        "zip": null,
        "country": "US",
        "phone": null,
        "company": null
      },
      "brand": "Visa",
      "last4": "1234",
      "exp_month": 10,
      "exp_year": 2023,
      "token": "card_QD5rOXP3I4bOmUCKlmLo7BzC",
      "address_check": "unchecked",
      "zip_check": "unchecked",
      "cvc_check": "unchecked",
      "fingerprint": "3628a7581fec797682e06740213c08f1",
      "date_created": "2022-07-13T15:52:53.253Z",
      "active": true,
      "id": "64ceea552fa37600131711f3"

},
    {...},
    {...}
  ],
  "page": 1,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "2": {
      "start": 51,
      "end": 51
    }
  }
}

Delete a customer account card.

Arguments

idobjectIdrequired

The ID of the account card to delete.

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

await swell.delete('/accounts:cards/{id}', {
  id: '62ceea552fa37600132911f6'
});