GraphQL access for MetafieldStorefrontVisibility - 403 Forbidden response

Solved
Highlighted
Shopify Partner
4 1 0

I'm attempting to use the GraphQL API to enable product metafields for Storefront API (GraphQL) access.


I've created a new private app. (It's not the first private app in the store.) The Products, variants and collections permission has been set to Read and write for the app.
API Access.png

I've attempted to create a MetafieldStorefrontVisibility record with both Insomnia and Shopify's GraphiQL private app, as explained in the Expose Metafields to the Storefront API article.

The Insomnia request is:


Endpoint:

https://my-store.myshopify.com/api/2020-01/graphql (POST)


Query:

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

Query Variables:

{	  
  "input": {
    "namespace": "fgcontent",
    "key": "short_description",
    "ownerType": "PRODUCT"
  }
}


Headers:

X-Shopify-Storefront-Access-Token: ****** (Admin API Password)
Accept: application/json
Content-Type: application/json

The response is `403 Forbidden`.

Any idea why I'm receiving a 403 Forbidden response?

0 Likes
Highlighted
Shopify Partner
4 1 0

This is an accepted solution.

I solved this problem by using the Shopify GraphiQL app. The install link is:
https://shopify-graphiql-app.shopifycloud.com/login

On the install page, be sure to select the appropriate permissions. You will need read and write permission for the products  scope AFAIK.

Screenshot_3.png

0 Likes
Highlighted
New Member
2 0 0

Hi! Is there anyway to expose customer metafields to the storefront API? I got it to work only for products.

 

Otherwise, how would you recommend creating, storing, and editing custom attributes for customers, e.g. birthday, school, loyalty points? 

0 Likes
Highlighted
Shopify Partner
4 1 0

> Hi! Is there anyway to expose customer metafields to the storefront API? I got it to work only for products.

I suspect the process is the same as for exposing product metafields. I haven't tried so cannot confirm either way. 

Have you created metafield storefront visibility records for the customer metafields you want to expose via the public Storefront API?

If you haven't, check out the docs here: 
https://shopify.dev/tutorials/retrieve-metafields-with-storefront-api#expose-metafields-to-the-store...


 

0 Likes