Example use of metaobjectDefinitions and other metaobject APIs?

Tristan3dt
Shopify Partner
36 0 16

I'm looking for some clear examples of using the metaobjectDefinitions GraphQL query, and related queries.   I want to export metaobject definitions from one store, and then reimport into another store.  Using a third-party app to do this isn't an option for me -  I want to understand how to do this myself.

 

The query I'm attempting is:

 

{
    metaobjectDefinitions {
        id
        name
        description
    }
}
 
..which is giving me the error..
 
Field 'metaobjectDefinitions' doesn't exist on type 'QueryRoot', locations - line - 2, column - 5, path - query, metaobjectDefinitions, extensions - code - undefinedField, typeName - QueryRoot, fieldName - metaobjectDefinitions
 
.. but it isn't clear to me whether my query is malformed or if there is something else going on.
 
Does anyone have a working example of how to use the Metaobject GraphQL queries, please?
Reply 1 (1)

ShopifyDevSup
Shopify Staff
1440 235 489

Hi @Tristan3dt 👋

 

I'd recommend reviewing this guide on how to manage metaobjects. The `metaobjectDefinitions` query is supported for versions 2023-01+, so it may be worthwhile checking which version you're querying.

 

The query below should work:

 

{
    metaobjectDefinitions (first:10) {
        nodes {
            id
            name
            description
        }
    }
}

 

Or in curl:

 

curl -L 'https://SHOP_NAME.myshopify.com/admin/api/2023-04/graphql.json' \
-H 'Content-Type:application/json' \
-H 'X-Shopify-Access-Token:ACCESS_TOKEN' \
-d '{"query":"{ metaobjectDefinitions (first:10) { nodes { id name description } } }"}'

 

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