Product Properties
Requests to this API will only succeed if the user making them has access to the underlying products. If the user is not an admin and the product is not available yet, users will receive a 404 response from this API.
List
Retrieve a list of all product properties for a product by making this request:
GET /api/v1/products/1/product_properties
Product properties are paginated and can be iterated through by passing along a page
parameter:
GET /api/v1/products/1/product_properties?page=2
Parameters
- page:
The page number of product properties to display.
- per_page:
The number of product properties to return per page
Response
{"product_properties": [{"id": 1,"product_id": 1,"property_id": 1,"value": "Tote","property_name": "bag_type"}],"count": 10,"current_page": 1,"pages": 2}
Search
To search for a particular product property, make a request like this:
GET /api/v1/products/1/product_properties?q[property_name_cont]=bag
The searching API is provided through the Ransack gem which Boxid depends on. The property_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
{"product_properties": [{"id": 1,"product_id": 1,"property_id": 1,"value": "Tote","property_name": "bag_type"}],"count": 10,"current_page": 1,"pages": 2}
Sorting results
Results can be returned in a specific order by specifying which field to sort by when making a request.
GET /api/v1/products/1/product_properties?q[s]=property_name%20desc
Show
To get information about a single product property, make a request like this:
GET /api/v1/products/1/product_properties/1
Or you can use a property’s name:
GET /api/v1/products/1/product_properties/size
Response
{"id": 1,"product_id": 1,"property_id": 1,"value": "Tote","property_name": "bag_type"}
Create
To create a new product property, make a request like this:
POST /api/v1/products/1/product_properties?product_property[property_name]=size&product_property[value]=10
If a property with that name does not already exist, then it will automatically be created.
Response
{"id": 1,"product_id": 1,"property_id": 1,"value": "Tote","property_name": "bag_type"}
Update
To update an existing product property, make a request like this:
PUT /api/v1/products/1/product_properties/size?product_property[value]=10
You may also use a property’s id if you know it:
PUT /api/v1/products/1/product_properties/1?product_property[value]=10
Response
{"id": 1,"product_id": 1,"property_id": 1,"value": "Tote","property_name": "bag_type"}
Delete
To delete a product property, make a request like this:
DELETE /api/v1/products/1/product_properties/size