{"library":"spotify-web-api-node","title":"Spotify Web API Node.js Wrapper","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install spotify-web-api-node"],"cli":null},"imports":["import SpotifyWebApi from 'spotify-web-api-node'"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://www.npmjs.com/package/spotify-web-api-node","github":"https://github.com/thelinmichael/spotify-web-api-node","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/spotify-web-api-node","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import SpotifyWebApi from 'spotify-web-api-node';\n\nconst clientId = process.env.SPOTIFY_CLIENT_ID ?? '';\nconst clientSecret = process.env.SPOTIFY_CLIENT_SECRET ?? '';\nconst redirectUri = process.env.SPOTIFY_REDIRECT_URI ?? 'http://localhost:8888/callback'; // Required for Authorization Code Flow\n\nif (!clientId || !clientSecret) {\n  console.error(\"Please set SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET environment variables.\");\n  process.exit(1);\n}\n\nconst spotifyApi = new SpotifyWebApi({\n  clientId: clientId,\n  clientSecret: clientSecret,\n  redirectUri: redirectUri\n});\n\n// Example: Client Credentials Flow (server-side, no user context)\nspotifyApi.clientCredentialsGrant()\n  .then(data => {\n    console.log('The access token expires in ' + data.body['expires_in'] + ' seconds.');\n    console.log('The access token is ' + data.body['access_token']);\n\n    spotifyApi.setAccessToken(data.body['access_token']);\n\n    // Example: Search for an artist (requires no user context)\n    return spotifyApi.searchArtists('The Weeknd');\n  })\n  .then(data => {\n    console.log('Found artists:', data.body.artists.items[0].name);\n    return spotifyApi.getArtistAlbums(data.body.artists.items[0].id);\n  })\n  .then(data => {\n    console.log('First album:', data.body.items[0].name);\n  })\n  .catch(err => {\n    console.error('Something went wrong during client credentials flow or API call!', err);\n  });\n\n// For Authorization Code Flow, you'd typically:\n// 1. Generate an authorization URL: spotifyApi.createAuthorizeURL(['user-read-private', 'user-read-email'], 'some-state');\n// 2. Redirect user to that URL.\n// 3. Handle the callback on your redirectUri, exchanging the code for tokens:\n//    spotifyApi.authorizationCodeGrant(code).then(...).catch(...);","lang":"javascript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}