What's your biggest current challenge? Have your say in Community Polls along the right column.

Why can't I view my app-data metafields with graphql?

Why can't I view my app-data metafields with graphql?

wil_dev
Shopify Partner
12 0 2

Hi there,

I can't see my app-data metafields if I use graphql

but I CAN see it on my app embed block... with  = > {{app.metafields.super_cart_metafields.div.value}}

/// CREATING MY METAFIELD, IT WORK
const response = await admin.graphql(
      `#graphql
      mutation CreateAppDataMetafield($metafieldsSetInput: [MetafieldsSetInput!]!) {
        metafieldsSet(metafields: $metafieldsSetInput) {
          metafields {
            id
            namespace
            key
          }
          userErrors {
            field
            message
          }
        }
      }`,
      {
        variables: {
          metafieldsSetInput: {
            namespace: "super_cart_metafields",
            key: "div",
            type: "single_line_text_field",
            value: "F",
            ownerId: id
          }
      }}
    )
///// RETRIEVE MY METAFIELD, IT DOESNT WORK
const responseData = await admin.graphql(
    `#graphql
    query divContent($id: ID!, $namespace: String!, $key: String!) {
      appInstallation(id : $id) {
        apiKey: metafield (namespace : $namespace, key: $key){
          value
        }
      }
    }
    `,
    {variables: {
      id: id,
      namespace : "super_cart_metafields",
      key: 'div'
    }
  }

And if I use the graphql app on shopify, 0 results...
I read the documentation, but it doesn't work...
https://shopify.dev/docs/api/admin-graphql/2023-10/queries/appInstallation#examples-Get_a_metafield_...

Replies 2 (2)

EasifyApps
Shopify Partner
635 19 48

Hi @wil_dev,

To add text fields effortlessly, you can consider utilizing the Easify Product Options app—it's free and eliminates the necessity for metafields and custom coding 🤗.

 

EasifyApps_0-1701661716264.pngEasifyApps_1-1701661737902.png

 

Easify Product Options: Any product options app can help you create custom options, but Easify turns those options into sales and conversions!
Easify Inventory Sync: Automate inventory syncing for Bundles, Duplicates, and Raw Materials. Say goodbye to manual tracking headaches.
Easify Product Attachments: Enrich your store with downloadable content. Easily add PDFs and other files to product or any page.
>>> Try Apps for Free | 24/7 Live Chat Support
wil_dev
Shopify Partner
12 0 2

Hi thank you for your response, but it's not what I search...
I need to see my app metafields that I have created with a graphQl request. I create the metafield, but impossible to see it with a request, my request is ok, anyone had the same problem?