Re: Bug: Setting metafields on product images via GraphQL API

Bug: Setting metafields on product images via GraphQL API

_Dominik_
Shopify Partner
31 0 11

 

Hi

 

Adding a metafield to a product image does not work (using 2023-04).

The mutation returns a "User Error" message: "invalid id"

 

(Strangely, creating a metafield definitions with "ownerType": "PRODUCTIMAGE" yields no error.)

 

---------------

To reproduce:
(Replace gid://shopify/ProductImage/XXXXXXXXXX with an actual product image gid)

 

 

mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafields) {
    metafields {
     id
    }
    userErrors {
      field
      message
    }
  }
}

VARIABLES:
{
  "metafields": [
    {
      "key": "test",
      "namespace": "test",
      "ownerId": "gid://shopify/ProductImage/XXXXXXXXXX",
      "value": "test",
      "type": "single_line_text_field"
    }
  ]
}

RESPONSE:
{
  "data": {
    "metafieldsSet": null
  },
  "errors": [
    {
      "message": "invalid id",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "metafieldsSet"
      ]
    }
  ],
}

 

 

 

Replies 4 (4)

ShopifyDevSup
Shopify Staff
1453 238 509

Hi @_Dominik_ 👋

 

Thanks for flagging this! We are working on a fix, and will update you here as soon as it ships.

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

_Dominik_
Shopify Partner
31 0 11

Sweet, thanks @ShopifyDevSup 

 

while I have your attention, and I am digging deep into the image APIs, there are a couple more inconsistencies I found

 

  1. webhooks for the PRODUCTS_UPDATE topic fire as expected when an image is edited via the built-in image editor in the admin UI (e.g. cropping an image) in which case the image gid stays the same while update_at is changed. But they don't fire in the same way when an image is altered via the productimageupdate mutation. 
  2. The rest API includes timestamps (created_at and updated_at) for product image, but the graphql api does not 
  3. The REST api for retrieving products does not include metafields, even if including "metafields" in the "fields" parameter.
  4. But payloads of webhooks for the PRODUCTS_UPDATE topic contains both, the image metafields (when setting correct WebhookSubscriptionInput.metafieldNamespaces) and the image timestamps.

Point 1) I would consider a bug, the others issues at least are very unexpected for me. Point 4) then saves the day, please don't alter that behaviour 😉

Thanks for 
listening.

Cheers

 

EDIT: (One more find from before regarding metafields and webhooks)


5. When listing namespaces to be included via WebhookSubscriptionInput.metafieldNamespaces, the Api layer's resolving of app reserved namespace, like $app:namespace, does not seem to kick in. Typing it out, like {app}--{your-app-id}--{some-namespace}, works

Richard_Monette
Shopify Staff
19 2 7

Hey _Dominik_, regarding your first point, the built-in editor uses the https://shopify.dev/docs/api/admin-graphql/2022-07/mutations/productUpdateMedia mutation. If you prefer the behaviour where the PRODUCTS_UPDATE webhook fires as a result of the update, would using that mutation be an option for you?

To learn more visit the Shopify Help Center or the Community Blog.

_Dominik_
Shopify Partner
31 0 11

Hey @Richard_Monette 

 

Thanks for digging out that information. Very interesting - good thinking.

My particular use case is

  • The app needs to be able to react to any product image changes – no matter how that change was initiated. 
  • The app is not going to initiate updates itself.

 

So I am trying to cover all possible ways that an product image can be altered and making sure that we can react to that without having to bulk crawl the whole product catalog 😄


Hope that makes sense. Any ideas how to solve this? The only way I see is that I need to have confidence that webhooks covers all cases...

Thank you very much for your help!

Dominik