Product admin api request including metafields from shopify app using shopify_app gem

Product admin api request including metafields from shopify app using shopify_app gem

jwilson114
Shopify Partner
3 0 0

Hi there. I'm doing an API request to the product resource and including the metafields in the field param but they are not being returned. Metafields are included in the webhook data, so you would think they would be included in the API response.

 

ShopifyAPI::Product.find(:all, params: { limit: 250, fields: 'id, status, title, body_html, handle, vendor, options, images, tags, published_at, admin_graphql_api_id, variants, metafields' })

 

Does anyone know if they can be returned? Seems bad if they cant be.

Reply 1 (1)

Alan
Shopify Staff
129 15 24

Hey @jwilson114 - you should be able to return metafields attached to the Product Object in GraphQL using something like the query below:

{
  products (first:10) {
    edges {
      node {
        id
        metafields (first:5) {
          edges {
            node {
              id
              namespace
            }
          }
        }
      }
    }
  }
}

 

 

Would you be able to share the response you're logging on your end from us? If you could supply an X Request ID from the response header that would be great as well. This would allow us to trace back the initial call in our logs to find out why metafields aren't surfacing. One thing I have seen is that depending on the product, it may not have metafields associated with it, and this could cause what you're seeing. It's not a required value for a product to have associated metafields, but it is definitely odd that they're not surfacing on your end.
 
Hope to hear from you soon so we can dig into this further.

 

Alan | API Support @ 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 Shopify.dev or the Shopify Web Design and Development Blog