Index

This action is only accessible by an admin user.

To return a paginated list of all stock movements for a stock location, make this request, passing the stock location id you wish to see stock items for:

GET /api/v1/stock_locations/1/stock_movements

Parameters

page
The page number of stock movements to display.
per_page
The number of stock movements to return per page

Response

Status: 200 OK
{
  "stock_movements": [
    {
      "id": 1,
      "quantity": 10,
      "stock_item_id": 1,
      "stock_item": {
        "id": 1,
        "count_on_hand": 10,
        "backorderable": true,
        "stock_location_id": 1,
        "variant_id": 1,
        "variant": {
          "id": 1,
          "name": "Ruby on Rails Tote",
          "sku": "ROR-00011",
          "price": "15.99",
          "weight": null,
          "height": null,
          "width": null,
          "depth": null,
          "is_master": true,
          "slug": "ruby-on-rails-tote",
          "description": "A text description of the product.",
          "track_inventory": true,
          "cost_price": null,
          "option_values": [
            {
              "id": 1,
              "name": "Small",
              "presentation": "S",
              "option_type_name": "tshirt-size",
              "option_type_id": 1,
              "option_type_presentation": "S"
            }
          ],
          "images": [
            {
              "id": 1,
              "position": 1,
              "attachment_content_type": "image/jpg",
              "attachment_file_name": "ror_tote.jpeg",
              "type": "Spree::Image",
              "attachment_updated_at": null,
              "attachment_width": 360,
              "attachment_height": 360,
              "alt": null,
              "viewable_type": "Spree::Variant",
              "viewable_id": 1,
              "mini_url": "/spree/products/1/mini/file.png?1370533476",
              "small_url": "/spree/products/1/small/file.png?1370533476",
              "product_url": "/spree/products/1/product/file.png?1370533476",
              "large_url": "/spree/products/1/large/file.png?1370533476"
            }
          ],
          "display_price": "$15.99",
          "options_text": "(Size: small, Colour: red)",
          "in_stock": true,
          "is_backorderable": true,
          "is_orderable": true,
          "total_on_hand": 10,
          "is_destroyed": false
        }
      }
    }
  ],
  "count": 25,
  "current_page": 1,
  "pages": 5
}
This action is only accessible by an admin user.

To search for a particular stock movement, make a request like this:

GET /api/v1/stock_locations/1/stock_movements?q[quantity_eq]=10

The searching API is provided through the Ransack gem which Spree depends on. The quantity_eq here is called a predicate, and you can learn more about them by reading about Predicates on the Ransack wiki.

The search results are paginated.

Response

Status: 200 OK
{
  "stock_movements": [
    {
      "id": 1,
      "quantity": 10,
      "stock_item_id": 1,
      "stock_item": {
        "id": 1,
        "count_on_hand": 10,
        "backorderable": true,
        "stock_location_id": 1,
        "variant_id": 1,
        "variant": {
          "id": 1,
          "name": "Ruby on Rails Tote",
          "sku": "ROR-00011",
          "price": "15.99",
          "weight": null,
          "height": null,
          "width": null,
          "depth": null,
          "is_master": true,
          "slug": "ruby-on-rails-tote",
          "description": "A text description of the product.",
          "track_inventory": true,
          "cost_price": null,
          "option_values": [
            {
              "id": 1,
              "name": "Small",
              "presentation": "S",
              "option_type_name": "tshirt-size",
              "option_type_id": 1,
              "option_type_presentation": "S"
            }
          ],
          "images": [
            {
              "id": 1,
              "position": 1,
              "attachment_content_type": "image/jpg",
              "attachment_file_name": "ror_tote.jpeg",
              "type": "Spree::Image",
              "attachment_updated_at": null,
              "attachment_width": 360,
              "attachment_height": 360,
              "alt": null,
              "viewable_type": "Spree::Variant",
              "viewable_id": 1,
              "mini_url": "/spree/products/1/mini/file.png?1370533476",
              "small_url": "/spree/products/1/small/file.png?1370533476",
              "product_url": "/spree/products/1/product/file.png?1370533476",
              "large_url": "/spree/products/1/large/file.png?1370533476"
            }
          ],
          "display_price": "$15.99",
          "options_text": "(Size: small, Colour: red)",
          "in_stock": true,
          "is_backorderable": true,
          "is_orderable": true,
          "total_on_hand": 10,
          "is_destroyed": false
        }
      }
    }
  ],
  "count": 25,
  "current_page": 1,
  "pages": 5
}

Sorting results

Results can be returned in a specific order by specifying which field to sort by when making a request.

GET /api/v1/stock_locations/1/stock_movements?q[s]=quantity%20asc

Show

This action is only accessible by an admin user.

To view the details for a single stock movement, make a request using that stock movement’s id, along with its stock_location_id:

GET /api/v1/stock_locations/1/stock_movements/1

Successful Response

Status: 200 OK
{
  "id": 1,
  "quantity": 10,
  "stock_item_id": 1,
  "stock_item": {
    "id": 1,
    "count_on_hand": 10,
    "backorderable": true,
    "stock_location_id": 1,
    "variant_id": 1,
    "variant": {
      "id": 1,
      "name": "Ruby on Rails Tote",
      "sku": "ROR-00011",
      "price": "15.99",
      "weight": null,
      "height": null,
      "width": null,
      "depth": null,
      "is_master": true,
      "slug": "ruby-on-rails-tote",
      "description": "A text description of the product.",
      "track_inventory": true,
      "cost_price": null,
      "option_values": [
        {
          "id": 1,
          "name": "Small",
          "presentation": "S",
          "option_type_name": "tshirt-size",
          "option_type_id": 1,
          "option_type_presentation": "S"
        }
      ],
      "images": [
        {
          "id": 1,
          "position": 1,
          "attachment_content_type": "image/jpg",
          "attachment_file_name": "ror_tote.jpeg",
          "type": "Spree::Image",
          "attachment_updated_at": null,
          "attachment_width": 360,
          "attachment_height": 360,
          "alt": null,
          "viewable_type": "Spree::Variant",
          "viewable_id": 1,
          "mini_url": "/spree/products/1/mini/file.png?1370533476",
          "small_url": "/spree/products/1/small/file.png?1370533476",
          "product_url": "/spree/products/1/product/file.png?1370533476",
          "large_url": "/spree/products/1/large/file.png?1370533476"
        }
      ],
      "display_price": "$15.99",
      "options_text": "(Size: small, Colour: red)",
      "in_stock": true,
      "is_backorderable": true,
      "is_orderable": true,
      "total_on_hand": 10,
      "is_destroyed": false
    }
  }
}

Not Found Response

Status: 404 Not Found
{
  "error": "The resource you were looking for could not be found."
}

Create

This action is only accessible by an admin user.

To create a new stock movement for a stock location, make this request with the necessary parameters:

POST /api/v1/stock_locations/1/stock_movements

For instance, a request to create a new stock movement with a quantity of 10, the action set to received, and a stock_item_id of 1 would look like this::

{
  "stock_movement": {
    "quantity": "10",
    "stock_item_id": "1",
    "action": "received"
  }
}

Successful response

Status: 201 Created
{
  "id": 1,
  "quantity": 10,
  "stock_item_id": 1,
  "stock_item": {
    "id": 1,
    "count_on_hand": 10,
    "backorderable": true,
    "stock_location_id": 1,
    "variant_id": 1,
    "variant": {
      "id": 1,
      "name": "Ruby on Rails Tote",
      "sku": "ROR-00011",
      "price": "15.99",
      "weight": null,
      "height": null,
      "width": null,
      "depth": null,
      "is_master": true,
      "slug": "ruby-on-rails-tote",
      "description": "A text description of the product.",
      "track_inventory": true,
      "cost_price": null,
      "option_values": [
        {
          "id": 1,
          "name": "Small",
          "presentation": "S",
          "option_type_name": "tshirt-size",
          "option_type_id": 1,
          "option_type_presentation": "S"
        }
      ],
      "images": [
        {
          "id": 1,
          "position": 1,
          "attachment_content_type": "image/jpg",
          "attachment_file_name": "ror_tote.jpeg",
          "type": "Spree::Image",
          "attachment_updated_at": null,
          "attachment_width": 360,
          "attachment_height": 360,
          "alt": null,
          "viewable_type": "Spree::Variant",
          "viewable_id": 1,
          "mini_url": "/spree/products/1/mini/file.png?1370533476",
          "small_url": "/spree/products/1/small/file.png?1370533476",
          "product_url": "/spree/products/1/product/file.png?1370533476",
          "large_url": "/spree/products/1/large/file.png?1370533476"
        }
      ],
      "display_price": "$15.99",
      "options_text": "(Size: small, Colour: red)",
      "in_stock": true,
      "is_backorderable": true,
      "is_orderable": true,
      "total_on_hand": 10,
      "is_destroyed": false
    }
  }
}

Failed response

Status: 422 Unprocessable Entity
{
  "error": "Invalid resource. Please fix errors and try again.",
  "errors": {

  }
}

Update

This action is only accessible by an admin user.

To update a stock movement’s details, make this request with the necessary parameters:

PUT /api/v1/stock_locations/1/stock_movements/1

For instance, to update a stock movement’s quantity, send it through like this:

{
  "stock_movement": {
    "quantity": "30"
  }
}

Successful response

Status: 201 Created
{
  "id": 1,
  "quantity": 30,
  "stock_item_id": 1,
  "stock_item": {
    "id": 1,
    "count_on_hand": 10,
    "backorderable": true,
    "stock_location_id": 1,
    "variant_id": 1,
    "variant": {
      "id": 1,
      "name": "Ruby on Rails Tote",
      "sku": "ROR-00011",
      "price": "15.99",
      "weight": null,
      "height": null,
      "width": null,
      "depth": null,
      "is_master": true,
      "slug": "ruby-on-rails-tote",
      "description": "A text description of the product.",
      "track_inventory": true,
      "cost_price": null,
      "option_values": [
        {
          "id": 1,
          "name": "Small",
          "presentation": "S",
          "option_type_name": "tshirt-size",
          "option_type_id": 1,
          "option_type_presentation": "S"
        }
      ],
      "images": [
        {
          "id": 1,
          "position": 1,
          "attachment_content_type": "image/jpg",
          "attachment_file_name": "ror_tote.jpeg",
          "type": "Spree::Image",
          "attachment_updated_at": null,
          "attachment_width": 360,
          "attachment_height": 360,
          "alt": null,
          "viewable_type": "Spree::Variant",
          "viewable_id": 1,
          "mini_url": "/spree/products/1/mini/file.png?1370533476",
          "small_url": "/spree/products/1/small/file.png?1370533476",
          "product_url": "/spree/products/1/product/file.png?1370533476",
          "large_url": "/spree/products/1/large/file.png?1370533476"
        }
      ],
      "display_price": "$15.99",
      "options_text": "(Size: small, Colour: red)",
      "in_stock": true,
      "is_backorderable": true,
      "is_orderable": true,
      "total_on_hand": 10,
      "is_destroyed": false
    }
  }
}

Failed response

Status: 422 Unprocessable Entity
{
  "error": "Invalid resource. Please fix errors and try again.",
  "errors": {

  }
}