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

Solved

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

charlypoly
Shopify Partner
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!

Accepted Solution (1)

oscprofessional
Shopify Partner
15950 2384 3093

This is an accepted solution.

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

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free

View solution in original post

Replies 3 (3)

oscprofessional
Shopify Partner
15950 2384 3093

This is an accepted solution.

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

Get pass your Store Core Web Vital Free Speed Optimization Audit, Chat on WhatsApp | Skype : oscprofessionals-87 | Email: pallavi@oscprofessionals.com | Hire us | Guaranteed Site Speed Optimization | Website Free Audit | Shopify Theme Customization | Build Shopify Private App | Shopify SEO | Digital Marketing | Oscp Upsell & Cross sell App : Free | Oscp Sales & Volume Discount App : Free | Custom Pricing Wholesale App : Free
Josh
Shopify Staff
1134 84 234

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
    }
  }
}

Josh | 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

charlypoly
Shopify Partner
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,