Assign a product image to a variant
POST https://api.squarespace.com/{api-version}/commerce/products/{productId}/variants/{variantId}/image
Assigns an image from a product’s collection of images to a variant of the physical product. A variant can only reference one product image at most.
A successful request assigns a ProductImage
to a ProductVariant
or removes the relationship between them.
Read the Overview to learn more about the mentioned resources.
Note: A product must have an image before sending a request to this endpoint. To add an image to a product, see Upload a product image.
Parameters
If needed, see the "Related endpoints" section to learn how to retrieve resource ids.
{api-version}
string
required
See the Products API Overview page for the current API version.
{productId}
string
required
Specifies the parent Product
of the ProductVariant
.
{variantId}
string
required
Specifies the ProductVariant
that should reference the ProductImage
.
Request example
Read the Making requests guide to learn why specific headers are necessary, and why some are omitted. Every request should also abide by Squarespace rate limits.
curl "https://api.squarespace.com/1.0/commerce/products/123/variants/456/image" \
-i \
-H "Authorization: Bearer YOUR_API_KEY_OR_OAUTH_TOKEN" \
-H "User-Agent: YOUR_CUSTOM_APP_DESCRIPTION"
-H "Content-Type: application/json" \
-X POST \
-d '{' \
# Required; string. The id of the ProductImage for the ProductVariant.
# Use `null` remove the relationship to a `ProductImage` from the `ProductVariant`.
'"imageId": "5ba1418df4204bb2d21eac3f",' \
'}'
Response example
A response to a successful request will not contain any data.
Status codes and error conditions
204 NO CONTENT
The request was successful. The message body does not contain any data.
400 BAD REQUEST
Type: INVALID_REQUEST_ERROR
Subtype: null
The imageId
field does not represent a ProductImage
belonging to the specified Product
.
404 NOT FOUND
Type: INVALID_REQUEST_ERROR
Subtype: INVALID_ARGUMENT
Either the Product
or the ProductVariant
was not found.
405 METHOD NOT ALLOWED
Type: METHOD_NOT_ALLOWED
Subtype: OPERATION_NOT_ALLOWED_FOR_PRODUCT_TYPE
The Product
requested is not a physical Product
.
Related endpoints
To retrieve ids for Products
and their ProductVariants
and ProductImages
, use these suggested endpoints: