Product Images

Hi All,

Just want to get clarification on a question regarding Products and their images on the API.

1. A Product has both the Images array, as well as a single Image associated. If we only want the featured image, can we just use the Image, and ignore the Images array?

<images type="array">
  <image>
    <created-at type="datetime">2014-02-06T04:01:52-05:00</created-at>
    <id type="integer">477060909</id>
    <position type="integer">2</position>
    <product-id type="integer">233569105</product-id>
    <updated-at type="datetime">2014-02-06T04:02:33-05:00</updated-at>
    <src>
        http://cdn.shopify.com/s/files/1/0160/8562/products/printer.png?v=1391677353
    </src>
  </image>
</images>
<image>
  <created-at type="datetime">2014-02-06T04:01:52-05:00</created-at>
  <id type="integer">477060909</id>
  <position type="integer">2</position>
  <product-id type="integer">233569105</product-id>
  <updated-at type="datetime">2014-02-06T04:02:33-05:00</updated-at>
  <src>
    http://cdn.shopify.com/s/files/1/0160/8562/products/printer.png?v=1391677353
  </src>
</image>
 

2. If we do need to use the Images array: The documentation states that the featured image will be set with Position 1 in the array. However, in testing I have found that sometimes there is no image in Position 1 (see above example). Can we assume that the image with the lowest Position is the featured one?

If anyone can shed some light on this it would be much appreciated :)

Thanks & good weekend to all,

Bjorn

Bjorn Forsberg | FORSBERG+two | Award-winning Shopify Apps since 2011
0 Likes
Shopify Staff
Shopify Staff
93 0 15

If you're looking to just get the product image then yes, the Product.image property works great for this. This property is set automatically with the values for the featured image. That being said, you can't set the featured image using this.

The featured image, for its part, is indeed determined by the image with the lowest position value. If no image has position => 1 but an image has a position => 2, then that second image will become the featured image. 

0 Likes

Thanks Ben, as we are after only the featured image we can now simplify the code a bit :)

Bjorn Forsberg | FORSBERG+two | Award-winning Shopify Apps since 2011
0 Likes