Metafield Storefront Visibility Record

Solved

Metafield Storefront Visibility Record

WebEnvy
Tourist
6 0 0

Hey Team!

 

Just wondering if anyone can help me with this as I have followed the documentation here:
https://help.shopify.com/en/api/guides/metafields/storefront-api-metafields#expose-metafields-to-the...
and have had no luck. 

 

I am building a storefront using Vue.js and am trying to expose the metafields created by the 'Custom Fields' App to the API

Using the 'Shopify GraphiQL App' in the SHopify admin area I have input the following:

mutation ($input: MetafieldStorefrontVisibilityInput!) {
  metafieldStorefrontVisibilityCreate(input: $input) {
    metafieldStorefrontVisibility {
      id
    }
    userErrors {
      field
      message
    }
  }
}

with the following Query Vars:

{
  "input": {
    "namespace": "custom_fields",
    "key": "suits",
    "ownerType": "PRODUCT"
  }
}

The error message I get is: "The access token provided does not have access to the supplied ownerType."

While I'm new to the GraphQL (and Shopify) the documentation on the page provided doesn't mention needing to auth using the Admin App.  

 

Any help pointing in the right direction would be appreciated. 

 

Accepted Solution (1)
Nesters
Shopify Partner
19 1 19

This is an accepted solution.

I haven't used Shopify's GraphiQL app in a while so I'm not entirely sure how it's set up.

It seems that you don't have the write access for your credentials that are associated with the Shopify's GraphiQL app.

 

Check your app's access scopes under "Manage private apps" in the Apps section of the Admin.

You can also download Graphiql as standalone app and set up your private app credentials that way.

Remember to set up write access for appropriate access scopes.

 

 

Contact me: mail@nesters.me
Technical solutions / integration / headless ecommerce.
Latest post: Benefits of JAMstack ecommerce

View solution in original post

Replies 16 (16)

Nesters
Shopify Partner
19 1 19

I'm slightly confused about your case.

 

Is there any chance you are trying to use Storefront API token to update metafield visibility?

Because the queries provided in the example are meant for GraphQL Admin API so you need the Admin API token.

Contact me: mail@nesters.me
Technical solutions / integration / headless ecommerce.
Latest post: Benefits of JAMstack ecommerce
WebEnvy
Tourist
6 0 0

Thanks for the reply @Nesters 

So, as i am understanding it.. (which is obviously wrong) 

To expose the Metafields to the API, I need to 'Whitelist' them using the GraphQL Admin API
The link below recommends using 'Shopify’s own GraphiQL app' (which I have installed). 
https://help.shopify.com/en/api/graphql-admin-api/getting-started#make-your-first-call-to-the-graphq...

 

Now following the information on this page:
https://help.shopify.com/en/api/guides/metafields/storefront-api-metafields#expose-metafields-to-the...

It says to use the GraphQL Admin API (which is: 'Shopify’s own GraphiQL app') to 'Expose the metafields' 

This now leads to my original post... I can read the data using the 'GraphiQL app' fine, but I get the auth error when following the 'Expose metafields to the Storefront API' documentation. 

Nesters
Shopify Partner
19 1 19

This is an accepted solution.

I haven't used Shopify's GraphiQL app in a while so I'm not entirely sure how it's set up.

It seems that you don't have the write access for your credentials that are associated with the Shopify's GraphiQL app.

 

Check your app's access scopes under "Manage private apps" in the Apps section of the Admin.

You can also download Graphiql as standalone app and set up your private app credentials that way.

Remember to set up write access for appropriate access scopes.

 

 

Contact me: mail@nesters.me
Technical solutions / integration / headless ecommerce.
Latest post: Benefits of JAMstack ecommerce
WebEnvy
Tourist
6 0 0

@Nesters Thanks dude!
Ok so. for reference I had all the permissions which had 'GraphQL' in the name enabled to 'read and write' and was still getting the issue. 
So, I went ahead and just gave read/write to a bunch more and it worked for some reason. Once I find the exact ones I'll post it here for anyone else with the same issue. 

I had to use the Mac App 'GraphiQL' to do the query so I could include the token. the App int he Shopify Admin area kept giving me the access issue. 
For anyone using the APP your GraphQL Endpoint should be:
https://<INSERT SHOP NAME>.myshopify.com/admin/api/2019-07/graphql.json?access_token=<INSERT YOUR TOKEN HERE> 

SBD_
Shopify Staff
1831 273 419

Hey @WebEnvy,

Since you're exposing a product metafield, the permission Products, variants and collections will need to be set to read and write.

 

Scott

Scott | Developer Advocate @ Shopify 

WebEnvy
Tourist
6 0 0

Thanks @SBD_ 🙂
Ok so now I have successfully ( I think ) managed to 'Expose' the Metafields do I have to do additional queries to retrieve them?
I have added the query vars for each field in the GraphiQL App (crazy you just can't expose all keys for a certain namespace) and have the response gid for each like so: gid://shopify/MetafieldStorefrontVisibility/xxxxxxx

If I am doing a query in the BUY SDK like:

client.product.fetch(productId).then((product) => {
  // Do something with the product
  console.log(product);
});

Should the metafields be visible within 'product' ?
like product.metafields.{namespace}.{key}

SBD_
Shopify Staff
1831 273 419

You'll need to build a custom query to retrieve them, there's some example code here.

 

Alternatively, you can query the Storefront API directly.

Scott | Developer Advocate @ Shopify 

WebEnvy
Tourist
6 0 0

@SBD_ YAAASSS!!!! They are finally coming through. Thank you for that example. Now the only bad part about this is having to 'add' every field to that query again (unless there is a fast way other than doing like 50 add('availableForSale'), add('createdAt')  etc etc? ).
but hey... the fields are coming through so thats a start! 

 

I had tried the direct query but I kept getting a Cross Domain issue. 

Karl1
Shopify Partner
6 0 5

Hey friend, did you figure out which permission was responsible? I have the same issue.

 

I've tried Shopify GraphQL App and I'm trying to expose product meta title & description:

 

mutation($input: MetafieldStorefrontVisibilityInput!) {
  metafieldStorefrontVisibilityCreate(
    input: $input
  ) {
    metafieldStorefrontVisibility {
      id
    }
    userErrors {
      field
      message
    }
  }
}
{
	"customerAccessToken":"MyAdminAPIKey",
  "input": {
    "namespace": "global",
    "key": "title_tag",
    "ownerType": "PRODUCT"
  }
}

and I keep getting 

{
  "data": {
    "metafieldStorefrontVisibilityCreate": null
  },
  "errors": [
    {
      "message": "The access token provided does not have access to the supplied ownerType.",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "metafieldStorefrontVisibilityCreate"
      ]
    }
  ],
  "extensions"...

even with all Admin API permissions enabled.  Any help greatly appreciated. Thanks.

Another thing that is unclear to me is in the query variable, should I use "customerAccessToken", "shopifyAccessToken" or "storefrontAccessToken"?

Xylon_Gracias
Shopify Partner
4 0 0

Even I am having this same issue

nktkarnany
Visitor
1 0 0

I am facing the same issue right now with the only difference being the ownerType: "COLLECTION" and I'm getting the same error. Did you manage to solve it? If not, can someone help, please?

Karl1
Shopify Partner
6 0 5
I never solved it, it just would not work
JualGeotextile
Visitor
2 0 0

Is there any chance you are trying to use Storefront API token to update metafield visibility?

 

Thanks

Pen Jual Geomembrane HDPE

a5okol
Tourist
3 0 1

Perhaps it will help someone. Try reinstalling Shopify Graphql App by selecting all checkboxes. It helped me.

https://shopify-graphiql-app.shopifycloud.com/

joshbedo
Tourist
10 0 3

It seems retarded and not very intuitive that we dont get product metafields back unless jumping through hoops. Why would we ever not want all product metafields.. exactly. I see people adding mutations and graphql queries to change visibility but how does this work with Hydrogen's <Product.Metafield> component... realizing none of my custom metafields are pulling in.

borealisstu
Visitor
1 0 0

This thread helped me figure out how to expose the metafields for use in gatsby-source-shopify. Thank you!