This library provides a universal wrapper and client for the Spotify Web API, designed to run seamlessly in both Node.js environments and modern browsers via bundlers like browserify, webpack, or rollup. Currently at stable version 5.0.2, the project maintains an active development status, with updates addressing bugs and adding new features, although major version releases can have extended intervals. Its key differentiators include comprehensive coverage of Spotify's Web API endpoints, offering helper functions for fetching music metadata, managing user profiles and playlists, interacting with the user's music library, personalizing content, browsing categories, controlling playback, and managing user/artist following relationships. The library aims to simplify interaction with the Spotify API's OAuth 2.0 authentication flows and various data retrieval/manipulation operations.
npm install spotify-web-api-nodeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to initialize the SpotifyWebApi, obtain an access token using the Client Credentials Flow, and then make a simple API call to search for an artist. It also briefly mentions the Authorization Code Flow setup.
Remove the `userId` parameter from all calls to playlist manipulation functions (e.g., `getPlaylists`, `createPlaylist`, `addTracksToPlaylist`). Ensure the API instance has an access token for the correct user set.
Before upgrading to or using version 5.0.0+, consult the `CHANGELOG.md` file in the `spotify-web-api-node` GitHub repository to identify and implement all necessary code adjustments for your application.
Implement robust token management logic. For web applications, use the Authorization Code Flow and handle refreshing tokens with `spotifyApi.refreshAccessToken()`. For server-to-server communication, periodically call `spotifyApi.clientCredentialsGrant()` to get new access tokens.
Upgrade `spotify-web-api-node` to version 4.0.0 or newer to ensure your application benefits from security fixes in its internal dependencies.
Ensure the authorization code is used immediately after redirection and only once. For refresh tokens, verify it's the current valid token and that the client ID/secret are correct.
Call `spotifyApi.setAccessToken(yourValidAccessToken)` with a non-expired token before making any authenticated API calls. Implement token refresh logic to automatically update the token.
Verify that `import SpotifyWebApi from 'spotify-web-api-node';` is used (default import) and that `spotifyApi = new SpotifyWebApi(...)` is correctly called to create an instance. Double-check method names against the documentation.
Carefully review the parameters being passed to the API method, ensuring they match the Spotify API documentation (e.g., URIs as arrays). Check that the access token has the necessary scopes (e.g., `playlist-modify-public`). If adding many tracks, ensure you are on `v2.4.0` or higher which passes track data in the body.
No dependency data recorded yet.