App-data metafields can't store type "list.metaobject_reference"

Hey, I just wanted to check if this issue is on my end or if it’s simply not possible at all.

So, initially, I was able to easily create app-data metafields using the Shopify documentation. Everything worked fine when storing simple values like single_line_text_field, as shown in the docs.

The issue came up when I tried to store a metaobject instead. I attempted to assign the value of a metaobject definition ID, but as expected, that didn’t work. I got the following error:

Value requires that you have a metafield definition with the key: xxxx

After seeing that, I figured okay maybe I need to create a metafield definition first. I tried several things, but I wasn’t sure how this would work specifically with app-data metafields.

I attempted multiple times with different metafield definitions and tried assigning values to those metafields, but it didn’t work.

My main goal with all of this was to be able to use the {{ app.metafields }} Liquid syntax inside my theme extensions.

Any idea if what I’m trying to do is supported? Or am I missing something?

1 Like

Hey @Umit_Demir :waving_hand: Could you share the exact mutation you’re using to create the app-data metafield when the “value requires…” message pops up?

I’m just wondering what type of value type you’re using there. Are you storing the metaobject definition ID as a single_line_text_field or another value?

Usually that error message pops up when a metafield can’t be found (usually because it was deleted or is inaccessible to the app making the request) - hope to hear back from you soon, happy to dig into this further for sure!

Hi @Alan_G thank you for your replay,

These are my mutations.

mutation CreateAppDataMetafield($metafieldsSetInput: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafieldsSetInput) {
    metafields {
      id
      namespace
      key
    }
    userErrors {
      field
      message
    }
  }
}

{
  "metafieldsSetInput": [
    {
      "namespace": "secret_keys",
      "key": "api_key",
      "type": "list.metaobject_reference",
      "value": "[\"gid://shopify/Metaobject/158811193691\"]",
      "ownerId": "gid://shopify/AppInstallation/861391487323"
    }
  ]
}

From this mutation I get this response

{
  "data": {
    "metafieldsSet": {
      "metafields": [],
      "userErrors": [
        {
          "field": [
            "metafields",
            "0",
            "value"
          ],
          "message": "Value requires that you have a metafield definition with the key: api_key."
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1990,
        "restoreRate": 100
      }
    }
  }
}

After because I saw the Value requires that you have a metafield definition with the key: api_key. error. I decided to create the metafield definition. Using this query.

mutation {
  metafieldDefinitionCreate(definition: {
    name: "Test"
    namespace: "secret_keys"
    key: "api_key"
    type: "list.metaobject_reference"
    ownerType: SHOP
    validations: {
      name: "metaobject_definition_id"
      value: "gid://shopify/MetaobjectDefinition/21219836251"
    }
  }) {
    createdDefinition {
      id
      name
      namespace
      key
    }
    userErrors {
      field
      message
      code
    }
  }
}

From this mutation I got the answer

{
  "data": {
    "metafieldDefinitionCreate": {
      "createdDefinition": {
        "id": "gid://shopify/MetafieldDefinition/270440890715",
        "name": "Test",
        "namespace": "secret_keys",
        "key": "api_key"
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1990,
        "restoreRate": 100
      }
    }
  }
}

Also here I create the metaobject with this query.

mutation {
  metaobjectCreate(
    metaobject: {
      type: "your_test_app_dataaadddsss"
      fields: [
        {
          key: "value"
          value: "111111111111"
        }
      ]
    }
  ) {
    metaobject {
      id
      definition {
        id
      }
    }
    userErrors {
      field
      message
    }
  }
}

{
  "data": {
    "metaobjectCreate": {
      "metaobject": {
        "id": "gid://shopify/Metaobject/158811193691",
        "definition": {
          "id": "gid://shopify/MetaobjectDefinition/21219836251"
        }
      },
      "userErrors": []
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 11,
      "actualQueryCost": 11,
      "throttleStatus": {
        "maximumAvailable": 2000,
        "currentlyAvailable": 1989,
        "restoreRate": 100
      }
    }
  }
}

After I run the app-data mutation query I shared initially. It still gives me the same error. As I started using the API recently I am not sure if I am making basic mistake. Thank you for your help.

Hey @Umit_Demir!

Currently, App-data metafields aren’t tied to metafield definitions, so only certain data types are permitted. The list.metaobject_reference type requires validation to which means it needs a predefined metafield definition to work properly (as demonstrated in the error you received).

App data metafields are accessed on the app installation object, but the app installation isn’t an ownertype that can be used so you can’t create a definition for these metafields.

That leaves a couple of options:

First, you can stick with simpler types like single_line_text_field and store the metaobject GID as a string value (like "gid://shopify/Metaobject/158811193691"), then parse it in your app code.

Second, if you really need the structured list.metaobject_reference functionality, you can create metafield definitions using your app’s reserved namespaces, which gives you full control over the definition and validation rules.

Check out the supported types documentation for app-data metafields and the reserved namespaces guide for the definition approach.

2 Likes