New API_PERMISSION adding app metafields issue

Hello,

I’m trying to use the recently introduced graphql API_PERMISSION ownership type in order to create my app metafields which i can use in theme-extension snippets.

Unfortunately it returns me this error:

{
  "data": {
    "metafieldDefinitionCreate": {
      "createdDefinition": null,
      "userErrors": [
        {
          "field": [
            "definition",
            "ownerType"
          ],
          "message": "Owner type is not included in the list",
          "code": "INCLUSION"
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 990,
        "restoreRate": 50
      }
    }
  }
}

I dont understand what does “Owner type is not included in the list” means.

THank you.

Hello,

It seems you are using metafieldDefinitionCreate mutation. Instead, you will need to use metafieldSet mutation from Admin API 2022-04 or above in order to create app-owned metafields.

Here is an example:

mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafields) {
    metafields {
      # Metafield fields
    }
    userErrors {
      field
      message
    }
  }
}

Mutation variables could be for example

{
  "metafields": {
    "key": "feature1", 
    "namespace": "sample_app",
    "ownerId": "<App installation ID>",
    "type": "boolean",
    "value": "true"
  }
}

In order to get App Installation Id, you can use the following GraphQL query:

appInstallation {
   id
} 

I hope this helps,

Feken

3 Likes

Thank you Feken for directing me!

Def useful.

  1. I’m a bit confused and will be happy if you can direct me, so, whats the purpose of metafieldDefinitionCreate then?
  2. Also, is it possible to add APP metafields using your REST API too?

@sanjar yes you can create app meta use of REST too.

@Feken Thanks for the answer. it was really help out.

now i want to access the app meta field to the theme app extension. here my questions https://community.shopify.com/c/shopify-apis-and-sdks/want-to-access-the-app-meta-field-to-the-theme-app-extension/m-p/1723040

Hello, probably its hard to find in their docs, can you share a link pleasE?

I cant find any explanation here: https://shopify.dev/api/admin-rest/2022-07/resources/metafield#post-orders-order-id-metafields