Api : Add image to variant when adding a new product

Topic summary

Issue: How to attach an image to a specific product variant at creation time via the Shopify API.

Context: A variant is being created successfully with fields like option1, price, and sku. Attempts to include the image directly in the variant payload failed.

Tried (none worked when sent in the variant payload):

  • image => $p->image
  • images => $p->image
  • imageSrc => $p->image
  • attachment => base64_encode($r)

Current conclusion: Images are associated with the product, not injected directly into a variant on creation. The workable approach is a two-step process:

  • First add/upload the image to the product (create product image and obtain its image_id).
  • Then update the variant to reference that image by setting variant.image_id.

Status: Resolved with a clear workaround (two-step image assignment). No indication of a single-call solution to create a variant with an image inline.

Summarized with AI on January 25. AI used: gpt-5.

using the shopify api,

i can add product variant like this $product->variants = [ [ “option1” => “color” “price” => “1.23”, “sku” => “abc” ] ]; $shopify->Product->post($p);

But how can i add image to the same variant, i tried with

“image” => $p->image

“images” => $p->image

“imageSrc” => $p->image

“attachment” => base64_encode($r)

but no one is working

Thanks

Seem that the only way is to add the image to a product then get it’s imageId and update the variant image_id.