The reason why the real file is File:Emblem_of_Afghanistan.svg
is because the Commons page File:Coat of arms of Afghanistan.svg
is a redirect to File:Emblem of Afghanistan.svg
. Unfortunately, the prop=imageinfo
API doesn't currently handle Commons redirects.
To work around that, when this happens (which you can recognize by imagerepository
in the response, but no URL*), you can instead query the Commons API, while also specifying redirects
: http://commons.wikimedia.org/w/api.php?action=query&titles=File:Coat_of_arms_of_Afghanistan.svg&prop=imageinfo&iiprop=url&format=json&redirects
* The query you linked to isn't right, it's missing the File:
prefix. The right query is: http://en.wikipedia.org/w/api.php?action=query&titles=File:Coat_of_arms_of_Afghanistan.svg&prop=imageinfo&iiprop=url&format=json