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
stringrequiredautoUnique identifier for the attribute. Defaults to attribute name underscored.
name
stringrequiredA human-friendly name for the attribute.
date_created
dateautoDate and time the attribute was created.
date_updated
dateautoDate and time the attribute was last updated.
default
mixedDefault value used when entering a value for the attribute.
filterable
booleanIndicates if the category is available in the storefront category page filters.
localized
booleanIndicates if this attribute supports localized content.
multi
booleanWhen attribute type=image is indicated, the attribute contains multiple images.
products
ProductExpandable list of products using the attribute.
required
booleanIndicates the attribute requires a value when assigned to a product.
searchable
booleanIndicates if this attribute is searchable on the backend.
type
enumrequiredInput type used when entering a value for the attribute.
Possible enum values:
values
array of child_scalarList of the attribute's associated select options used with attribute type of checkbox, radio, or select.
variant
booleanIndicates if this attribute is a variant.
visible
booleanIndicates 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
stringrequiredA human-friendly name for the attribute.
required
booleanIndicates the attribute requires a value when assigned to a product.
type
enumInput type used when entering a value for the attribute.
Possible enum values:
values
array of child_scalarList of the attribute's associated select options used with attribute type of checkbox, radio, or select.
visible
booleanIndicates the attribute is visible to customers.
default
mixedDefault value used when entering a value for the attribute.
filterable
booleanIndicates if the category is available in the storefront category page filters.
localized
booleanIndicates if this attribute supports localized content.
multi
booleanWhen attribute type=image is indicated, the attribute contains multiple images.
products
ProductExpandable list of products using the attribute.
searchable
booleanIndicates if this attribute is searchable on the backend.
variant
booleanIndicates if this attribute is a variant.
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
objectIdrequiredThe id of the attribute to retrieve.
expand
stringExpanding 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
stringReturn 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
stringInclude one or more arbitrary queries in the response, possibly related to the main query.
See including for more details.
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
stringrequiredautoUnique identifier for the attribute. Defaults to attribute name underscored.
name
stringrequiredA human-friendly name for the attribute.
required
booleanSet true to make the attribute require a value when added to a product.
type
enumInput type used when entering a value for the attribute.
Possible enum values:
values
array of child_scalarList of the attribute's associated select options used with attribute type of checkbox, radio, or select.
visible
booleanIndicates the attribute is visible to customers.
default
mixedDefault value used when entering a value for the attribute.
localized
booleanIndicates if this attribute supports localized content.
multi
booleanWhen attribute type=image is indicated, the attribute contains multiple images.
products
ProductExpandable list of products using the attribute.
variant
booleanIndicates if this attribute is a variant.
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
stringExpand 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
stringReturns 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
objectInclude one or more arbitrary queries in the response which are potentially related to the main query.
See including for more details.
limit
intLimit the number of records returned, ranging between 1 and 1000. Defaults to 15.
page
intThe page number of results to return given the specified or default limit.
search
stringA 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
stringExpression 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
objectAn 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').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
objectIdrequiredThe id of the attribute to delete.
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"
]
}