Can metafields transfer data to an app block?

dakperera
Shopify Partner
9 0 1

I'm creating a shopify app that will take some user (the merchant) specified input box text from the app dashboard gui, (this is an embedded app), and use it to populate an app block which i wish to place in the cart page of a store. I've created the front end dashboard part of the app, and I know how to create the app block liquid code as an app extension.  What I'm not sure about is how to transfer this data to the app block to be used.  ChatGPT has told me that metafields are a viable option.  I've found very little information on creating metafields entirely in app code.  For now I'd just like to know if this should be possible using metafields, or if there is another easier way to do it.

 

Thank you

Dak

Replies 7 (7)

conversionist
Shopify Partner
55 7 9

Hey bro I just created my first app! I ran into the same issue and found no content about it
Maybe I should make a YouTube video about this

You can use metafields or metaobjects
You can find the documentation here 

Basically the way it works is you create a metaobject definition which is essentially a schema

Here are the docs for creating a definition here 

Then you can add or remove metaobjects. You can find the documentation on how to do Everything 

And you can access it from theme app extension using This 

Building 100 Shopify apps for that BMW M5 dream

Follow the journey at https://www.youtube.com/@conversinist
https://conversionist.online/
dakperera
Shopify Partner
9 0 1

hey,

thanks a lot man, I'll have a look!

dakperera
Shopify Partner
9 0 1

My stuff is just text, so I would think a metafield could be used instead of a metaobject.  But it's enough to know that you got your app working using this method.

conversionist
Shopify Partner
55 7 9

I checked out YouTube videos comparing metafields and metaobjects
and I found that metaobjects are the best for apps because they offer this only your app can access the data

I was in your shoes just four days ago so I know how frustrating it can get If you run into any problems just let me know  and I'll reply as soon as possible

Building 100 Shopify apps for that BMW M5 dream

Follow the journey at https://www.youtube.com/@conversinist
https://conversionist.online/
dakperera
Shopify Partner
9 0 1

hey thanks man!  I'll take more of a deep dive into this before I bug you anymore on here lol

conversionist
Shopify Partner
55 7 9

No problem bro Feel free to ask as much as you want

Building 100 Shopify apps for that BMW M5 dream

Follow the journey at https://www.youtube.com/@conversinist
https://conversionist.online/
dakperera
Shopify Partner
9 0 1

So I finally had a chance to look at this again, and I had some questions about getting started.  I'm building my app using the Express App template.  I'm kind of a backend newbie, although I know the basics.  So looking at the sample nodejs code for creating a metaobject definition, as per your second link, I'm guessing it would have to be placed in the server file, so app/web/index.js.  ?  Also would that sample code need to be wrapped in an endpoint? So something like this:  

 

app.post("/api/metaobject", async(req, res) => {
  const session = res.locals.shopify.session;
  const client = new shopify.clients.Graphql({session});
  const data = await client.query({
    data: {
    "query": `mutation CreateMetaobjectDefinition($definition: MetaobjectDefinitionCreateInput!) {
        metaobjectDefinitionCreate(definition: $definition) {
 
....
 
})