FROM CACHE - en_header

Product, Variant, Image and Option Update via API strategy

jonmjones
Shopify Partner
26 0 17

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

Replies 8 (8)
Alex
Shopify Staff
Shopify Staff
1561 81 323

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.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

jonmjones
Shopify Partner
26 0 17

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

Alex
Shopify Staff
Shopify Staff
1561 81 323

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.

Alex | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit the Shopify Help Center or the Shopify Blog

GrantDB
Shopify Partner
57 2 10

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

den232
Shopify Partner
108 1 27

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
}
}
}
}
HMM100
Tourist
6 0 0
So there's no answer to this question?I have this problem now
jonmjones
Shopify Partner
26 0 17

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

den232
Shopify Partner
108 1 27

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