Spotify Web API
api.spotify.com · Media
Spotify music data — search tracks, albums, artists, playlists, audio features, and recommendations. Control playback for Premium users. Free with OAuth2.
Authentication
OAuth2
OAuth2 with Client Credentials or Authorization Code flow. Register at developer.spotify.com. Client Credentials grants read access to catalog; Authorization Code needed for user data.
Sample Requests
GET
Search tracks
Search for a song on Spotify.
https://api.spotify.com/v1/search?q=Bohemian Rhapsody&type=track&limit=3
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Authorization | Bearer YOUR_TOKEN |
curl -X GET "https://api.spotify.com/v1/search?q=Bohemian%20Rhapsody&type=track&limit=3" \ -H "Authorization: Bearer YOUR_TOKEN"
import requests
params = {
"q": "Bohemian Rhapsody",
"type": "track",
"limit": "3"
}
headers = {
"Authorization": "Bearer YOUR_TOKEN"
}
response = requests.get(
"https://api.spotify.com/v1/search",
params=params,
headers=headers,
)
print(response.json())const url = new URL('https://api.spotify.com/v1/search');
url.searchParams.set('q', 'Bohemian Rhapsody');
url.searchParams.set('type', 'track');
url.searchParams.set('limit', '3');
const response = await fetch(url, {
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
},
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"net/url"
)
func main() {
baseURL, _ := url.Parse("https://api.spotify.com/v1/search")
q := baseURL.Query()
q.Set("q", "Bohemian Rhapsody")
q.Set("type", "track")
q.Set("limit", "3")
baseURL.RawQuery = q.Encode()
targetURL := baseURL.String()
req, _ := http.NewRequest("GET", targetURL, nil)
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.spotify.com/v1/search")
uri.query = URI.encode_www_form({
"q" => "Bohemian Rhapsody",
"type" => "track",
"limit" => "3"
})
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
req["Authorization"] = "Bearer YOUR_TOKEN"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.spotify.com/v1/search?" . http_build_query([
"q" => "Bohemian Rhapsody",
"type" => "track",
"limit" => "3"
]);
$opts = ["http" => [
"method" => "GET",
"header" => implode("\r\n", [
"Authorization: Bearer YOUR_TOKEN"
]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
GET
Get audio features
Get audio analysis (tempo, energy, valence) for a track.
https://api.spotify.com/v1/audio-features/6rqhFgbbKwnb9MLmUQDhG6
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Authorization | Bearer YOUR_TOKEN |
curl -X GET "https://api.spotify.com/v1/audio-features/6rqhFgbbKwnb9MLmUQDhG6" \ -H "Authorization: Bearer YOUR_TOKEN"
import requests
headers = {
"Authorization": "Bearer YOUR_TOKEN"
}
response = requests.get(
"https://api.spotify.com/v1/audio-features/6rqhFgbbKwnb9MLmUQDhG6",
headers=headers,
)
print(response.json())const url = 'https://api.spotify.com/v1/audio-features/6rqhFgbbKwnb9MLmUQDhG6';
const response = await fetch(url, {
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
},
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
)
func main() {
targetURL := "https://api.spotify.com/v1/audio-features/6rqhFgbbKwnb9MLmUQDhG6"
req, _ := http.NewRequest("GET", targetURL, nil)
req.Header.Set("Authorization", "Bearer YOUR_TOKEN")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://api.spotify.com/v1/audio-features/6rqhFgbbKwnb9MLmUQDhG6")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Get.new(uri)
req["Authorization"] = "Bearer YOUR_TOKEN"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://api.spotify.com/v1/audio-features/6rqhFgbbKwnb9MLmUQDhG6";
$opts = ["http" => [
"method" => "GET",
"header" => implode("\r\n", [
"Authorization: Bearer YOUR_TOKEN"
]),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- Register at developer.spotify.com → Create App
- Get access token: POST https://accounts.spotify.com/api/token with client_id:client_secret base64 encoded
- Set Authorization: Bearer YOUR_TOKEN
- Search: GET /v1/search?q=the+beatles&type=artist,track&limit=5
- Token expires in 1 hour — re-request for continued use