title: Apple Music/Music Kit: how to get song IDs?
body: <p>The Apple Music API provides a service to fetch a song via an identifier, as detailed in their <a href="https://developer.apple.com/documentation/applemusicapi/get_a_catalog_song" rel="nofollow noreferrer">documentation</a> in this format <code>https://api.music.apple.com/v1/catalog/us/songs/900032829</code></p>
  <p>My goal is to pick songs at random, from an array of songs. My current blocker is obtaining the song IDs from the ordinary Apple Music links, which is in this format: <code>https://music.apple.com/us/album/take-on-me-1985-12-mix-2015-remastered/1035047659?i=1035048414</code></p>
  <p>What would be the best way convert normal Apple Music links (such as the one above) to a the unique song id? (For the purpose of this project, the territory could be set as <code>us</code>)</p>
  <hr />
  <p><strong>Edit</strong>: there is a workaround to use the Spotify API, which is to look up a song's IRSC code, and then use the Apple Music's IRSC look up to find the song ID. (more detailed <a href="https://leemartin.dev/how-to-match-tracks-between-spotify-and-apple-music-2d6b6159957e" rel="nofollow noreferrer">here</a>)</p>
  <p>The constraints of this project requires that I can only use the Apple Music API/MusicKit, which means the above workaround is not possible.</p>