Backend API
Stock adjustments are used to keep track of inventory changes over time. Each record represents a single change of 1 or more quantities. When adjustments are made, product and variant stock levels are updated automatically. Stock adjustments are children of products.
Fields
id
objectIdUnique identifier for the stock adjustment.
date_created
dateautoDate and time the stock adjustment was created.
date_updated
dateautoDate and time the stock adjustment was last updated.
description
stringA brief description of the stock entry.
level
intrequiredNew stock level after the adjustment is applied.
location
stringLocation associated to the stock entry, if applicable.
number
stringautoAuto-incremented stock adjustment number.
order
OrderrequiredExpandable link to an order, if applicable to the stock adjustment.
order_id
objectIdrequiredID of an order when the stock adjustment was either reduced by the sale of a product, or increased by cancelling an order. Adjustments from orders are created automatically when stock tracking is enabled.
parent
ProductExpandable link to the parent product.
parent_id
objectIdrequiredID of the parent product.
prev
StockLink to the previous stock adjustment.
prev_id
objectIdID of the previous stock adjustment.
quantity
intrequiredQuantity of the adjustment. A positive number means stock was increased, and a negative number means stock was decreased.
reason
enumEnumerated reason for the stock adjustment. Can be received, returned, canceled, sold, missing, or damaged.
Possible enum values:
reason_message
stringA brief description of the reason for the stock adjustment.
variant
Product variantExpandable link to the parent variant, if applicable.
variant_id
objectIdID of the parent variant, if applicable.
The stock model
{
"id": "60f199509111e7000000005f",
"parent_id": "60f199509111e70000000062",
"date_created": "2021-07-16T14:36:00.321Z",
"date_updated": "2021-07-16T14:36:00.321Z",
"level": 20,
"number": 1029376,
"reason": "received",
"reason_message": "Restock - PO #47362",
"variant_id": "60f199509111e70000000061"
}
Create a new stock adjustment. Normally, stock adjustments are automatically created when stock tracking is enabled and orders are placed or canceled. If you wish to generate your own unique ID for the record, it must use BSON ObjectID format for compatibility.
Arguments
parent_id
objectIdrequiredThe id of the parent product.
quantity
intrequiredQuantity of the adjustment. A positive number means the stock was increased, and a negative number means the stock was decreased.
reason
stringEnumerated reason for the stock adjustment. Can be received, returned, canceled, sold, missing, or damaged.
reason_message
stringA brief description of the reason for the stock adjustment.
order_id
objectIdThe id of an order when the stock adjustment was either reduced by the sale of a product or increased by canceling an order. Adjustments from orders are created automatically when stock tracking is enabled.
variant_id
objectIdThe id of the parent variant, if applicable.
const swell = require('swell-node').init('store-id', 'secret-key');
await swell.post('/products:stock', {
parent_id: '5ca24abb9c077817e5fe2b3b',
quantity: 10,
reason: 'received',
reason_message: 'Restock - PO #47362',
});
Response
{
"id": "5ca24abb9c077817e5fe2b3b",
"parent_id": "5ca7d6c68f749692da37c985",
"quantity": 10,
"level": 10,
"number": "100184",
"reason": "received"
"reason_message": "Restock - PO #47362",
"date_created": "2019-04-01T00:00:00.000Z"
}
Retrieve an existing stock adjustment using the id that was returned when created.
Arguments
id
objectIdrequiredThe id of the stock adjustment 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 stock adjustment 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('/products:stock/{id}', {
id: '5ca24abb9c077817e5fe2b3b',
});
Response
{
"id": "5ca24abb9c077817e5fe2b3b",
"parent_id": "5ca7d6c68f749692da37c985",
"quantity": 10,
"level": 10,
"number": "100184",
"reason": "received"
"reason_message": "Restock - PO #47362",
"date_created": "2019-04-01T00:00:00.000Z"
"date_updated": "2019-04-01T00:00:00.000Z",
}
Return a list of product stock adjustments.
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('/products:stock', {
limit: 25,
page: 1
});
Response
{
"count": 51,
"results": [
{
"id": "60f199509111e7000000005f",
"parent_id": "60f199509111e70000000066",
"date_created": "2021-07-16T14:36:00.321Z",
"date_updated": "2021-07-16T14:36:00.321Z",
"level": 20,
"number": 1029376,
"reason": "received",
"reason_message": "Restock - PO #47362",
"variant_id": "60f199509111e70000000061"
},
{...},
{...}
],
"page": 1,
"pages": {
"1": {
"start": 1,
"end": 25
},
"2": {
"start": 26,
"end": 50
},
"2": {
"start": 51,
"end": 51
}
}
}