Search code examples
httprequestitunes-storeapple-music

iTunes Lookup API response is different for different clients


Right now it looks like a mystery. Please help me in solving it.

I use iTunes public API to fetch an album: "Metallica" by Metallica (see it in browser: US region, MV region). I construct the following URLs to fetch it via API:

  1. US region https://itunes.apple.com/lookup?id=579372950&country=US&entity=album - works
  2. MV region https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album - doesn't work

Here's the actual behaviour I observe:

  • If I query GET https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album in a Spring app (using RestTemplate + Jackson HttpMessageConverter) I get an empty response:

    {
     "resultCount":0,
     "results": []
    }
    
  • If I navigate to https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album in a browser I get a file download prompt. The file contains an empty response:

    {
     "resultCount":0,
     "results": []
    }
    
  • If I query API using HttpPie http get https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album I get a non-empty response !!!

    {
        "resultCount": 1,
        "results": [
            {
                "amgArtistId": 4906,
                "artistId": 3996865,
                "artistName": "Metallica",
                "artistViewUrl": "https://music.apple.com/us/artist/metallica/3996865?uo=4",
                "artworkUrl100": "https://is1-ssl.mzstatic.com/image/thumb/Music/v4/0b/9c/d2/0b9cd2e7-6e76-8912-0357-14780cc2616a/source/100x100bb.jpg",
                "artworkUrl60": "https://is1-ssl.mzstatic.com/image/thumb/Music/v4/0b/9c/d2/0b9cd2e7-6e76-8912-0357-14780cc2616a/source/60x60bb.jpg",
                "collectionCensoredName": "Metallica",
                "collectionExplicitness": "notExplicit",
                "collectionId": 579372950,
                "collectionName": "Metallica",
                "collectionPrice": 9.99,
                "collectionType": "Album",
                "collectionViewUrl": "https://music.apple.com/us/album/metallica/579372950?uo=4",
                "copyright": "℗ 1991 Blackened Recordings",
                "country": "USA",
                "currency": "USD",
                "primaryGenreName": "Metal",
                "releaseDate": "1991-08-12T07:00:00Z",
                "trackCount": 13,
                "wrapperType": "collection"
            }
        ]
    }
    

I tried it multiple times and the results seem to be consistent. I compared the requests and they seem to be identical.

Why does iTunes respond differently to different clients? I can't understand. What important detail am I missing?


Similar questions:

  1. Spring RestTemplate getForObject URL not working for Apple iTunes - there's another problem (double encoding of the whitespace character).

This problem happens to the following regions (it's a complete list):


Solution

  • I spotted a difference:

    • http get 'https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album' -> empty response
    • curl 'https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album' -> empty response

    • http get https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album -> 1 album in response

    • curl https://itunes.apple.com/lookup?id=579372950&country=MV&entity=album -> 1 album in response

    if I don't use quotes around URL, the request is interpreted as GET https://itunes.apple.com/lookup?id=579372950. the default country is US and therefore I see 1 US album in response.