Mapping country names to Shopify taxonomy GIDs

In order to use the metaobjectCreate mutation to add metaobject’s associated with a Shopify-internal taxonomy attribute’s like Country, for example, it requires a taxonomy_reference, which is a gid of type TaxonomyValue. If given some country name as input, for example Germany, how can I identify whether it exists in Shopify’s taxonomy already and if so, to retrieve its gid?

I have checked the metaobject and metaobjects queries, however these are scoped to the current store and do not allow querying of the taxonomy. I have seen that if I know the gid, I can load its details using the node query, but that doesn’t help here. The only way I’ve seen to provide a list of taxonomy values for a given attribute is by using the taxonomy query:

query {
  categories(first: 10) {
    nodes {
      id
      fullName
      level
      name
      attributes(first: 10) {
        nodes {
          __typename
          ... on TaxonomyChoiceListAttribute {
            id
            name
            values(first: 10) {
              nodes {
                id
                name
              }
            }
          }
        }
      }
    }
  }
}

If I go through the pagination enough I will eventually find the desired attribute and the first X (10 in this example) taxonomy values:

                {
                  "__typename": "TaxonomyChoiceListAttribute",
                  "id": "gid://shopify/TaxonomyAttribute/2364",
                  "name": "Country",
                  "values": {
                    "nodes": [
                      {
                        "id": "gid://shopify/TaxonomyValue/8807",
                        "name": "Australia"
                      },
                      {
                        "id": "gid://shopify/TaxonomyValue/8808",
                        "name": "Austria"
                      },
 ...

However, this is a really inefficient, super nested query that requires paginating through all taxonomy values to determine if the desired value exists in the Shopify taxonomy before choosing “Other” by default.

Surely there must be a better way?

I have seen the admin interface using a query called SuggestedMetaobjects but this doesn’t seem to be available for app developers, despite being exactly what I need:

operationName=SuggestedMetaobjects
variables={"type":"shopify--country","first":20,"after":null,"displayName":"Germany"}

Results:

        "suggestedMetaobjects": {
            "edges": [
                {
                    "cursor": "<removed>",
                    "node": {
                        "displayName": "Germany",
                        "title": "Germany",
                        "id": "gid://shopify/SuggestedMetaobject/3682",
                        "type": "shopify--country",
                        "fields": [
                            {
                                "key": "label",
                                "value": "Germany"
                            },
                            {
                                "key": "taxonomy_reference",
                                "value": "gid://shopify/TaxonomyValue/8815"
                            }
                        ],
                        "handle": "germany",
                        "__typename": "SuggestedMetaobject"
                    },
                    "__typename": "SuggestedMetaobjectEdge"
                }
            ],
            "pageInfo": {
                "hasPreviousPage": false,
                "hasNextPage": false,
                "__typename": "PageInfo"
            },
            "__typename": "SuggestedMetaobjectConnection"
        }

Any ideas?

Shopify taxonomy is available on Github and you can get all the Countries from there – 2025-12

@tim_tairli Thanks. I’ll take a look to see if the relevant taxonomies can be simply included as part of the code. I’m not sure if this is a super robust solution though. If Shopify were to ever change any of the gids, things would break… so I would definitely still prefer a way to query the taxonomy in real time like the admin interface is able to.

I do not expect them to change those. Maybe add a country or two when new available :slight_smile:
Can probably fetch data.yml as part of your build process and retrieve a list of countries there.
Or include this repo as submodule…