Grapql productImageUpdate not working? ID of the image should be present

Solved
Anonymous
Not applicable
1812 0 0

Hello

I want to update my products images with productImageUpdate method from shopify graphql but getting always following message:

 

"ID of the image should be present"

But don't know what I need to do. 

Here the productUpdateImage documentation

I tried the example in the documentation:

 

mutation productImageUpdate($productId: ID!, $image: ImageInput!) {
  productImageUpdate(productId: $productId, image: $image) {
    image {
      id
    }
    userErrors {
      field
      message
    }
  }
}

 

Variables:

 

{
  "productId": "gid://shopify/Product/6138041729194",
  "image": {"src": "https://test.jp"}
}

 

 

Getting following message or error:

 

 

{
  "data": {
    "productImageUpdate": {
      "image": null,
      "userErrors": [
        {
          "field": [
            "image",
            "id"
          ],
          "message": "ID of the image should be present"
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 990,
        "restoreRate": 50
      }
    }
  }
}

 

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

This is an accepted solution.

Looking at the API docs, this method appears to be intended for updating the source for an existing product image. Not necessarily the same thing as loading a new product image. Here is the way the variables should probably be defined. But this is based on the assumption that the product image is already defined.

 

{
  "productId": "gid://shopify/Product/6138041729194",
  "image": {
      "id": "gid://shopify/ProductImage/{whatever_is_defined}",
      "src": "https://test.jp"
  }
}

 

Anonymous
Not applicable
1812 0 0

Hi

Many thanks for your response.

Is it also possible update multiple images, e.g. :

 

{
"productId": "gid://shopify/Product/6138041729194",
"image": { {
"id": "gid://shopify/ProductImage/{whatever_is_defined}",
"src": "https://test.jp"
}, 
{
"id": "gid://shopify/ProductImage/{whatever_is_defined}",
"src": "https://test2.jp"
}
}
}
0 Likes
Greg_Kujawa
Shopify Partner
1016 83 237

Why not try it out and see what comes back? Although you would presumably need an array delimiter around multiple values? Like [ and ]. There is a GraphiQL app you can install in the Shopify shop admin that will allow you play around in real time.