Get Metafields from Storefront Api unauthenticated_read_metafields

Hello maybe someone know how to sove this…

when i try to get a metafield data from Storefront GQL API got this error:

“Access denied for metafield field. Required access: unauthenticated_read_metafields access scope.”

since storefront api are tokenless i’ve no idea where to set that ‘access scope’

this is a very basic request:

query {
  product(id:"gid://shopify/Product/8795014037832"){
    id
    metafield(key:"product_care" namespace:"custom"){
        id
    }
  }
}

and this is the response:

{
    "errors": [
        {
            "message": "Access denied for metafield field. Required access: `unauthenticated_read_metafields` access scope.",
            "locations": [
                {
                    "line": 4,
                    "column": 5
                }
            ],
            "path": [
                "product",
                "metafield"
            ],
            "extensions": {
                "code": "ACCESS_DENIED",
                "documentation": "https://shopify.dev/api/usage/access-scopes",
                "requiredAccess": "`unauthenticated_read_metafields` access scope."
            }
        }
    ],
    "data": {
        "product": {
            "id": "gid://shopify/Product/8795014037832",
            "metafield": null
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 2
        }
    }
}

of course i’ve checked Shopify API access scopes
(even if it does have no sense for tokenless api)
and there is no unauthenticated_read_metafields option

plus querying the definition from the Admin GraphQL API i have PUBLIC_READ on storefront:

{
    "data": {
        "metafieldDefinition": {
            "key": "product_care",
            "namespace": "custom",
            "name": "product_care",
            "access": {
                "storefront": "PUBLIC_READ"  /*<=================*/
            }
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 2,
            "actualQueryCost": 2,
            "throttleStatus": {
                "maximumAvailable": 2000.0,
                "currentlyAvailable": 1998,
                "restoreRate": 100.0
            }
        }
    }
}

any ideas?
what i’m doing wrong?

The storefront API is both token-based & tokenless. For metafields/metaobjects, you do indeed require a token:

thanks a lot , you made my day,

storefront and admin have different header key,value

I only changed the value of the token but not the name

  • X-Shopify-Storefront-Access-Token (storefront)
  • X-Shopify-Access-Token (admin)

I’ve been looking for the error for over a week :man_facepalming:

1 Like

Feels good to figure that one out I bet! Good job, hah!