Ownership
Metafields and metaobjects can be owned by merchants or apps. Merchant owned metafields and metaobjects are open to merchants and developers, which means there are no restrictions on who can read, write, or modify them. However, you can use reserved namespaces to gain control over your application's data.
Anchor to Reserved prefixesReserved prefixes
There is a reserved prefix your app can prepend to metafield namespaces and metaobject types to take ownership of them. Using a reserved namespace ensures that your app exclusively controls all structure, data, permissions, and optional features.
Learn more about permissions.
Anchor to Create metafield definitions with reserved namespacesCreate metafield definitions with reserved namespaces
To establish metafield definitions within a reserved namespace, prefix the namespace with $app
. The API will automatically convert this to a fully qualified reserved namespace like app--{your-app-id}[--{optional-namespace}]
:
app
: Indicates that this is a reserved namespace for an app.{your-app-id}
: Your app's unique API client ID.{optional-namespace}
: An optional namespace of your choosing.
For example, if your app's API client ID is 123456
, you can create both:
$app
→app--123456
$app:influencer
→app--123456--influencer
All APIs default to using a reserved namespace $app
.
Example:
The following example creates a product metafield definition under a reserved namespace:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
JSON response
Anchor to Create metaobject definitions with reserved typesCreate metaobject definitions with reserved types
Similar to metafields, you can create metaobject definitions owned by your app by using the reserved prefix syntax for the metaobject type.
The following example creates a product highlight metaobject definition under a reserved namespace, while overriding the default permissions to grant the merchant read and write access:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
JSON response
Anchor to App-data metafieldsApp-data metafields
An app-data metafield is a metafield that is tied to a particular app installation and can only be accessed by that app. App-data metafields can't be overwritten by other apps or by merchants, and can be accessed using GraphQL. You can access app-data metafields using the metafields
property on the app
object in Liquid.
Using app-data metafields, you can provide different levels of features to users depending on their app payment plan by using app-data metafields and conditional app blocks. You can also store a client ID or client secret in app-data metafields.
The following steps demonstrate how to create and manage app-data metafields, which are metafields that are tied to a specific app installation. You'll learn how to securely store app-specific data that can't be modified by other apps or merchants.
Anchor to RequirementsRequirements
- Your app can make authenticated requests to the GraphQL Admin API.
Anchor to Step 1: Retrieve the app installation IDStep 1: Retrieve the app installation ID
First, use the currentAppInstallation
query to retrieve the ID of the AppInstallation
object associated with your app. In the next step, you'll use this ID to create a new app-data metafield.
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL query
Response
Anchor to Step 2: Create an app-data metafieldStep 2: Create an app-data metafield
To create an app-data metafield, use the metafieldSet
mutation, setting ownerID
to the app installation ID from the previous step:
POST https://{shop}.myshopify.com/api/{api_version}/graphql.json
GraphQL mutation
Variables
After you've created a metafield, you can access its value using the metafield
field on the AppInstallation
object.
Anchor to Next stepsNext steps
- Learn about defining metafields to create custom fields.
- Learn about managing metaobjects to create custom objects.
- Learn about permissions for your definitions.
- Use an app-data metafield to implement a conditional app block.