Understand the image resizing REST APIs

Commerce Service REST APIs allow you to resize images displayed on your store while optimizing load times and maintaining image quality.

Note: See Use the REST APIs for information you need to know before using the REST APIs.

View image file names and paths

To view file names and paths for uploaded images for a product or collection, issue a GET request to the /ccstore/v1/products/{id} or /ccstore/v1/collections/{id} endpoint. For example:

GET /ccstore/v1/products/prod10007 HTTP/1.1
 Authorization: Bearer <access_token>

The following portion of the sample response shows the URLs of the product’s large image:

  "primaryLargeImageURL":"/ccstore/v1/images/?source=/file/v7875483805069966233/products/APP_WeekendTrouser_large.jpg&height=940&width=940",

The path returned here is the full path to the location of the image file. (See Manage Media for Your Store for more information about the locations of uploaded images.)

Resize an image via the REST API

To resize an existing image, you use the Store API, which provides access to the storefront. Issue a GET request to the /ccstore/v1/images endpoint. The following table describes the query parameters you specify in the request.

Property Description
source

(Required) String that specifies the fully qualified URL for the image to resize. This is returned in the response to

GET /ccstore/v1/products/{id} or

GET /ccstore/v1/collections/{id}.

height (Required) The maximum height for the resized image, in pixels. If the request does not include either height or width, the source image is not resized.
width (Required) The maximum width for the resized image, in pixels. If the request does not include either height or width, the source image is not resized.
quality

A number that lets you control the image resolution quality. The value of quality is a number from 0.0 (worst resolution but fastest load time) to 1.0 (best resolution but slowest load time).

For example, you might want to reduce the resolution of product listing images to speed up image loading times.

The default value of quality is 1.0.

outputFormat The format of the converted images. Only JPEG is supported.
alphaChannelColor The hexadecimal color code for the replacement color of the PNG alpha channel (default is white, FFFFFF).

For example, the following request resizes a product image to 500x500:

GET /ccstore/v1/images/?source=/file/v7875483805069966233/products
        /APP_WeekendTrouser_full.jpg&height=500&width=500