Metafield Storefront Visibility Record

Solved
Highlighted

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. 

 

0 Likes
Shopify Partner
6 1 14

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
0 Likes

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. 

0 Likes

Success.

Shopify Partner
6 1 14

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
1 Like

@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> 

0 Likes
Shopify Staff
Shopify Staff
44 5 11

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

1 Like

Thanks @greatscott :-)
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}

0 Likes
Shopify Staff
Shopify Staff
44 5 11

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.

1 Like

@greatscott 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. 

0 Likes