Example use of metaobjectDefinitions and other metaobject APIs?

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?

Hi @Tristan3dt :waving_hand:

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!