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

idstringauto

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

namestring

A human-friendly name for the attribute.

date_createddateauto

Date and time the attribute was created.

date_updateddateauto

Date and time the attribute was last updated.

defaultmixed

Default value used when entering a value for the attribute.

filterableboolean

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

localizedboolean

Indicates if this attribute supports localized content.

multiboolean

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

productsProduct

Expandable list of products using the attribute.

requiredboolean

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

searchableboolean

Indicates if this attribute is searchable on the backend.

typeenumrequired

Input type used when entering a value for the attribute.

valuesarray of child_scalar

List of values applicable to checkbox, radio, dropdown, and image attributes.

variantboolean

Indicates if this attribute is a variant.

visibleboolean

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.

Arguments

idobjectIdrequired

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

namestringrequired

A human-friendly name for the attribute.

requiredboolean

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

typeenum

Input type used when entering a value for the attribute.

valuesarray of child_scalar

List of values applicable to checkbox, radio, dropdown, and image attributes.

visibleboolean

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

idobjectIdrequired

The id of the attribute 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 category 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/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

idobjectIdrequired

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

namestring

A human-friendly name for the attribute.

requiredboolean

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

typeenum

Input type used when entering a value for the attribute.

valuesarray of child_scalar

List of values applicable to checkbox, radio, dropdown, and image attributes.

visibleboolean

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

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/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

idobjectIdrequired

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"
  ]
}