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, similar to private metafields. Unlike private metafields, 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.
This guide shows you how to create an app-data metafield using the GraphQL Admin API.
RequirementsAnchor link to section titled "Requirements"
- Your app can make authenticated requests to the GraphQL Admin API.
Step 1: Retrieve the app installation IDAnchor link to section titled "Step 1: Retrieve the app installation ID"
currentAppInstallation query to retrieve the ID of the
AppInstallation object associated with the app. You'll use this ID to create an app-data metafield in the next step.
Step 2: Create an app-data metafieldAnchor link to section titled "Step 2: Create an app-data metafield"
To create an app-data metafield, use the
metafieldSet mutation and set the
ownerID to the app installation ID that you retrieved in the previous step:
After you've created an app-data metafield, you can access its value using the
metafield field on the
- Use an app-data metafield to implement a conditional app block.