Location API: country or country_name?

Shopify Partner
660 0 128

There is something weird and inconsitent in the location API.


It appears that both country and country_code are returning the country code (e.g. CA).

In addition, there is a non-documented country_name that does return the actually country (e.g. Canada).

This is inconsistent with other APIs.

And to make it even more confusing, the province and province_code appear to work as one would expect, returning the name and code (respectively) of the province, e.g. Ontario/ON.

What's the deal here?

We want to get the country name of the location. Is it safe to use the undocumented country_name field?

28 1 10

I'm having a similar problem with the Customer_Address object. https://shopify.dev/docs/admin-api/rest/reference/customers/customer-address

In my customer export, I have three fields: "default_address.country", "default_address.country code", and "default_address.country_name". Here's what I've been able to piece together:

"default_address.country" contains the country name (or the entire default_address is empty, e.g. for customers that I imported but who never placed an order)

"default_address.country_code" and "default_address.country_name" only contain a value if "default_address.country" is populated, but not always (about 99% of the time). 

If "default_address.country_code" is populated, so is "default-address.country_name" (and vice versa)

"default_address.country_name", when populated, always contains the same value as "default_address.country".


I can't tell why some records only have default_address.country and some have all three country fields. Both groups include domestic and international customers, and I think both groups include people who have placed orders and people who have not (the latter being people I would have imported but who haven't created customer accounts and/or made a purchase). 

At least for my purposes I was able to determine that customer.default_address.country is the one to use. Hopefully this is helpful for others.