Create a stock item

How to create a stock item via API

To create a new stock item, send a POST request to the /api/stock_items endpoint, passing the resource arguments in the request body.

Request

POST https://yourdomain.commercelayer.io/api/stock_items

Arguments

Body Parameter
Type
Required

type

string

Required

attributes.sku_code

string

Optional

attributes.quantity

integer

Required

attributes.reference

string

Optional

attributes.reference_origin

string

Optional

attributes.metadata

object

Optional

relationships.stock_location

object

Required

relationships.sku

object

Required, if not set through the sku_code attribute

Example

The following request creates a new stock item:

curl -g -X POST \
  'https://yourdomain.commercelayer.io/api/stock_items' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -H 'Content-Type: application/vnd.api+json' \
  -d '{
  "data": {
    "type": "stock_items",
    "attributes": {
      "quantity": 100
    },
    "relationships": {
      "stock_location": {
        "data": {
          "type": "stock_locations",
          "id": "ABCRtyUpBa"
        }
      },
      "sku": {
        "data": {
          "type": "skus",
          "id": "BCDRtyUpBa"
        }
      }
    }
  }
}'

Last updated