REST Product API - Create Product and attach Variant Image by URL instead of Image ID

Giulio1
Excursionist
31 3 7

Is there a way to create a product with one or many variants and attach a variant image to the variants right away.

 

To my understanding:

I create a product with images and variants ---> Shopify will generate IDs for those images and variants

Than I'd retrieve those IDs and match them - VARIANT ID { image_id : IMAGE_ID} with the Variant API

 

Can I do this instead?

POST /admin/api/2019-10/products.json
{
  "product": {
    "title": "Product 1",
    "variants" : [{"option1": "Default Title",  IMAGE_SRC: "https//something"}]
} }

Thank you

 

 

Code402
Shopify Partner
50 10 23

Hey Giulio,

 

I don't believe you can do this via the REST API (see this thread from a year ago), however, it appears to be possible in the productCreate GraphQL API.

Code 402 Inc - Ecommerce Consulting in Kitchener, Ontario, Canada
0 Likes
Giulio1
Excursionist
31 3 7

Hi,

Thanks for the link

I will stick to REST for now though,

 

I think that the shortest path to take using rest is to create in one go products and variants

and later POST the images to the product by the  images endpoint with the list of variants id

 

One can also create the product with variants and images together, but then you have to retrieve the image id and pass them to the variants, which becomes a bowl of spaghetti

 

 

0 Likes
HMM100
Tourist
6 0 0

Can you teach me how to use graphql to realize this function?can you give me a code example?

0 Likes