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

idobjectId

Unique identifier for the stock adjustment.

parent_idobjectIdrequired

ID of the parent product.

quantityintrequired

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

date_createddateauto

Date and time the stock adjustment was created.

date_updateddateauto

Date and time the stock adjustment was last updated.

levelintrequired

New stock level after the adjustment is applied.

numberstringauto

Auto-incremented stock adjustment number.

order_idobjectIdrequired

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.

orderOrderrequired

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

parentProduct

Expandable link to the parent product.

prevStock

Link to the previous stock adjustment.

prev_idobjectId

ID of the previous stock adjustment.

reasonenum

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

reason_messagestring

A brief description of the reason for the stock adjustment.

variant_idobjectId

ID of the parent variant, if applicable.

variantProduct variant

Expandable link to 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.

Arguments

parent_idobjectIdrequired

The id of the parent product.

quantityintrequired

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

reasonstring

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

reason_messagestring

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

idobjectIdrequired

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

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