Re: Metafield definition and access settings, this is a big problem

Solved

Metafield definition and access settings, this is a big problem

Next_Cart
Shopify Partner
3 0 8

We are migrating products from our client's online store to Shopify using the latest API version 2023-10. The product attributes are migrated as metafields, and we just noticed a serious problem with metafield definition and access settings since the API version 2023-01 to 2023-10.

 

There are some issues/limitations:

  • The namespace is required to be the app reserved namespaces. You cannot create a metafield definition in a custom namespace without the app reserved prefix, this is the error: "Setting access controls on a definition under this namespace is not permitted".
  • The store owner cannot change the metafield definitions once they are imported. You can only delete the metafield definitions through the app you used to import them, but this will not work with custom apps.
  • The access "MERCHANT_READ_WRITE" is the only setting you can use if you want to be able to view and edit the metafields via admin. This leads to a problem: one year later, if the store owner wants to use another app to interact with the metafields, or copy data to another store, you'll need to go back and grant access to that app. But, this becomes impossible if the metafield definitions were imported via a custom app and that custom app was removed for some reason.

Shopify developers, e-merchants, web agencies and developers should take note of thess issues. I hope you will find out a comprehensive solution.

Accepted Solution (1)

JohnBerry
Shopify Staff
8 4 7

This is an accepted solution.

Hello,

 

You should be able to create a metafield definition in a non app reserved namespace (e.g. "custom") as long as you are not setting a value for the access input. If you do not use a reserved namespace, the merchant and other apps should be able to edit the definition and set metafield values.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 17 (17)

JohnBerry
Shopify Staff
8 4 7

This is an accepted solution.

Hello,

 

You should be able to create a metafield definition in a non app reserved namespace (e.g. "custom") as long as you are not setting a value for the access input. If you do not use a reserved namespace, the merchant and other apps should be able to edit the definition and set metafield values.

To learn more visit the Shopify Help Center or the Community Blog.

homerjam
Shopify Partner
1 0 1

How should I go about creating a definition in a "custom" namespace with storefront access??

 

EDIT/UPDATE:

 

So it seems that creating the namespace with "$app:custom" is the answer

JohnBerry
Shopify Staff
8 4 7

That is correct. Prefixing a namespace with "$app:" produces a metafield definition in a reserved namespace that is owned by the app that created it. The owning app has full control over the definition including the definition's admin and storefront access settings.

 

Apps can also create non-reserved namespace metafields (e.g. "custom") but cannot set storefront or admin access. In the 2024-01 API release and beyond, storefront access for non-reserved namespace metafields can only be set from within the Admin.

To learn more visit the Shopify Help Center or the Community Blog.

m4rc
Shopify Partner
2 0 5

@JohnBerry 

Do you know we will be able to create non-reserved namespace metafields for any owner type?

 

I would like to create a shop metafield as a non-reserved namespace metafields, but it seems like there's no way to currently define it from the Shopify Admin.

JohnBerry
Shopify Staff
8 4 7

Shop metafields can be created using the metafieldDefinitionCreate Admin API mutation with an ownerType = SHOP.

 

Shop metafields cannot be created through the Admin interface.

To learn more visit the Shopify Help Center or the Community Blog.

sebizox
Shopify Partner
6 0 3

Within an app, I attempted to create a metafield definition with the following settings:

metafieldDefinitionCreate(definition: {
  name: "Custom Test",
  namespace: "customtest",
  key: "config",
  type: "json",
  ownerType: SHOP
  access: {
    admin: MERCHANT_READ_WRITE
    storefront: PUBLIC_READ
  }
}) {
  createdDefinition {
    id
  }
}

I launch shopify's graphiql app and can successfully fetch the metafield value using the admin API endpoint. When I switch it to Storefront, i get a null value instead. Does this not work on metafields where the SHOP is the ownerType? When I set a metafield value, i used the shopid for the `ownerId`, but we're still having issues accessing this via Storefront.

We were deploying our app to another store within our plus plan to attempt to set up a staging site, but we're unable to deploy due to this inconvenience. We're assuming the metafield we have on the SHOP owner type is grandfathered in or added a long time ago before the metafield storefront visibility mutation was deprecated. Any insights you can provide?
 
I must also mention, that we tried without the `access` input, and we yield the same result.
newbie_01
Shopify Partner
34 0 13

Hi. Is there a way to access a product image metafield from the storefront api and liquid?

I defined it with [storefront] => PUBLIC_READ access, but I can't find any query to access it.  

The image object in the back end include metafields, but not the one in the front end.

Thanks

SPEAZ
Shopify Partner
31 3 18

Hi 🙂

 

The issue is now : by default storefront access is set to "LEGACY_LIQUID_ONLY" instead of "PUBLIC_READ"

and there is no way to update access of no-owned metafields.

 

The default value should be set to "PUBLIC_READ" by default like metafieldStorefrontVisibilityCreate did it  ?

 

Otherwise metafields will not be accessible by the storefront api unless merchant is going trough admin to change itself to "Read" which is adding more steps than before.

 

Thank you

 

Next_Cart
Shopify Partner
3 0 8

A non app reserved namespace with no access input is the best solution 👍.

*Note: if anyone is trying this solution, remember to use the API stable versions, as it doesn't work with the "Unstable" versions.

Thank you so much, John!

SPEAZ
Shopify Partner
31 3 18

Yes but by default storefront access is set to "LEGACY_LIQUID_ONLY" instead of "PUBLIC_READ" 

Metafields will not be accessible by the Storefront API unless merchant is going trough admin to change itself to "Read" which is adding more steps than before.

did you figured out a solution ?

 

 

tuzmusic
Shopify Partner
5 0 0

A big +1 on this. The solution "with no access input" is not a solution if the result doesn't allow the access needed. We are also having problems where creating a metafield via our script results in a metafield with no storefront access and we have to remember to change it manually each time we create something which creates a lot of confusion in the time it takes an engineer to remember to make this manual change.

Teetoy
Shopify Partner
1 0 0

hello

JohnBerry
Shopify Staff
8 4 7

UPDATE:

It is now possible to manage access (including storefront access) for merchant / non-reserved namespace metafields. More details can be found here.

To learn more visit the Shopify Help Center or the Community Blog.

SoumenDana
Shopify Partner
1 0 0

Issue with Creating a New Metafield in Shopify via Storefront API.

I am encountering an issue while creating a new metafield in Shopify using the Storefront API.
Specifically, the Storefronts access for the newly created metafield is being set to No Access by default.

Current Implementation:
'metafield_definitions' => [
MetafieldOwnerType::COLLECTION->value => [
[
'description' => "Name for the new field",
'key' => 'field_key',
'name' => 'field_name',
'namespace' => 'namespace',
'ownerType' => COLLECTION,
'type' => [
'name' => MetafieldType::SINGLE_LINE_TEXT_FIELD->value,
],
],
]
]

When I try adding the access attribute like this:

'access' => [
'admin' => 'PUBLIC_READ_WRITE',
'storefront' => 'PUBLIC_READ',
]
I get the following error:
Could not create a MetafieldDefinition in Shopify: Cannot create MetafieldDefinitionInput since access values require a reserved namespace ($app:) [code 0].

Attempted Fix:
To address the namespace issue, I updated the namespace to use the reserved format: 'namespace' => '$app:namespace',
This resolved the namespace-related error, but I now encounter a new error.
Error: Could not create a MetafieldDefinition in Shopify: Cannot create MetafieldAccessInput due to missing attributes [code 0].
When trying to include unauthenticated access its still same 😞

'access' => [
'admin' => 'PUBLIC_READ_WRITE',
'storefront' => 'PUBLIC_READ',
'unauthenticated' => 'PUBLIC_READ',
]

Question:
Is it possible to set storefront and unauthenticated access levels for metafields created via the Storefront API?
Am I missing any required attributes or misusing the access property in my request?
Any guidance or clarification on this issue would be greatly appreciated.

Thank you!

tuzmusic
Shopify Partner
5 0 0

@SoumenDana do we need “unauthenticated” or is that just something you were trying? (Note: Soumen is my colleague in this project)

JohnBerry
Shopify Staff
8 4 7

@SoumenDana it is not possible to create metafield definitions via the Storefront API. Metafield definitions can only be created via the Admin API.

 

If you would like to create a definition in a merchant namespace with storefront access, you need to use API version 2025-01 or later and should set:
access: {

  storefront: "PUBLIC_READ"
}

 

Please see MetafieldAccessInput for more details.

 

 

To learn more visit the Shopify Help Center or the Community Blog.

tuzmusic
Shopify Partner
5 0 0

Thank you @JohnBerry! I think Soumen and I can follow up offline.