GraphQL API - Fetching Article Data

Hey team,

I’m trying to fetch the title of a store’s home page using the GraphQL Admin API, but I’m running into issues with the query structure. The title is set by the user in Online Store > Preferences.

I asked the AI dev assistant in the docs, it told me to do this:

query GetStoreSeoData {
  shop {
    name
    title
    description
  }
}

but I get this error: GraphqlQueryError: Field ‘title’ doesn’t exist on type ‘Shop’

The description works though!

I noticed that title is not listed as a field in the docs. shop - GraphQL Admin

Any ideas how I can get the title?

I’ve tried a few other options:

const homepageResponse = await admin.graphql(
          `query GetStoreSeoData {
            shop {
              id
              name
              onlineStore {
                name
                primaryDomain {
                  url
                }
                seo {
                  title
                  description
                }
              }
            }
          }`,
        );

I got this error: Field ‘onlineStore’ doesn’t exist on type ‘Shop’

`query GetSeoData {
            shop {
              onlineStore {
                seo {
                  title
                  description
                }
              }
            }
          }`,

GraphqlQueryError: Field ‘onlineStore’ doesn’t exist on type ‘Shop’

I tried accessing the data through shop metafields

const seoResponse = await admin.graphql(
          `query GetSeoData {
            shop {
              metafields(first: 10) {
                edges {
                  node {
                    namespace
                    key
                    value
                  }
                }
              }
            }
          }`,
        );

The query worked, but the title and meta description were not in the metafields.

I also tried accessing the data through the theme but this did not work.

Any ideas? This seems like a very basic query.

Hey @Limon

This is an interesting one. The title value isn’t currently something that can be queried directly but I did find a workaround to get it.

As this field is translatable, you can get it through the translatableResources object.

Here’s the query that’s working for me that will return the current meta_title and meta_description values:

query TranslatableResources {
    translatableResources(first: 2, resourceType: SHOP) {
        nodes {
            resourceId
            translatableContent {
                digest
                key
                locale
                type
                value
            }
        }
    }
}

Thanks so much @KyleG-Shopify! That worked!

I had to add read_translations as a scope to get this to work, but that should be fine.

A quick question about scopes… my app is asking for read_content, read_products, read_translations. But when I install the app, I see two additional fields under “View personal data” that I don’t request and never actually use in my app.

Is that standard for Shopify apps? I would like to remove those if possible so that I only have access to data that is used in the app. I feel like too many scopes could deter merchants that don’t want to expose their data unnecessarily.

Thanks again for your help.

Just testing here, when I deploy with no scopes, the minimum that is requested is the store owner:

The Content providers that you are seeing is coming from the read_content scope request.

Thanks @KyleG-Shopify

1 Like