
LastFm
MusicThe Last.fm API allows anyone to build their own programs using Last.fm data, whether they're on the web, the desktop or mobile devices. Embeds a Last.FM Group playlist into your vBulletin forum, on a new page. Scrobble music videos all around the web with this Google Chrome extension! Get your own personalized screensaver here – brought to you by Motorola.
🔑 How to get a free Last.fm API key
Last.fm issues API keys instantly — the whole process takes about a minute.
- Sign in to Last.fm. Create a free account at last.fm/join or log in.
- Create an API account. Go to last.fm/api/account/create and fill in your application name and description (a callback URL is only needed for auth flows).
- Copy your API key. Your API key (and shared secret) are shown immediately. Lost it? Retrieve it at last.fm/api/accounts.
- Make your first request. Call https://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Radiohead&api_key=YOUR_KEY&format=json — no OAuth needed for read endpoints.
📚 Documentation & Examples
Everything you need to integrate with LastFm
🚀 Quick Start Examples
// LastFm API Example
const response = await fetch('https://www.last.fm/api', {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const data = await response.json();
console.log(data);Using Last.fm API in JavaScript
Last.fm provides a public API that allows developers to access information about music, artists, tags, and more. In this blog post, we'll explore some of the basic API requests using JavaScript.
How to Get a Last.fm API Key
- Create or sign in to a free Last.fm account.
- Go to the Create API account page.
- Fill in your contact email and application name/description, then submit.
- Last.fm instantly issues two credentials: an API key and a shared secret. Manage them anytime at last.fm/api/accounts.
The API is free. Read methods (search, getInfo, charts) need only the API key; the shared secret is required only for authenticated/write methods such as scrobbling.
Pass the key as the api_key query parameter and request JSON with format=json:
const apiKey = 'YOUR_API_KEY';
fetch(`https://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Radiohead&api_key=${apiKey}&format=json`)
.then(res => res.json())
.then(data => console.log(data));
Making API Requests
Last.fm API requests can be made using any programming language that can communicate with web APIs. In this example, we'll use JavaScript to make API requests using the fetch method.
Search for Songs
To search for songs, we can use the track.search method. Here's an example code snippet:
const apiKey = '<your-API-key>';
const searchText = 'love';
fetch(`http://ws.audioscrobbler.com/2.0/?method=track.search&track=${searchText}&api_key=${apiKey}&format=json`)
.then(response => response.json())
.then(data => console.log(data));
In this code, we construct the API URL by building a query string with the API method (track.search), the search text (love), our API key, and the response format (json). We then use fetch to make a GET request to the Last.fm API with this URL.
Get Song Info
To get information about a specific song, we can use the track.getInfo method. Here's an example code snippet:
const apiKey = '<your-API-key>';
const trackArtist = 'The Beatles';
const trackName = 'Let It Be';
fetch(`http://ws.audioscrobbler.com/2.0/?method=track.getInfo&api_key=${apiKey}&artist=${trackArtist}&track=${trackName}&format=json`)
.then(response => response.json())
.then(data => console.log(data));
In this code, we construct the API URL by building a query string with the API method (track.getInfo), our API key, the song artist (The Beatles), the song name (Let It Be), and the response format (json). We then use fetch to make a GET request to the Last.fm API with this URL.
Get Artist Info
To get information about a specific artist, we can use the artist.getInfo method. Here's an example code snippet:
const apiKey = '<your-API-key>';
const artistName = 'The Beatles';
fetch(`http://ws.audioscrobbler.com/2.0/?method=artist.getInfo&api_key=${apiKey}&artist=${artistName}&format=json`)
.then(response => response.json())
.then(data => console.log(data));
In this code, we construct the API URL by building a query string with the API method (artist.getInfo), our API key, the artist name (The Beatles), and the response format (json). We then use fetch to make a GET request to the Last.fm API with this URL.
Conclusion
Using the Last.fm API in JavaScript is a great way to access information about music and artists. By constructing API URLs and making requests using fetch, we can easily retrieve data and integrate it into our own applications. This was just a brief introduction to some of the basic API requests, but the Last.fm API offers many more methods and parameters to explore.
❓ Frequently Asked Questions
Is the Last.fm API free?
Yes, for non-commercial use. Keys are issued instantly. Last.fm asks that you stay under a reasonable request rate (roughly 1 request/second averaged) and cache results.
How do I get a Last.fm API key?
Log in to Last.fm, open last.fm/api/account/create, fill in an app name, and the key appears immediately — no review process.
Can I get user scrobble data with the Last.fm API?
Yes — user.getRecentTracks, user.getTopArtists, and similar methods work with just an API key for public profiles. Writing scrobbles requires the authenticated session flow.









