How do I access the same metafield from Checkout and Customer Account extensions?

Since according to the documentation, we cannot access reserved-namespace metafields from a Checkout UI extension and we can not use a namespace that’s not owned by the app in the Customer Account extension (since we can’t change its customerAccount access propery), as far as I can tell there is no way to use one metafield in both types of extensions. Is there any way to do this? Or if not, what is the reason behind this design decision?

Thanks for the help.

Which is the owner of these metafields?

I’m able to retrieve access reserved-namespace shop metafields from the customer account ui extension by using the customer account API

That’s a query I’m using to retrieve a reserved-namespace metafield owned by the shop:

query {
  shop {
    metafield(namespace: "$app:forms", key: "account") {
      id
      namespace
      key
      value
    }
  }
}

Also, why cannot you change the customerAccount access property? You have to change it from the metafield definition

Hi, the lack of support for app-reserved namespaces via Checkout UI extensions is a known issue and is currently being worked on.

In the meantime, the only way to access metafields on both surfaces is to create them outside of the app-reserved namespace (e.g. not prefixed with $app) and ensuring that both surfaces have the proper permissions to access them.

I’m able to retrieve access reserved-namespace shop metafields from the customer account ui extension by using the customer account API

Yes, using the Customer Account API, I’m also able to access reserved-namespace metafields, however not, using the Storefront API. I am trying to get the Customer resource metafields, so the code you showed won’t work (using the Storefront API we need to specify the customerAccessToken for the customer query, which as far as I know is not possible to get from a Checkout extension).

Also, why cannot you change the customerAccount access property? You have to change it from the metafield definition

When I try to change the access property of a regular (not reserved-namespace) metafield, I get the error described in this post (Setting access controls on a definition under this namespace is not permitted) and I’m not sure how to resolve that.

In the meantime, the only way to access metafields on both surfaces is to create them outside of the app-reserved namespace (e.g. not prefixed with $app ) and ensuring that both surfaces have the proper permissions to access them.

Does that mean that I can change the access of a metafield that have a namespace not starting with $app? When I tried that I got the error described in this post (Setting access controls on a definition under this namespace is not permitted). Can you advise me on what I’m doing wrong?

I believe that you should be able to specify Storefront API and Customer Account API access (see here). They can also be adjusted via the Admin UI.

I’m not sure how to do that since when I’m trying to specify the access in the metafieldDefinitionCreate or metafieldDefinitionUpdate, then I get the error I mentioned. This is my full mutation:

mutation MetafieldDefinitionUpdateMutation {
  metafieldDefinitionUpdate(
    definition: {
      namespace: "loyalty_program",
      key: "points",
      ownerType: CUSTOMER,
      access: { admin: PUBLIC_READ, customerAccount: READ }
    }
  ) {
    userErrors { field, message }
  }
}

Then the error is:

Setting access controls on a definition under this namespace is not permitted.

Can you check if it works with admin: PUBLIC_READ_WRITE? I wonder if there may be an undocumented restriction on the allowable values.

I’m getting the same error with PUBLIC_READ_WRITE for the admin access. Does it work on your side?

You can edit the permissions from the admin:

By default the admin access is set on PUBLIC_READ_WRITE, but you can edit che storefront and customer account access properties from here

Thank you for your reply. However, this is not a suitable solution for us, since we cannot require every merchant to change the access permissions after they installed the app. Is there no way to do this via the Admin API?

We have the same problem. Our current solution (and I think it is the only one) is to force the merchant to put the customer account access to Read and write

As you said, it is not possible to set these properties using the GraphQL admin API unless the metafield definition namespace is the app reserved one $app:<some namespace>

I spent a bit of time looking into this and it looks like changing those access controls on a metafield in the custom namespace is not possible for 3rd party clients. I believe this was done intentionally to push apps towards using app-reserved namespaces.

Unfortunately, as you pointed out, this is a problem since checkout extensions don’t presently have access to the app-reserved namespaces.

I know that this is something that is being actively worked on, but unfortunately for the time being, the only workaround is for the merchant to update access controls via Admin.

+1 This is the only way we’ve found to be able to change the access settings for non app reserved metafields. We can detect if metafields being used in the app don’t have the correct access and display a warning for the merchant to update, but the app cannot do so automatically.