0
Get the tracks by album
let apiKey := "8c6c8610-4f04-11ee-b74b-03c9318fae41";
let artist := substitute(text(Name), { " " : "%20" });
let album := substitute(text(Title), { " " : "%20" });
let url := "https://ws.audioscrobbler.com/2.0/?method=album.getinfo&artist=" + artist +
"&album=" + album +
"&api_key=" + apiKey +
"&format=json";
let headers := {};
let body := null;
let response := http("GET", url, headers, body);
let albumData := record(response, "album");
let tracksData := record(albumData, "tracks");
let trackList := tracksData.track;
let allTracks := "";
for t in trackList do
allTracks := allTracks + record(t, "name") + lineBreak()
end;
Tracks := allTracks
I'm trying to get the tracks by album from Last.fm but I haven't been able to and the AI isn't helping much. Any ideas?
1 reply
-
Hello Rafael,
I see you were trying to encode artist and album manually by replacing spaces with%20
.
However, it's better to useurlEncode()
in Ninox, because it also handles special characters, accents, and Unicode properly.let artist := urlEncode(Name); let album := urlEncode(Title);
In the second part, after retrieving the result, you need to iterate through the response using a key-value loop.
Here is the complete code:
let apiKey := "your-api-key"; let artist := urlEncode(Name); let album := urlEncode(Title); let url := --- https://ws.audioscrobbler.com/2.0/?method=album.getinfo &artist= { artist } &album={ album } &api_key={ apiKey } &format=json ---; let response := http("GET", url, {}, {}); let allTracks := for key, value in response.result do if key = "album" then join(for t in value.tracks.track do text(t.name) end, " ") end end; allTracks
Content aside
- 20 hrs agoLast active
- 1Replies
- 31Views
-
2
Following