Difference between revisions of "API Image"
From Spiffy Stores Knowledge Base
Line 122: | Line 122: | ||
</pre> | </pre> | ||
− | |||
=== <code>GET /api/products/(OBJECT_ID|OBJECT_HANDLE)/images/count.json<br/>GET /api/standard_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json<br/>GET /api/super_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json</code> === | === <code>GET /api/products/(OBJECT_ID|OBJECT_HANDLE)/images/count.json<br/>GET /api/standard_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json<br/>GET /api/super_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json</code> === | ||
Revision as of 13:13, 20 November 2014
The Spiffy Stores API Image object represents an image that may belong to either a product or a collection. Images can be in either .png
, .gif
or .jpg
format.
You can view a product or collection's images, update them, create new ones, and delete them.
Contents
- 1 Accessing a Product, StandardCollection or SuperCollection
- 2 Image Properties
- 3 Endpoints
- 3.1 GET /api/products/(OBJECT_ID|OBJECT_HANDLE)/images.jsonGET /api/standard_collections/(OBJECT_ID|OBJECT_HANDLE)/images.jsonGET /api/super_collections/(OBJECT_ID|OBJECT_HANDLE)/images.json
- 3.2 GET /api/products/(OBJECT_ID|OBJECT_HANDLE)/images/count.jsonGET /api/standard_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.jsonGET /api/super_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json
- 3.3 GET /api/products/(PRODUCT_ID|PRODUCT_HANDLE).json
- 3.4 POST /api/products.json
- 3.5 PUT /api/products/PRODUCT_ID.json
- 3.6 DELETE /api/products/(PRODUCT_ID|PRODUCT_HANDLE).json
- 4 Further Reference
Accessing a Product, StandardCollection or SuperCollection
If you want to refer to a single Product, StandardCollection or SuperCollection then you will need to use the unique id that has been assigned to that object.
The object ids are internally generated by the software and cannot be created or assigned.
Alternatively, you may specify the object handle in place of the object id when requesting access to the object. The handle is the unique character string that is assigned to every product, standard or super collection when it is created. The handle is used in the URL to display the product or collection page.
For example, you may retrieve a product's images in two ways.
GET /api/products/12345678/images.json or GET /api/products/cute-dog/images.json
The advantage of using the handle form of the request is that you don't need to search all the products first in order to determine the product id, as you will already know what the handle is. This will reduce the number of API calls that you need to make and greatly simplifies the amount of coding that is needed to manage your products.
Image Properties
id | { "id" : 123456789 } A unique numeric identifier for the image. |
position | { "position" : 1 } The position of the image in the ordered list of images. The first image has a position of 1 and is the main image for the product or collection. |
alt | { "alt" : "This is the alt text for the image" } Images may have some associated alternative text which can be used when the image can't be displayed. It also provided additional information for screen readers and search engines. |
filename | { "filename" : "cute-puppy.jpg" } The filename of the image is the base name of the image file as originally uploaded. |
src | { "src" : "http://server1.spiffystores.com/sites/4/products/123456789_cute_puppy_full.jpg?6afd63d069abc37a673dd3927e283633" } Specifies the full URL for the image. |
product_id | { "product_id" : 123456789 } The id of the image's associated product. |
collection_id | { "collection_id" : 123456789 } The id of the image's associated collection. |
Endpoints
GET /api/products/(OBJECT_ID|OBJECT_HANDLE)/images.json
GET /api/standard_collections/(OBJECT_ID|OBJECT_HANDLE)/images.json
GET /api/super_collections/(OBJECT_ID|OBJECT_HANDLE)/images.json
GET /api/standard_collections/(OBJECT_ID|OBJECT_HANDLE)/images.json
GET /api/super_collections/(OBJECT_ID|OBJECT_HANDLE)/images.json
Return a list of images belonging to either a product, standard collection or super collection.
Optional Parameters
limit | Number of results returned. The default is 30, with a maximum of 50 in a single request. |
page | The number of the page to return. The number of results per page is set by the limit parameter. If more results are required, then submit the request again, increasing the page number each time.
|
since_id | Limit the results to only include objects which have an id greater than the given value. |
fields | A comma-separated list of fields to return in the response. |
Example Request and Response
GET /api/products/123456789/images.json HTTP/1.1 200 OK { "images" : [ { "id": 2321, "position": 1, "alt": "", "filename": "penguins.jpg", "src": "http://server1.spiffystores.com/sites/4/products/156_penguins_full.jpg?936fec7af78d49584087eed3339c4e13", "product_id": 156 }, { "id": 2324, "position": 2, "alt": "", "filename": "jellyfish.jpg", "src": "http://server1.spiffystores.com/sites/4/products/156_jellyfish_full.jpg?cfe2abb2c206c8ad0196d84e53b100a0", "product_id": 156 } ] } Examples using filters GET /api/products/123456789/images.json?fields=id,src Alternative form GET /api/products/fluffy-puppy/images.json GET /api/standard_collections/home-collection/images.json GET /api/super_collections/featured-collection/images.json
GET /api/products/(OBJECT_ID|OBJECT_HANDLE)/images/count.json
GET /api/standard_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json
GET /api/super_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json
GET /api/standard_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json
GET /api/super_collections/(OBJECT_ID|OBJECT_HANDLE)/images/count.json
Return a count of images.
Optional Parameters
since_id | Limit the results to only include objects which have an id greater than the given value. |
Example Request and Response
GET /api/products/fluffy-puppy/images/count.json HTTP/1.1 200 OK { "count": 2 } Examples using filters GET /api/products/123456789/images/count.json?since_id=1000
GET /api/products/(PRODUCT_ID|PRODUCT_HANDLE).json
Return a single product.
Optional Parameters
fields | A comma-separated list of fields to return in the response. |
Example Request and Response
GET /api/products/123456789.json HTTP/1.1 200 OK { "product": { "id": 123456789, "title": "Cute Puppy", "handle": "cute-puppy", "body": "A very cute puppy.", ... } } Alternative form GET /api/products/cute-puppy.json
POST /api/products.json
Create a new product.
You can include images for the new product, either by including the image as Base64 data using the attachment
tag, or by including a URL to the image which can be used to download the image using the src
tag.
Example Request and Response
POST /api/products.json { "product": { "title": "Brand New Product", "body": "A must for every home.", "vendor": "Big Brand", "product_type": "Gadget", "tags": "yellow, gadget, blue, home", "variations": [ { "option1": "Large", "option2": "Yellow", "price": "10.00", "sku": "123", "inventory_quantity": 100 }, { "option1": "Small", "option2": "Blue", "price": "20.00", "sku": "456", "inventory_quantity": 50 } ], "options": [ { "name": "Size", "position": 1 }, { "name": "Colour", "position": 2 } ], "images": [ { "attachment": "R0lGODlhAQABAIAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\n", "filename": "cute_puppy.jpg" }, { "src": "http://www.puppies-r-us.com/images/cute_puppy2.jpg", "filename": "cute_puppy2.jpg" } ] } } HTTP/1.1 201 Created
PUT /api/products/PRODUCT_ID.json
Update a product and associated images and variations.
You can include images for the updated product, either by including the image as Base64 data using the attachment
tag, or by including a URL to the image which can be used to download the image using the src
tag.
When you update a product, you must include the id
parameter, which must match the product_id specified in the POST URL.
You can update any of the product properties by including the parameter in the PUT data. All other product properties remain unchanged.
You cannot change the number of options. Only the name of the option can be updated.
Product variations, custom_options and images cannot be individually updated using this API. If you specify any new variations, custom_options or images, then all existing variations, custom_options or images are deleted and replaced by the new variations, custom_options or images provided by this API.
Individual variations and images can be updated using the specific API calls for Variations and Images.
Example Request and Response
PUT /api/products/123456789.json { "product": { "id": 123456789, "title": "This is a new title" } } HTTP/1.1 200 OK
DELETE /api/products/(PRODUCT_ID|PRODUCT_HANDLE).json
Delete a product and all associated images and variations.
Example Request and Response
DELETE /api/products/123456789.json HTTP/1.1 200 OK {} Alternative form DELETE /api/products/cute-puppy.json