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

objectId

Unique identifier for the stock adjustment.

date_created

dateauto

Date and time the stock adjustment was created.

date_updated

dateauto

Date and time the stock adjustment was last updated.

description

string

A brief description of the stock entry.

level

intrequired

New stock level after the adjustment is applied.

location

string

Location associated to the stock entry, if applicable.

number

stringauto

Auto-incremented stock adjustment number.

order

Orderrequired

Expandable link to an order, if applicable to the stock adjustment.

order_id

objectIdrequired

ID 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

Product

Expandable link to the parent product.

parent_id

objectIdrequired

ID of the parent product.

prev

Stock

Link to the previous stock adjustment.

prev_id

objectId

ID of the previous stock adjustment.

quantity

intrequired

Quantity of the adjustment. A positive number means stock was increased, and a negative number means stock was decreased.

reason

enum

Enumerated reason for the stock adjustment. Can be received, returned, canceled, sold, missing, or damaged.

Possible enum values:

receivedreturnedcanceledsoldmissingdamaged

reason_message

string

A brief description of the reason for the stock adjustment.

variant

Product variant

Expandable link to the parent variant, if applicable.

variant_id

objectId

ID 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

objectIdrequired

The id of the parent product.

quantity

intrequired

Quantity of the adjustment. A positive number means the stock was increased, and a negative number means the stock was decreased.

reason

string

Enumerated reason for the stock adjustment. Can be received, returned, canceled, sold, missing, or damaged.

reason_message

string

A brief description of the reason for the stock adjustment.

POST/products:stock
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

objectIdrequired

The id of the stock adjustment 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 stock adjustment 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/products:stock/:id
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

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/products:stock
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
    }
  }
}