Solved

API to fetch product SEO

stormindia
Tourist
5 1 2

I am filtering my products based on tags. I also want to include product's SEO description in that.  
Screenshot (37)_LI.jpg

The description that I get from GraphQL query is the entire description that is listed on the full page of the product. 

Using 

Below is my QUERY -> 

 

graphQLquery11 = """ {

  products(first:1, query:"tag:[%s, %s]") {
    edges {
      node {
        id
        title
        description
        seo {
      description
      title
    }
        metafields(first:100){
          edges
            {
              node{
                namespace
                key
                value
              }
            }
          
        }
        onlineStoreUrl
      }
    }
  }
}"""%('0-12', 'physical')

 

 

This gives me an error 

 

Field 'seo' doesn't exist on type 'Product'

 

 

If I remove SEO node from the query and run only metafields I receive this for metafield

 

"metafields": {"edges": []}

 

 

Is there any way to fetch the SEO while fetching the products?
Here is what I want to do illustrated in liqiud - https://shopify.dev/docs/themes/liquid/reference/objects/page-description
But I can not find any such reference for GraphQL

Accepted Solution (1)

stormindia
Tourist
5 1 2

This is an accepted solution.

Resolved the issue on my own 
Here is the Updated QUERY
Also keep in mind that I have to use ADMIN API for this(to get metafields)

 

graphQLquery11 = """ {
  products(first:1, query:"tag:[%s, %s]") {
    edges {
      node {
        id
        title
        description
        onlineStoreUrl
        metafields(first:1)
          {
            edges{
              node{
                value
              }
            }
           
          }
        
      }
    }
  }
}"""%('0-12', 'physical')

 

View solution in original post

Replies 4 (4)

KarlOffenberger
Shopify Partner
1873 184 900

Hi there!

The query mostly works but I had to change your product query to be:

products(first:1, query:"tag:%s AND tag:%s")

 

Give that a try and let me know if it works for you too.

stormindia
Tourist
5 1 2

The issue actually was that I was using URL for STOREFRONT API and not ADMIN API which is why both 'seo' tag and 'metafield' tag were not working. Fixed that

fttdDev
Visitor
1 0 1

Is it possible to use on gatsbyjs?

Here is the graphql by gatsby + shopify integration.

fttdDev_0-1618304969701.png

 

stormindia
Tourist
5 1 2

This is an accepted solution.

Resolved the issue on my own 
Here is the Updated QUERY
Also keep in mind that I have to use ADMIN API for this(to get metafields)

 

graphQLquery11 = """ {
  products(first:1, query:"tag:[%s, %s]") {
    edges {
      node {
        id
        title
        description
        onlineStoreUrl
        metafields(first:1)
          {
            edges{
              node{
                value
              }
            }
           
          }
        
      }
    }
  }
}"""%('0-12', 'physical')