I am working on building an app which creates custom metaobject definition and objects using the Admin API / GraphQL. I cannot figure out how to access it from my Theme App Extension / Embed? From the documentation (The Documentation), it seemed like I should be able to add the storefront access as seen below in the definition.
I verified via my API that I can create/edit/retrieve objects, and that they are set to published status ‘ACTIVE’.
"{{ app.metafields.XXXX__METAOBJ_DEF_TYPE__XXXX.XXXX__KEY_NAME__XXXX.value | json }}",
"{{ app.metafields.XXXX__METAOBJ_DEF_TYPE__XXXX.XXXX__KEY_NAME__XXXX}}",
"{{ app.metafields.XXXX__METAOBJ_DEF_TYPE__XXXX.XXXX__KEY_NAME__XXXX.value }}",
"{{ app.metafields.XXXX__METAOBJ_DEF_TYPE__XXXX.XXXX__KEY_NAME__XXXX | json }}"
/**
** Note: I am NOT including the "$app:" prefix
** or the "app-123456" prefix to any of the types above
**/
We manage multiple custom apps and needed a more automated solution. We haven’t found a simpler solution -there might be one-, so this is what we did:
Resolve your owned metafield namespace by querying the “currentAppInstallation” with the admin API:
query currentAppInstallation {
currentAppInstallation {
id # This will be used to set a metafield in a later mutation
app {
id # This is your app ID, that is part of the resolved namespace
}
}
}
then, the namespace will be **app--{currentAppInstallation.app.id}--{your-namespace}**.
Store it in a metafield in the currentAppInstallation:
mutation CreateAppDataMetafield($metafieldsSetInput: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafieldsSetInput) {
metafields {
id
namespace
key
value
}
userErrors {
field
message
}
}
}