Spotify

Spotify

Music

Fetch data from the Spotify music catalog, manage users' playlists and saved music, get recommendations, control Spotify Connect, and more. Based on simple REST principles, the Spotify Web API endpoints return JSON metadata about music artists, albums, and tracks, directly from the Spotify Data Catalogue.

Visit API🔁 Alternatives

🔑 How to get free Spotify API credentials

Spotify doesn't use simple API keys — you create a free app to get a Client ID and Secret, then exchange them for an access token.

  1. Log in to the developer dashboard. Go to developer.spotify.com/dashboard with any free or premium Spotify account.
  2. Create an app. Click "Create app", give it a name, description, and a redirect URI (http://127.0.0.1:3000 works for local development).
  3. Copy your Client ID and Client Secret. Both are in the app's Settings page.
  4. Get an access token. For public data, use the Client Credentials flow: POST to https://accounts.spotify.com/api/token with grant_type=client_credentials and your ID/secret. Then send Authorization: Bearer TOKEN to https://api.spotify.com/v1/.
Open the Spotify dashboard →

📚 Documentation & Examples

Everything you need to integrate with Spotify

🚀 Quick Start Examples

Spotify Javascript Examplejavascript
// Spotify API Example
const response = await fetch('https://beta.developer.spotify.com/documentation/web-api/', {
    method: 'GET',
    headers: {
        'Content-Type': 'application/json'
    }
});

const data = await response.json();
console.log(data);

A Beginner's Guide to Spotify's Web API

Spotify's Web API is a powerful tool for developers to integrate streaming music and user data into their applications. In this tutorial, we'll go over the basics of the API and provide example code in JavaScript.

How to Get a Spotify API Key

Yes, the Spotify Web API is free — you just need a Spotify account (free or Premium) and a registered app.

  1. Log in to the Spotify Developer Dashboard.
  2. Click Create app, give it a name and description, add a redirect URI, and accept the Developer Terms of Service.
  3. Open the app and copy its Client ID; click Settings to reveal the Client Secret. Keep the secret private (use the ROTATE button if it ever leaks).

Spotify uses OAuth 2.0 rather than a plain key. For catalog data that isn't tied to a user (search, tracks, audio features), use the Client Credentials flow to exchange your Client ID and Secret for an access token:

curl -X POST "https://accounts.spotify.com/api/token" \
  -d grant_type=client_credentials \
  -u "CLIENT_ID:CLIENT_SECRET"

Send the returned token as Authorization: Bearer <token>. Reaching a user's own library or playlists requires the Authorization Code flow instead.

Authentication

Before you can make any requests to the API, you'll need to authenticate your app. The Web API uses OAuth 2.0 for authentication, which means you'll need to obtain an access token. You can do this by making a POST request to the following endpoint:

https://accounts.spotify.com/api/token

Here's an example code snippet in JavaScript:

const client_id = 'YOUR_CLIENT_ID';
const client_secret = 'YOUR_CLIENT_SECRET';

let access_token;
async function getAccessToken() {
  const response = await fetch('https://accounts.spotify.com/api/token', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Basic ' + btoa(client_id + ':' + client_secret)
    },
    body: 'grant_type=client_credentials'
  });
  const data = await response.json();
  access_token = data.access_token;
}
getAccessToken();

This code will obtain an access token using your client ID and secret, and store it in the access_token variable.

Common API Requests

Here are some common API requests you might make using the Web API.

Search for Tracks

You can search for tracks using the following endpoint:

https://api.spotify.com/v1/search?type=track&q=QUERY

Here's an example code snippet in JavaScript:

async function searchTracks(query) {
  const response = await fetch(`https://api.spotify.com/v1/search?type=track&q=${query}`, {
    headers: {
      'Authorization': 'Bearer ' + access_token
    }
  });
  const data = await response.json();
  return data.tracks.items;
}

This code will search for tracks matching the query parameter and return the results as an array of objects.

Get a Track's Audio Features

You can get a track's audio features using the following endpoint:

https://api.spotify.com/v1/audio-features/ID

Here's an example code snippet in JavaScript:

async function getTrackFeatures(id) {
  const response = await fetch(`https://api.spotify.com/v1/audio-features/${id}`, {
    headers: {
      'Authorization': 'Bearer ' + access_token
    }
  });
  const data = await response.json();
  return data;
}

This code will get the audio features of the track with the specified id.

Get a User's Top Tracks

You can get a user's top tracks using the following endpoint:

https://api.spotify.com/v1/me/top/tracks

Here's an example code snippet in JavaScript:

async function getTopTracks() {
  const response = await fetch('https://api.spotify.com/v1/me/top/tracks', {
    headers: {
      'Authorization': 'Bearer ' + access_token
    }
  });
  const data = await response.json();
  return data.items;
}

This code will get the current user's top tracks and return the results as an array of objects.

Conclusion

These are just a few examples of what you can do with Spotify's Web API. By using this guide and the Spotify Web API documentation, you can build your own music-focused applications and take advantage of all the amazing features Spotify has to offer.

❓ Frequently Asked Questions

Is the Spotify API free?

Yes — full catalog search, artist/album/track metadata, playlists, and audio features are free. New apps start in Development Mode (up to 25 allowlisted users); request Extended Quota for public apps.

How do I get a Spotify API key?

Spotify uses OAuth, not a standalone key: create an app at developer.spotify.com/dashboard to get a Client ID and Secret, then exchange them for a bearer token (Client Credentials flow for public data).

Can I play full tracks with the Spotify API?

Full-track playback requires the Web Playback SDK and a Spotify Premium user logged into your app. The Web API itself returns metadata and 30-second preview URLs for many tracks.

Explore More

Best Spotify alternatives (2026)Best Music APIsHow to Use Spotify API with PythonHow to Use Spotify API with JavaScriptHow to Use Spotify API with Node.js

Related APIs in Music