How can I create an AppOwnedMetafield using GraphQL?

How can I create an AppOwnedMetafield using GraphQL?

Not applicable

Hi all i am try to create the AppOwnedMetafield usage of the  graphql

 

 

 

# Create app meta field 
mutation CreateAppOwnedMetafield($metafieldsSetInput: [MetafieldsSetInput!]!) {
  metafieldsSet(metafields: $metafieldsSetInput) {
    metafields {
       namespace:secret_keys,
      key:api_key_ga3,
      type:single_line_text_field,
      value:ga343434344,
      ownerId:`gid://shopify/AppInstallation/3`
    
    }
    userErrors {
      field
      message
    }
  }
}

 

 


here is   graphql Query  

Replies 2 (2)

oscprofessional
Shopify Partner
16343 2438 3177

Hello @Anonymous 

  • Obtain the necessary permissions: Make sure your app has the required access and permissions to create metafields. You'll need the write_metafields scope.
     Please check following code may help you

 

mutation {
  metafieldCreate(input: {
    namespace: "your_app_namespace"
    key: "your_metafield_key"
    value: "your_metafield_value"
    valueType: STRING
    ownerType: SHOP
  }) {
    metafield {
      id
    }
    userErrors {
      field
      message
    }
  }
}

 

  • Customize the mutation: Modify the namespace, key, value, valueType, and ownerType fields according to your requirements. The namespace and key fields uniquely identify the metafield, while the value field holds the actual data. The valueType field specifies the data type (e.g., STRING, INTEGER, JSON_STRING). The ownerType field defines the scope of the metafield (e.g., SHOP, PRODUCT, CUSTOMER).

 

Thank you!!

 

Hire us | Pass Core Web Vital | B2B Wholesale Experts | Claim Your Free Website Review |
Connect with Us: WhatsApp | Skype: oscprofessionals-87 | Email: pallavi@oscprofessionals.com |
Custom Shopify SolutionsPrivate Apps, Theme Customization & SEO | Digital Marketing |
OSCP Apps: Discount Suite | Wholesale App | Bundle & Upsell | Shipping Discount | and more...
Not applicable

@oscprofessional  Thanks for the your answer. but I am using the app own meta filed.

I was not able to trackback with shopify admin api 2022-07 it was. now I need to update.

those API. 

https://shopify.dev/docs/apps/custom-data/metafields/app-data

app own meta only access by the app theme extension that was good. 
can you please help in same.