shopifyshopify-appshopify-api-node

How to call app owned metafields in shopify extension function run graphql?


---- run.graphql ----
query RunInput {
  cart {
    lines {
      id
    }
  }

  appInstallation(id: "gid://shopify/AppInstallation/73424761***") {
    metafield(namespace: "attributes9", key: "attributes9") {
      value
    }
  }
}

I'm attempting to access app-owned metafields within a Shopify extension function, but I'm encountering the following error:

Error 0: 
Cannot query field "appInstallation" on type "Input".

Solution

  • The error occurs because appInstallation cannot be queried within RunInput or alongside cart.
    To fix this, you should directly query appInstallation without nesting it under RunInput.

    Here's the corrected query to retrieve your app-owned metafield:

    query {  
      appInstallation(id: "gid://shopify/AppInstallation/73424761***") {
        metafield(namespace: "attributes9", key: "attributes9") {
          value
        }
      }
    }
    

    This query will correctly retrieve the attributes9 metafield from the specified namespace.

    Additionally, if you want to retrieve all metafields owned by the app, you can use this query:

    query {
      appInstallation(id: "gid://shopify/AppInstallation/73424761***") { 
        metafields(first: 50) {
          edges {
            node {
              namespace
              key
              value
            }
          }
        }
      }
    }