MB URL resource not found when spaces exist

I’m trying to use the API to look for the artist that relates to a specific Last.FM page (such as https://www.last.fm/music/Amy+Grant). However, the API returns saying that this resource can’t be found. I determine it works fine if the artist doesn’t have a space (such as https://www.last.fm/music/Petra). Do I have to put the resource in quotes or something for it to be found? Both attempted artist have Last.FM relations on their artist page. Below are the two complete API request that are mentioned above.
Doesn’t Work: https://musicbrainz.org/ws/2/url?resource=https://www.last.fm/music/Amy+Grant&fmt=json&inc=artist-rels

Does Work: https://musicbrainz.org/ws/2/url?resource=https://www.last.fm/music/Petra&fmt=json&inc=artist-rels

You need to URL escape the plus sign which encodes the space in the underlying URL: https://musicbrainz.org/ws/2/url?resource=https://www.last.fm/music/Amy%2BGrant&fmt=json&inc=artist-rels (note the %2B).

Without this, your input decodes as last.fm/music/Amy Grant with a literal space instead of the plus.

3 Likes

Thanks, that worked!
I had tried replacing the ‘+’ with %20. but that it hadn’t worked.