Product Images
Index
List product images visible to the authenticated user. If the user is an admin, they are able to see all images.
You may make a request using product’s permalink or id attribute.
Note that the API will attempt a permalink lookup before an ID lookup.
GET /api/v1/products/a-product/images
Response
Status:
200 OK
{"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"}]}
Show
GET /api/v1/products/a-product/images/1
Successful Response
Status:
200 OK
{"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"}
Not Found Response
Status:
404 Not Found
{"error": "The resource you were looking for could not be found."}
New
You can learn about the potential attributes (required and non-required) for a product’s image by making this request:
GET /api/v1/products/a-product/images/new
Response
Status:
200 OK
{
"attributes": [
"id", "position", "attachment_content_type", "attachment_file_name", "type",
"attachment_updated_at", "attachment_width", "attachment_height", "alt"
],
"required_attributes": []
}
Create
This action is only accessible by an admin user.
To upload a new image through the API, make this request with the necessary parameters:
POST /api/v1/products/a-product/images
For instance, a request using cURL will look like this:
curl -i -X POST \
-H "X-Spree-Token: USER_TOKEN" \
-H "Content-Type: multipart/form-data" \
-F "image[attachment]=@/absolute/path/to/image.jpg" \
-F "type=image/jpeg" \
http://localhost:3000/api/v1/products/a-product/images
Successful response
Status:
201 Created
Update
This action is only accessible by an admin user.
To update an image, make this request with the necessary parameters:
PUT /api/v1/products/a-product/images/1
A cURL request to update a product image would look like this:
curl -i -X PUT \
-H "X-Spree-Token: USER_TOKEN" \
-H "Content-Type: multipart/form-data" \
-F "image[attachment]=@/new/path/to/image.jpg" \
-F "type=image/jpeg" \
http://localhost:3000/api/v1/products/a-product/images/1
Successful response
Status:
201 Created
Delete
This action is only accessible by an admin user.
To delete a product image, make this request:
DELETE /api/v1/products/a-product/images/1
This request will remove the record from the database.
Status:
204 No Content