Product, Variant, Image and Option Update via API strategy

jonmjones
Shopify Partner
23 0 4

I'm managing a large inventory of products between warehouse systems and Shopify.

 

The products are added by API initially and the Shopify Product ID is stored in the warehouse product database. The variant, image and option IDs are not stored as we have not found a good way to match them on creation (Shopify appears to re-order them etc). Products Images are uploaded via src field and Shopify downloads them automatically. We have not found a way yet to tie the product image to the variant as we are attempting to keep API calls to a minimum and add Product with Variants, Options and Images in a single call.

 

The products often have updates (changes to descriptions, additional variants, updated variants, new images etc).

 

Could anyone suggest a good strategy for managing this please?  The dirty way is to delete the Product and treat the update as a new Shopify Product however that has issues with referential integrity our end and flags the product as new which it isn't on the Shopify end.  

 

Many thanks

 

Jon

Alex
Shopify Staff
Shopify Staff
1555 81 294

We have not found a way yet to tie the product image to the variant

This should be doable via the images field on the product level. Each product_image should have a variants_ids array, indicating which variants that image is associated with. Am I missing something here?

 

Cheers.

0 Likes
jonmjones
Shopify Partner
23 0 4

Hi Alex, thanks for the reply.

 

I understand the product_image has variants_ids array, however at time of adding product, those variant_ids are not known as they are generated by Shopify.

 

I'm trying to do it all in a single call. Is there a better way?

 

Many thanks

0 Likes
Alex
Shopify Staff
Shopify Staff
1555 81 294

It looks like you can definitely do this with the GraphQL productCreate and productUpdate mutations. The VariantInput type takes an imageSrc value, which will download and apply the image to the variant at the time of creation.

 

Does that work for you?

 

Cheers.

0 Likes
GrantDB
Explorer
48 2 8

Hi there

 

Could you explain please how this would work, what the code would look like.  It isn't clear to me how you would get the src from the product images

 

Thanks

 

Grant

0 Likes
den232
Excursionist
33 0 0

The VariantInput type takes an imageSrc value, which will download and apply the image to the variant at the time of creation. ... 

I'm having no joy in this.  The GraphQL interface does accept the imageSrc ... but ignores it.  When I query the database for images or look at it using the shopify paroduct page, these images do not exist.

 

Please advise ... is there a better / different way to add variants AND images AND assign the images to the variants to a product in one shot?

 

Thanks and best regards, jb

 

My input code:

mutation {
  productUpdate(input: 
{title: "title for howlites", 
descriptionHtml: "wordy descr howlites", 
tags: "oval, stoney", 
    id: "gid://shopify/Product/5383773421732"
variants: [ 
sku: "144", 
barcode:"short descr 144",
          options: "option144",
        },
sku: "145", 
barcode:"short descr 145",
          options: "option145",
        },
],
images: [
{
altText: "image of f0142"
        },
 
      ],
}
) {
product {
id images (first:5) {
  edges {
    node {
      id
    }
  }
}
      variants (first:5) {
        edges {
            node {
                id
                
              }
          }
      }
}
userErrors {
field
message
}
}
}
 
The response I received:
 
{
"data": {
"productUpdate": {
"product": {
"id": "gid://shopify/Product/5383773421732",
"images": {
"edges": [
{
"node": {
"id": "gid://shopify/ProductImage/17703249903780"
}
}
]
},
"variants": {
"edges": [
{
"node": {
"id": "gid://shopify/ProductVariant/34918147031204"
}
},
{
"node": {
"id": "gid://shopify/ProductVariant/34918147063972"
}
}
]
}
},
"userErrors": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 24,
"actualQueryCost": 17,
"throttleStatus": {
"maximumAvailable": 1000,
"currentlyAvailable": 983,
"restoreRate": 50
}
}
}
}
0 Likes
HMM100
Tourist
6 0 0
So there's no answer to this question?I have this problem now
0 Likes
jonmjones
Shopify Partner
23 0 4

I never found a solution without multiple calls which isn’t ideal. Maybe Shopify could comment with a strategy?

0 Likes
den232
Excursionist
33 0 0

I'm still at multiple calls.  If it's a product with just one (default) variant, I can add the product, variant, image(s) all in one go with productCreate.  But assigning images to multiple variants, nope.  jb

0 Likes