Getting Started
Set up your Spotify Developer account and make your first API call
This tutorial walks you through setting up your Spotify Developer account, creating an application, and making your first API call to retrieve artist data.
Prerequisites
Section titled “Prerequisites”- A Spotify account (free or Premium)
- Basic knowledge of JavaScript/Node.js
- Node.js 18+ installed
Create a Spotify App
Section titled “Create a Spotify App”-
Log into the Developer Dashboard
Go to the Spotify Developer Dashboard and log in with your Spotify account.
-
Create a new app
Click “Create app” and fill in the details:
- App name: Your application’s name
- App description: Brief description of what you’re building
- Redirect URI:
http://localhost:3000/callback(for development) - APIs used: Select “Web API”
-
Get your credentials
After creating the app, you’ll see your Client ID on the app dashboard. Click “View client secret” to reveal your Client Secret.
Your First API Call
Section titled “Your First API Call”Let’s make a simple API call to get information about an artist.
Option 1: Quick Test with cURL
Section titled “Option 1: Quick Test with cURL”# First, get an access tokencurl -X POST "https://accounts.spotify.com/api/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET"
# Use the token to get artist info (Taylor Swift)curl "https://api.spotify.com/v1/artists/06HL4z0CvFAxyc27GXpf02" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN"Option 2: Using the SDK
Section titled “Option 2: Using the SDK”First, install the Spotted SDK:
npm install spotted-tsCreate a new file spotify-test.js:
import Spotted from "spotted-ts";
// Initialize the client (uses SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET env vars)const client = new Spotted();
// Get Taylor Swift's artist profileasync function main() { const artist = await client.artists.retrieve("06HL4z0CvFAxyc27GXpf02");
console.log(` Artist: ${artist.name} Followers: ${artist.followers.total.toLocaleString()} Genres: ${artist.genres.join(", ")} Popularity: ${artist.popularity}/100 `);}
main();Run it:
node spotify-test.jsYou should see output like:
Artist: Taylor SwiftFollowers: 100,000,000+Genres: pop, pop dancePopularity: 100/100Understanding the API Response
Section titled “Understanding the API Response”Here’s what a typical artist object looks like:
{ "id": "06HL4z0CvFAxyc27GXpf02", "name": "Taylor Swift", "type": "artist", "uri": "spotify:artist:06HL4z0CvFAxyc27GXpf02", "followers": { "total": 100000000 }, "genres": ["pop", "pop dance"], "images": [ { "url": "https://i.scdn.co/image/...", "height": 640, "width": 640 } ], "popularity": 100, "external_urls": { "spotify": "https://open.spotify.com/artist/06HL4z0CvFAxyc27GXpf02" }}Key Fields
Section titled “Key Fields”| Field | Description |
|---|---|
id | Unique Spotify ID for the artist |
uri | Spotify URI (used for playback and linking) |
name | Artist name |
followers.total | Number of followers |
genres | Array of genre tags |
popularity | 0-100 popularity score |
images | Array of profile images in different sizes |
Searching for Content
Section titled “Searching for Content”Now let’s search for tracks:
import Spotted from "spotted-ts";
const client = new Spotted();
// Search for "Blinding Lights"async function main() { const results = await client.search.query({ q: "Blinding Lights", type: ["track"], limit: 10, });
console.log("Search Results:"); results.tracks.items.forEach((track, i) => { console.log(`${i + 1}. ${track.name} by ${track.artists[0].name}`); });}
main();Building a Simple CLI App
Section titled “Building a Simple CLI App”Here’s a complete example that combines multiple API calls using the SDK:
import Spotted from "spotted-ts";
const client = new Spotted();
async function exploreArtist(artistId) { // Get artist info const artist = await client.artists.retrieve(artistId); console.log(`\n🎤 ${artist.name}`); console.log(` Followers: ${artist.followers.total.toLocaleString()}`); console.log(` Genres: ${artist.genres.slice(0, 3).join(", ")}`);
// Get top tracks const { tracks } = await client.artists.getTopTracks(artistId, { market: "US", }); console.log(`\n🎵 Top Tracks:`); tracks.slice(0, 5).forEach((track, i) => { console.log(` ${i + 1}. ${track.name} (${track.album.name})`); });
// Get albums (using async iterator) console.log(`\n💿 Recent Albums:`); let albumCount = 0; for await (const album of client.artists.listAlbums(artistId, { include_groups: "album", })) { if (albumCount >= 5) break; console.log(` • ${album.name} (${album.release_date.slice(0, 4)})`); albumCount++; }
// Get related artists const { artists: related } = await client.artists.getRelatedArtists(artistId); console.log(`\n👥 Similar Artists:`); console.log( ` ${related .slice(0, 5) .map((a) => a.name) .join(", ")}`, );}
// Explore The WeekndexploreArtist("1Xyo4u8uXC1ZmMpatF05PJ");Output:
🎤 The Weeknd Followers: 75,000,000+ Genres: canadian contemporary r&b, canadian pop, pop
🎵 Top Tracks: 1. Blinding Lights (After Hours) 2. Starboy (Starboy) 3. Save Your Tears (After Hours) 4. Die For You (Starboy) 5. The Hills (Beauty Behind the Madness)
💿 Recent Albums: • Dawn FM (2022) • After Hours (2020) • Starboy (2016) • Beauty Behind the Madness (2015) • Kiss Land (2013)
👥 Similar Artists: Dua Lipa, Post Malone, Drake, Doja Cat, Harry StylesNext Steps
Section titled “Next Steps”Now that you’ve made your first API calls, explore these guides to build more advanced features: