Solved

Import/export metafield definitions between stores or by API?

Tristan3dt
Shopify Partner
36 0 16

Hi everybody,


I'm using a developer store to prepare for the 'big upgrade' to Themes 2.0, where we will be making heavy use of metafields to standardise the information we display on our product pages.


This could mean we will have almost 20 different metafield definitions for the various parts (text, images, etc).

 

Is there any way to export the metafield definitions from one store, so that we can import those onto another?

 

It would save a lot of tedious and error-prone copy and pasting when it comes to deploy the theme onto our live site.

 

If this isn't possible (either in the backend or via API), I'd like to make this a feature suggestion!

 

Thanks,

Accepted Solution (1)
ShopifyDevSup
Shopify Staff
1363 228 476

This is an accepted solution.

Hey @Tristan3dt - you should be able to pull the types as a field under the metafieldDefinitions object as well. Can you try this query and let us know if it resolves the issue:

{
   metafieldDefinitions(first: 250, ownerType: PRODUCT) {
       edges {
           node {
               id
               namespace
               key
             type {
               name
               category
             }
           }
       }
   }
   }

Hope this helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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 6 (6)

ShopifyDevSup
Shopify Staff
1363 228 476

Hi @Tristan3dt 


We can use the `metafieldDefinitions` query to fetch the metafield definitions required for your theme, then use the `metafieldDefinitionCreate` mutation to create them on the next store. Keep in mind, there may be pre-existing metafield definitions so it would be worthwhile to ensure your namespace and key is unique before importing.

 

Hope that helps!

 

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

Tristan3dt
Shopify Partner
36 0 16

Thanks for this.  I've just come to try and implement this, but I can't figure out what the query should be to fetch the metafieldDefinitionType that corresponds to an existing metafieldDefinition. 

 

I can't see any example that does this.  Do you have any advice how to do this please?

 

My working query to fetch the metafieldDefinitions id, namespace and key is below, but I also need to pull the type of the metafield too, so that I can recreate it automatically on the target store.

 

Thanks for any help you can offer,

 


@ShopifyDevSup wrote:

Hi @Tristan3dt 


We can use the `metafieldDefinitions` query to fetch the metafield definitions required for your theme, then use the `metafieldDefinitionCreate` mutation to create them on the next store. Keep in mind, there may be pre-existing metafield definitions so it would be worthwhile to ensure your namespace and key is unique before importing.

 

Hope that helps!

 

 


{
    metafieldDefinitions(first: 250, ownerType: PRODUCT) {
        edges {
            node {
                id
                namespace
                key
            }
        }
    }
    }
ShopifyDevSup
Shopify Staff
1363 228 476

This is an accepted solution.

Hey @Tristan3dt - you should be able to pull the types as a field under the metafieldDefinitions object as well. Can you try this query and let us know if it resolves the issue:

{
   metafieldDefinitions(first: 250, ownerType: PRODUCT) {
       edges {
           node {
               id
               namespace
               key
             type {
               name
               category
             }
           }
       }
   }
   }

Hope this helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

Tristan3dt
Shopify Partner
36 0 16

Thank you for this!  I came back around to explore this, and couldn't figure out how to get the metafield type, since I don't think its mentioned on the metafield GraphQL documentation.  This gave me the answer I needed! 

 

Now just to figure out how to turn the response into a createMetafieldDefinition (?) query... and then to do the same again for Metaobjects!

PaulNewton
Shopify Partner
6339 579 1345

Search and Review the dev docs

https://shopify.dev/ 

https://shopify.dev/api/admin-rest/2022-10/resources/metafield

Also see the dev graphql docs on metafields and metafield definitions

 

Instead of a full app it is possible to script tools like postman or insomnia clients to get data from one store to pass to another.

 

You can use a scripting automation app like usemechanic to output data or to sync stores

https://tasks.mechanic.dev/?tags=Metafields 

https://tasks.mechanic.dev/?q=CSV 

or https://docs.usemechanic.com/article/325-the-anatomy-of-a-store-to-store-sync 

 

Or a shopify app for ETL import/export to get a CSV; such as ez-exporter, matrixify.

Or third party lowcode/nocode platfrom such as zapier,integromat(now "make").

 

Currently I think it is now theoretically possible to sync a dev shop to a production store using shopify-flow with the release of the scheduling, get-data(no /pages data), and list action features in tandem with the send-http-request action and custom-app keys.

https://changelog.shopify.com/posts/shopify-flow-new-scheduled-time-trigger-get-data-actions-and-too... 

https://help.shopify.com/en/manual/shopify-flow/reference/actions/send-http-request 

 

 

Save time & money ,Ask Questions The Smart Way


Confused? Busy? Get the solution you need paull.newton+shopifyforum@gmail.com


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Buy Paul a Coffee for more answers or donate to eff.org


Kahvia
Visitor
2 0 1

Yes, it is possible to export and import metafields between stores. You can use the Shopify Metafields API to export and import metafields. The API allows you to create, retrieve, update, and delete metafields for products, customers, orders, and shop resources. You can also use third-party apps from the Shopify App Store that provide this functionality. However, if you want to use a customized solution, you can use the Shopify API and write code to export and import metafields as per your need.