Hi,
Is there a way to get a list of countries and country codes using a GQL query?
Hi,
Is there a way to get a list of countries and country codes using a GQL query?
To get a list of countries and their country codes using a GraphQL query in Shopify, you can use the availableLocales
query. This query retrieves a list of locales, including their ISO country code and name.
Here’s an example of how you can use this query:
query {
availableLocales {
isoCode
name
}
}
This query will return a list of locales with their ISO country codes and names.
Refer to this documentation:
You can also use shopLocales to get a list of locales available on a shop.
availableLocales gives you the list of languages
If you’re looking into what countries and provinces a place delivers to, you can run
query GetCountriesAndProvinces {
deliveryProfiles(first: 10) {
edges {
node {
profileLocationGroups {
locationGroupZones(first: 10) {
edges {
node {
zone {
name
countries {
code {
countryCode
}
provinces {
code
}
}
}
}
}
}
}
}
}
}
}
But if you’re looking to fetch all country and province codes that are available in Shopify, you can run the same query on your test store after adding all locations to your delivery profile from Admin > Settings > Shipping and Delivery > Shipping Profile > Add all available countries and provinces. Once you have this, you can flatten it out so you have a better structured array.
Either ways, you also want to add cursors so you can loop over all possible entries.
in that case, a good old json file with codes and name would work best if there is no way to get country codes and country names
Sorry, didn’t have my coffee yet.
no worries it happens with me all the time