Spotify API integration with website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Spotify API Integration with Website

Spotify Web API is used for displaying current artist track, embedding players, and creating music recommendations on your website. Relevant for musician websites, podcasters, fan portals.

Authentication

Client Credentials Flow — for server requests without user participation (artist and album data):

async function getSpotifyToken(): Promise<string> {
  const credentials = Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString('base64');
  const resp = await fetch('https://accounts.spotify.com/api/token', {
    method: 'POST',
    headers: { 'Authorization': `Basic ${credentials}`, 'Content-Type': 'application/x-www-form-urlencoded' },
    body:    'grant_type=client_credentials',
  });
  const data = await resp.json();
  return data.access_token;  // lives for 3600 seconds
}

Authorization Code Flow — for user data (current track, playlists).

Artist Data

async function getArtistData(artistId: string): Promise<ArtistData> {
  const token = await getSpotifyToken();

  const [artist, topTracks, albums] = await Promise.all([
    fetch(`https://api.spotify.com/v1/artists/${artistId}`, {
      headers: { Authorization: `Bearer ${token}` },
    }).then(r => r.json()),

    fetch(`https://api.spotify.com/v1/artists/${artistId}/top-tracks?market=RU`, {
      headers: { Authorization: `Bearer ${token}` },
    }).then(r => r.json()),

    fetch(`https://api.spotify.com/v1/artists/${artistId}/albums?include_groups=album,single&market=RU&limit=10`, {
      headers: { Authorization: `Bearer ${token}` },
    }).then(r => r.json()),
  ]);

  return {
    name:       artist.name,
    followers:  artist.followers.total,
    genres:     artist.genres,
    popularity: artist.popularity,
    image:      artist.images[0]?.url,
    topTracks:  topTracks.tracks.slice(0, 5).map((t: any) => ({
      name:     t.name,
      preview:  t.preview_url,  // 30-second MP3 preview
      duration: t.duration_ms,
    })),
    latestAlbum: albums.items[0],
  };
}

Player Embedding

<!-- Spotify Embed — no API required -->
<iframe
  src="https://open.spotify.com/embed/track/TRACK_ID?utm_source=generator&theme=0"
  width="100%" height="152"
  frameBorder="0"
  allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
  loading="lazy">
</iframe>

Now Playing Widget

// Requires Authorization Code Flow + scope: user-read-currently-playing
async function getNowPlaying(userAccessToken: string) {
  const resp = await fetch('https://api.spotify.com/v1/me/player/currently-playing', {
    headers: { Authorization: `Bearer ${userAccessToken}` },
  });
  if (resp.status === 204) return null;  // nothing playing
  return resp.json();
}

Implementation time: 2–3 business days.