Accessing variant image via id. Python
I'm trying to use Shopify's python API to get variant image url, I have received image_id and trying to do Image.find but I receive error, please help!
image = shopify.Image.find(variant.image_id) image_url = image.scr
If you already have the
Product resource, then you have all the data you need without making an extra API call to Shopify. Simply take the
image_id from the variant you want and loop through the images on
product.images to see which one matches.
image_id = product.variants.image_id # Or however you pick the variant image_src = None for image in product.images: if image.id == image_id: image_src = image.src break
Or, to wrap it into a function:
def image_src_by_id(product, image_id): image_src = None for image in product.images: if image.id == image_id: image_src = image.src break return image_src
image = shopify.Image.find(variant.image_id, product_id=product.id)
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.