Index
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/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,
"action": "received",
"stock_item_id": 1
}
],
"count": 25,
"pages": 5,
"current_page": 1
}
Search
To search for a particular stock movement, make a request like this:
GET /api/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,
"action": "received",
"stock_item_id": 1
}
],
"count": 25,
"pages": 5,
"current_page": 1
}
Sorting results
Results can be returned in a specific order by specifying which field to sort by when making a request.
GET /api/stock_locations/1/stock_movements?q[s]=quantity%20asc
Show
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/stock_locations/1/stock_movements/1
Successful Response
Status: 200 OK
{
"id": 1,
"quantity": 10,
"action": "received",
"stock_item_id": 1
}
Not Found Response
Status: 404 Not Found
{
"error": "The resource you were looking for could not be found."
}
Create
To create a new stock movement for a stock location, make this request with the necessary parameters:
POST /api/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,
"action": "received",
"stock_item_id": 1
}
Failed response
Status: 422 Unprocessable Entity
{
"error": "Invalid resource. Please fix errors and try again.",
"errors": {
}
}
Update
To update a stock movement’s details, make this request with the necessary parameters:
PUT /api/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": 10,
"action": "received",
"stock_item_id": 1
}
Failed response
Status: 422 Unprocessable Entity
{
"error": "Invalid resource. Please fix errors and try again.",
"errors": {
}
}
Delete
To delete a stock movement, make this request:
DELETE /api/stock_locations/1/stock_movement/1
Response
Status: 204 No Content