Index
To get a list of stock locations, make this request:
GET /api/stock_locations
Stock locations are paginated and can be iterated through by passing along a page
parameter:
GET /api/stock_locations?page=2
Parameters
- page
- The page number of stock location to display.
- per_page
- The number of stock locations to return per page
Response
Status: 200 OK
{
"stock_locations": [
{
"id": 1,
"name": "default",
"address1": "7735 Old Georgetown Road",
"address2": "Suite 510",
"city": "Bethesda",
"state_id": 26,
"country_id": 49,
"zipcode": "20814",
"phone": "",
"active": true
}
],
"count": 5,
"pages": 1,
"current_page": 1
}
Search
To search for a particular stock location, make a request like this:
GET /api/stock_locations?q[name_cont]=default
The searching API is provided through the Ransack gem which Spree depends on. The name_cont
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_locations": [
{
"id": 1,
"name": "default",
"address1": "7735 Old Georgetown Road",
"address2": "Suite 510",
"city": "Bethesda",
"state_id": 26,
"country_id": 49,
"zipcode": "20814",
"phone": "",
"active": true
}
],
"count": 5,
"pages": 1,
"current_page": 1
}
Show
To get information for a single stock location, make this request:
GET /api/stock_locations/1
Response
Status: 200 OK
{
"id": 1,
"name": "default",
"address1": "7735 Old Georgetown Road",
"address2": "Suite 510",
"city": "Bethesda",
"state_id": 26,
"country_id": 49,
"zipcode": "20814",
"phone": "",
"active": true
}
Create
To create a stock location, make a request like this:
POST /api/stock_locations
Assuming in this instance that you want to create a stock location with a name of East Coast
, send through the parameters like this:
{
"stock_location": {
"name": "East Coast",
"action": "true"
}
}
Response
Status: 201 Created
{
"id": 1,
"name": "default",
"address1": "7735 Old Georgetown Road",
"address2": "Suite 510",
"city": "Bethesda",
"state_id": 26,
"country_id": 49,
"zipcode": "20814",
"phone": "",
"active": true
}
Update
To update a stock location, make a request like this:
PUT /api/stock_locations/1
To update stock location information, use parameters like this:
{
"stock_location": {
"name": "North Pole",
"action": "false"
}
}
Response
Status: 200 OK
{
"id": 1,
"name": "default",
"address1": "7735 Old Georgetown Road",
"address2": "Suite 510",
"city": "Bethesda",
"state_id": 26,
"country_id": 49,
"zipcode": "20814",
"phone": "",
"active": true
}
Delete
To delete a stock location, make a request like this:
DELETE /api/stock_locations/1
This request will also delete any related stock item
records.
Response
Status: 204 No Content