Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: New API_PERMISSION adding app metafields issue

Solved

New API_PERMISSION adding app metafields issue

sanjar
Shopify Partner
21 1 2

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
      }
    }
  }
}

 

 

sanjar_0-1651783626076.png

 

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

THank you. 

Accepted Solution (1)

Feken
Shopify Staff
1 1 3

This is an accepted solution.

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

Feken | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 5 (5)

Feken
Shopify Staff
1 1 3

This is an accepted solution.

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

Feken | Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

sanjar
Shopify Partner
21 1 2

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? 
Not applicable

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

sanjar
Shopify Partner
21 1 2

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

Not applicable

@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...