New API_PERMISSION adding app metafields issue

Solved

New API_PERMISSION adding app metafields issue

sanjar
Shopify Partner
21 1 1

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 1

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? 
hashcode_io
Shopify Partner
110 3 12

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

Shopify Team @ Conversios System
Please confirm its success with a like or marking it as a solution!
Google analytics 4
SST - Server-side tagging solution.
#martech#GA4 #GTM #ownGTM #SST #ServerSideTagging
sanjar
Shopify Partner
21 1 1

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

hashcode_io
Shopify Partner
110 3 12

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

Shopify Team @ Conversios System
Please confirm its success with a like or marking it as a solution!
Google analytics 4
SST - Server-side tagging solution.
#martech#GA4 #GTM #ownGTM #SST #ServerSideTagging