Retrieving country name from city areas using API

api
areas
Tags: #<Tag:0x00007f2a00b14960> #<Tag:0x00007f2a00b14820>

#1

I use the XML API in my tagger to retrieve all sorts of information, including the artist country. For most artists, the information is easily retrieved, however I don’t see any way to get the country for artists which have specific city information listed.

For example:
Emma Ruth Rundle artist query
The only area info that comes back:

<area id="1f40c6e1-47ba-4e35-996f-fe6ee5840e62">
    <name>Los Angeles</name>
    <sort-name>Los Angeles</sort-name>
</area>

Querying off LA’s MBID doesn’t provide much extra information
Adding inc=rea-rels to the query still doesn’t include the country.

So if an artist only has a city area listed, is there any way to get to the country that city resides in using the API?


#2

I think the only way to do this is to

  1. filter the results you get from your inc=area-rels query, find the one (or more) that’s “part of” with <direction>backward</direction>
  2. query that area and check its area-type
    • if the type is “country”, you’re done
    • if the type is not a “country”, then repeat recursively until you find the country.

#3

Thanks! I somehow missed the LA county in that area-reals query and the <direction>backward</backward>.

That’s a huge pain, but it’s definitely doable.