Backend API

Product attributes are additional characteristics of a product that can be used in different ways. Attributes can be made visible on your detail page with the visible flag or hidden from view. Visible attributes are typically used to display a list of specifications on a detail page. Hidden attributes are typically used as internal data points or to affect the behavior of products in your store theme.

Fields

id

stringrequiredauto

Unique identifier for the attribute. Defaults to attribute name underscored.

name

stringrequired

A human-friendly name for the attribute.

date_created

dateauto

Date and time the attribute was created.

date_updated

dateauto

Date and time the attribute was last updated.

default

mixed

Default value used when entering a value for the attribute.

filterable

boolean

Indicates if the category is available in the storefront category page filters.

localized

boolean

Indicates if this attribute supports localized content.

multi

boolean

When attribute type=image is indicated, the attribute contains multiple images.

products

Product

Expandable list of products using the attribute.

required

boolean

Indicates the attribute requires a value when assigned to a product.

searchable

boolean

Indicates if this attribute is searchable on the backend.

type

enumrequired

Input type used when entering a value for the attribute.

Possible enum values:

short_textlong_textassetlookupbooleanselectnumberdatetagsiconcollectionfield_group

values

array of child_scalar

List of the attribute's associated select options used with attribute type of checkbox, radio, or select.

variant

boolean

Indicates if this attribute is a variant.

visible

boolean

Indicates the attribute is visible to customers.

Response
{
  "id": "material",
  "name": "Color",
  "date_created": "2021-07-16T14:35:59.968Z",
  "date_updated": "2021-07-16T14:35:59.968Z",
  "default": null,
  "required": false,
  "type": "text",
  "values": [
    "Red",
    "White",
    "Blue",
    "Green",
    "Yellow",
    "Black"
  ],
  "visible": true
}

Create a new attribute. If you wish to generate your own unique ID for the record, it must use BSON ObjectID format for compatibility.

Arguments

name

stringrequired

A human-friendly name for the attribute.

required

boolean

Indicates the attribute requires a value when assigned to a product.

type

enum

Input type used when entering a value for the attribute.

Possible enum values:

short_textlong_textassetlookupbooleanselectnumberdatetagsiconcollectionfield_group

values

array of child_scalar

List of the attribute's associated select options used with attribute type of checkbox, radio, or select.

visible

boolean

Indicates the attribute is visible to customers.

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

await swell.post('/attributes', {
  name: 'Material',
  visible: true,
  type: 'dropdown',
  values: [
    'Cotton',
    'Polyester',
    'Wool'
  ],
});
Response
{
  "id": "material",
  "name": "Material",
  "date_created": "2019-04-01T00:00:00.000Z",
  "required": false,
  "visible": true,
  "type": "dropdown",
  "values": [
    "Cotton",
    "Polyester",
    "Wool"
  ]
}

Retrieve an existing attribute using the ID, that was returned when created.

Arguments

id

objectIdrequired

The id of the attribute to retrieve.

expand

string

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.

fields

string

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 category id is always returned.

include

string

Include one or more arbitrary queries in the response, possibly related to the main query.

See including for more details.

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

await swell.get('/attributes/{id}', {
  id: 'material',
});
Response
{
  "id": "material",
  "name": "Material",
  "date_created": "2019-04-01T00:00:00.000Z",
  "required": false,
  "visible": true,
  "type": "dropdown",
  "values": [
    "Cotton",
    "Polyester",
    "Wool"
  ]

Update an existing attribute using the ID, that was returned when created. Updating performs a merge operation. To explicitly override values such as arrays, use the $set operator.

Arguments

id

stringrequiredauto

Unique identifier for the attribute. Defaults to attribute name underscored.

name

stringrequired

A human-friendly name for the attribute.

required

boolean

Set true to make the attribute require a value when added to a product.

type

enum

Input type used when entering a value for the attribute.

Possible enum values:

short_textlong_textassetlookupbooleanselectnumberdatetagsiconcollectionfield_group

values

array of child_scalar

List of the attribute's associated select options used with attribute type of checkbox, radio, or select.

visible

boolean

Indicates the attribute is visible to customers.

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

await swell.put('/attributes/{id}', {
  id: 'material',
  required: true
});
Response
{
  "id": "material",
  "name": "Material",
  "date_created": "2019-04-01T00:00:00.000Z",
  "date_updated": "2019-04-01T00:00:00.000Z",
  "required": true,
  "visible": true,
  "type": "dropdown",
  "values": [
    "Cotton",
    "Polyester",
    "Wool"
  ]
}

Return a list of product attributes.

Arguments

expand

string

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.

fields

string

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

object

Include one or more arbitrary queries in the response which are potentially related to the main query.

See including for more details.

limit

int

Limit the number of records returned, ranging between 1 and 1000. Defaults to 15.

page

int

The page number of results to return given the specified or default limit.

search

string

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.

sort

string

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.

where

object

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/attributes
const swell = require('swell-node').init('store-id', 'secret-key');

await swell.get('/attributes', {
  limit: 25,
  page: 1
});
Response
{
  "count": 51,
  "results": [
    {
      "id": "material",
      "name": "Color",
      "date_created": "2021-07-16T14:35:59.968Z",
      "date_updated": "2021-07-16T14:35:59.968Z",
      "default": null,
      "required": false,
      "type": "text",
      "values": [
        "Red",
        "White",
        "Blue",
        "Green",
        "Yellow",
        "Black"
      ],
      "visible": true
    },
    {...},
    {...}
  ],
  "page": 1,
  "pages": {
    "1": {
      "start": 1,
      "end": 25
    },
    "2": {
      "start": 26,
      "end": 50
    },
    "2": {
      "start": 51,
      "end": 51
    }
  }
}

Delete an attribute.

Arguments

id

objectIdrequired

The id of the attribute to delete.

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

await swell.delete('/attributes/{id}', {
  id: 'material',
});
Response
{
  "id": "material",
  "name": "Material",
  "date_created": "2019-04-01T00:00:00.000Z",
  "date_updated": "2019-04-01T00:00:00.000Z",
  "required": true,
  "visible": true,
  "type": "dropdown",
  "values": [
    "Cotton",
    "Polyester",
    "Wool"
  ]
}