Re: Any one done the App Own meta graphql API 'mutation CreateAppOwnedMetafield'

Any one done the App Own meta graphql API 'mutation CreateAppOwnedMetafield'

hashcode_io
Shopify Partner
115 3 13


HI all,
Does any one using  the 
AppOwnedMetafield 
this was Shopify admin API grapql. 2022-04 ,  

As per the old document `{
"created_at": "2012-03-13T16:09:54-04:00",
"description": "The number of units at the warehouse.",
"id": 915396206,
"key": "warehouse",
"namespace": "inventory",
"owner_id": 548380009,
"owner_resource": "product",
"updated_at": "2012-08-24T14:02:15-04:00",
"value": "25",
"type": "single_line_text_field"
}
`

but it for latest API version 2023-04.  what was the way to create app own meta or app secure meta value.. !!
@Shopify
 

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
Replies 2 (2)

Shayne
Shopify Staff (Retired)
254 20 48

To create an app-owned metafield in Shopify Admin API GraphQL, you need to use the metafieldSet mutation and set the ownerID to the ID of the AppInstallation object associated with the app. Here's an example of how to create an app-owned metafield:

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

 

And the variables for the mutation:

{
  "metafieldsSetInput": [
    {
      "namespace": "your_namespace",
      "key": "any_key",
      "type": "single_line_text_field",
      "value": "blah blah blah",
      "ownerId": "gid://shopify/AppInstallation/541153067321"
    }
  ]
}

 

Remember to replace the `ownerId` value with the correct `AppInstallation` ID for your app. For more information, you can refer to the Shopify documentation on app-owned metafields.

Shayne | Developer Advocate @ 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

hashcode_io
Shopify Partner
115 3 13

@Shayne Thanks I was using the same code as now my app side.
Issue i am facing.
1. We are updating Shopify admin  API  latest version 2023-04.   I was looking into the document i was not found any reference for the same. 

2. We can see the API notice. We are updating same app meta value it was in an app feature. 
this case what was the solution  do not passing the type time of meta creation ?

As of 2023-01, `metafieldsSet` no longer requires `type` when a corresponding metafield definition exists. View change


3. facing issue into accessing those meta value in the  theme app extension checking those meta field value into when those value is not  started liquid code stop ruining

` this working  when value is stored. 

{% if app.metafields.myapps.appmeta1.value %}
app liquid code 
{% endif %}


 

` This code block run all 

{% if app.metafields.myapps.appmeta1 %}
app liquid code 
{% endif %}


 

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