[GraphQL] Cant get metafield for product using key and namespace

Solved
Highlighted
New Member
3 0 0

Hi Shopify team!

 

I am Charly, Lead Engineer of the Shopify Plugin of Algolia (https://community.algolia.com/shopify/)

Our product relies heavily on the Shopify GraphQL API in order to index data in our search engine.

 

We are currently facing issues with the following query:

 

query resource_metafields($id: ID!) {
    product(id: $id) {
      metafield_0: metafield(namespace: "algolia", key: "grouping") {  key namespace value }
      metafield_1: metafield(namespace: "color_filters", key: "images") {  key namespace value }
      metafield_2: metafield(namespace: "multiwarehouse", key: "canonical") {  key namespace value }
      metafield_3: metafield(namespace: "translate", key: "en-CA") {  key namespace value }
  }
}

For product that have a value for metafield_0, the API is returning `null`

 

We have this bug impacting more than 50 customers right (over different and many metafields) and we had to rollback to the REST API.

I saw that a similar issue was raised on Collections recently: https://community.shopify.com/c/Shopify-APIs-SDKs/GraphQL-Cant-get-metafield-for-collection/td-p/556...

 

We plan to stop using `Product.metafield` and use `Product.metafields` instead, can you guarantee that we will not face the same issue by using the following query?

 

query resource_metafields($id: ID!) {
  product(id: $id) {
    metafields(first: 100) {
      edges {
        node {
          key
          namespace
          value
        }
      }
    }
  }
}

Thank you for your time!

0 Likes

Success.

Hello 
We have understand your query so for that please go throgh below link to get more details what is wrong:

https://help.shopify.com/en/api/guides/metafields/admin-api-metafields#retrieving-metafields

Want to modify or incorporate custom changes on store, Hire us.
If helpful then please Like and Accept Solution .
Email: pallavi@oscprofessionals.com
Skype : oscprofessionals-87
Custom Shopify Private App | Custom Theme Development | Custom Modifications In To Shopify Theme | Digital Marketing | Site Speed Optimization | Web Development
0 Likes
Shopify Staff
Shopify Staff
1113 77 153

Hello @charlypoly , 

 

Are you able to confirm if this issue is still ongoing? I just ran the following query and I was not able to replicate this : 

 

{
  product(id: "gid://shopify/Product/1969403592760") {
    metafield_0: metafield(namespace: "google", key: "test") {
      key
      namespace
      value
    }
    metafield_1: metafield(namespace: "testmetafield", key: "warehouse") {
      key
      namespace
      value
    }
  }
}
0 Likes
New Member
3 0 0

Hi @Josh ,

 

Thanks for replying.

 

In fact the issue was on our side, we were trying to get Variant metafields instead of Product metafields.

Sorry for the misunderstanding and thanks for the support!

 

Have a nice day,

0 Likes