Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Give us an endpoint to decode new shortened share links

Give us an endpoint to decode new shortened share links

On mobile share-links are now shortened.

For example: https://spotify.link/hRkBrwub9xb

As a developer who relied on the URL containing the trackID this makes it impossible for me to find which track is being passed on. The website redirects to the correct song but it's not using 301 or 302 redirects which means that it probably is a client side JS redirect. 

Giving us an endpoint to paste the short url and retrieve the long url would be nice.

 

Redirect Chain

To further clearify that the short links are not a good idea is that embeds in popular chat programs like Discord won't work anymore. Even Spotify's own oEmbed endpoint does not work with this kind of URL: https://open.spotify.com/oembed?url=https://spotify.link/hRkBrwub9xb

 

 

"error": {
    "code": 404,
    "message": "Invalid URI: error in parsing"
}

 

 

Reply
9 Replies

I just ran into this issue myself, you don't actually need a dedicated endpoint for it because it's just a redirect. Just send a HEAD request to the URL and follow the redirects. Here's how you can unfurl it in Python.

import requests
r = requests.head("<spotify.link url>", allow_redirects=True)
print(r.url)

  And similarly in cURL.

curl -vILsw %{url_effective} https://spotify.link/hRkBrwub9xb

Even though it gives the response code for forbidden it returns the full URL. This is, albeit not ideal, the solution.

 

Thanks!

This is still impossible in some popular programming languages, Dart for example. Without the 3xx redirect code Dart cannot properly expand the URL all the way. A Spotify endpoint that gives you the full URL would be very helpful. 

The "allow_redirects" param is not helpful as I'm redirected to this page: https://www.spotify.com/us/download/pc?_branch_match_id=1240295733527340369&utm_source=copy-link&utm... which is not the playlist linked by the Spotify link: https://spotify.link/ltOhkWzXKDb

This is because Spotify does the redirect through js - specifically 

window.top.location.replace(FINAL_DESTINATION)

Ok; so how can I handle that correctly using CURL in PHP to have the correct destination URL?

EDIT: good by parsing the HTML. Still need a proper API endpoint for that.

You can use the cURL command or python snippet to get the final destination. Here is a Replit using the python snippet: https://replit.com/@HenryHill4/spotify-short-link-redirect-example?v=1

This is still broken in 2024 

Set your user agent to curl! Example in Dart:

Future<String> getShortLinkID(String url) async {
Dio dio = Dio();
dio.options.followRedirects = true;
dio.options.maxRedirects = 10;
Response<void> response = await dio.head(url,
options: Options(headers: {"User-Agent": "curl/7.79.1"}));
if (response.statusCode == 200) {
return response.realUri.toString();
} else {
throw Exception();
}
}
 
It will give you the real URL. 

Suggested posts