<titledata-react-helmet="true">5.x.x to 6.x.x | SpotifyAPI-NET</title><metadata-react-helmet="true"name="docsearch:version"content="next"><metadata-react-helmet="true"name="twitter:card"content="summary_large_image"><metadata-react-helmet="true"property="og:title"content="5.x.x to 6.x.x | SpotifyAPI-NET"><metadata-react-helmet="true"name="description"content="SpotifyAPI.Web"><metadata-react-helmet="true"property="og:description"content="SpotifyAPI.Web"><metadata-react-helmet="true"property="og:url"content="https://johnnycrazy.github.io/SpotifyAPI-NET/docs/next/5_to_6"><linkdata-react-helmet="true"rel="shortcut icon"href="/SpotifyAPI-NET/img/favicon.ico"><linkdata-react-helmet="true"rel="canonical"href="https://johnnycrazy.github.io/SpotifyAPI-NET/docs/next/5_to_6"><linkrel="stylesheet"href="/SpotifyAPI-NET/styles.8a053330.css">
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var config = SpotifyClientConfig</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> .CreateDefault()</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> .WithAuthenticator(new ClientCredentialsAuthenticator(CLIENT_ID, CLIENT_SECRET)); // takes care of access tokens</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var spotify = new SpotifyClient(config);</span></div></div></div></div></div><p>For some performance guides, have a look at the <ahref="/SpotifyAPI-NET/docs/next/configuration">Configuration Guide</a></p><h3><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_ZqCz"id="proxy"></a>Proxy<aaria-hidden="true"tabindex="-1"class="hash-link"href="#proxy"title="Direct link to heading">#</a></h3><p>In <code>5.x</code>, the proxy configuration could be passed to the <code>SpotifyWebAPI</code> constructor. In <code>6.x</code>, they're part of the HTTP Client. The built-in http client supports proxies out of the box:</p><divclass="mdxCodeBlock_iHAB"><divclass="codeBlockContent_32p_"><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_1BYj">Copy</button><divtabindex="0"class="prism-code language-csharp codeBlock_19pQ"><divclass="codeBlockLines_2n9r"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var httpClient = new NetHttpClient(new ProxyConfig("localhost", 8080)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> User = "",</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> Password = "",</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> SkipSSLCheck = false,</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">});</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var config = SpotifyClientConfig</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> .CreateDefault()</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> .WithHTTPClient(httpClient);</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var spotify = new SpotifyClient(config);</span></div></div></div></div></div><h3><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_ZqCz"id="calling-api-endpoints"></a>Calling API Endpoints<aaria-hidden="true"tabindex="-1"class="hash-link"href="#calling-api-endpoints"title="Direct link to heading">#</a></h3><p>In <code>5.x</code>, there was one big instance to support all API endpoints. Parameters to these endpoints were passed directly as method parameters. Optional parameters were nullable and could be excluded. In <code>6.x</code>, every endpoint group (<code>albums</code>, <code>tracks</code>, <code>userprofile</code>) has their own API-Client, which is available as a property in a <code>SpotifyClient</code> instance. While URI path parameters are still passed as method parameter, query and body parameters are now passed as a grouped class instance, where required parameters are needed in the constructor and optional parameters can be supplied as properties. All endpoints are also only implemented as async methods.</p><divclass="mdxCodeBlock_iHAB"><divclass="codeBlockContent_32p_"><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_1BYj">Copy</button><divtabindex="0"class="prism-code language-csharp codeBlock_19pQ"><divclass="codeBlockLines_2n9r"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">// OLD:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">PrivateProfile profile = await spotify.GetPrivateProfileAsync();</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var playlists = await spotify.GetUserPlaylists(profile.Id, 100, 0);</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">// NEW:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">PrivateUser user = await spotify.UserProfile.Current();</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var playlists = await spotify.Playlists.GetUsers(user.Id, new PlaylistGetUsersRequest</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> Limit = 100,</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> Offset = 0</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">});</span></div></div></div></div></div><p>All required arguments are checked for non-null values. If it's null, the methods will throw a <code>ArgumentNullException</code></p><h3><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_ZqCz"id="errorheader-handling"></a>Error/Header Handling<aaria-hidden="true"tabindex="-1"class="hash-link"href="#errorheader-handling"title="Direct link to heading">#</a></h3><p>In <code>5.x</code>, all response models included a base error model, with properties like <code>Headers</code>, <code>Error</code> and <code>HasError</code>. This was not a good decision since response models should be clean and only contain API response data. In <code>6.x</code>, error handling is <code>Exception</code> based. For example, if the access token is invalid, calling API endpoints will throw a <code>APIUnauthorizedException</code>. If you hit the API too many times, the method will throw a <code>APITooManyRequestsException</code>. They all derive from a base exception <code>APIException</code>, which is also thrown in more general cases, e.g bad request input parameters. If you're interested in the headers of the last response, you can use <code>spotify.LastResponse</code>, <strong>make sure there is only one thread using this instance!</strong></p><divclass="mdxCodeBlock_iHAB"><divclass="codeBlockContent_32p_"><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_1BYj">Copy</button><divtabindex="0"class="prism-code language-csharp codeBlock_19pQ"><divclass="codeBlockLines_2n9r"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">// OLD:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">PrivateProfile profile = await spotify.GetPrivateProfileAsync();</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">if(profile.HasError())</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // handle error</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">}</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var headers = profile.Headers(); // access to headers</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"style="display:inline-block">
</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">// NEW:</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">try</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> PrivateProfile profile = await spotify.GetPrivateProfileAsync();</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> var response = spotify.LastResponse; // response.Headers</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">}</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">catch (APIUnauthorizedException e)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // handle unauthorized error</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // e.Response contains HTTP response</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // e.Message contains Spotify error message</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">}</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">catch (APIException e)</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">{</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // handle common error</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // e.Response contains HTTP response</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> // e.Message contains Spotify error message</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">}</span></div></div></div></div></div><p>More Info: <ahref="/SpotifyAPI-NET/docs/next/error_handling">Error Handling</a></p><h2><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_ZqCz"id="spotifyapiwebauth"></a>SpotifyAPI.Web.Auth<aaria-hidden="true"tabindex="-1"class="hash-link"href="#spotifyapiwebauth"title="Direct link to heading">#</a></h2><p>In <code>5.x</code>, <code>SpotifyAPI.Web.Auth</code> contained every logic related to the OAuth flows. In <code>6.x</code>, <code>SpotifyAPI.Web.Auth</code> is only required if you need a HTTP Server for handling OAuth responses. For example, if you're in a ASP.NET environment or just use the <ahref="/SpotifyAPI-NET/docs/next/client_credentials">Client Credentials</a> flow, there is no need to install <code>SpotifyAPI.Web.Auth</code> anymore.</p><h3><aaria-hidden="true"tabindex="-1"class="anchor enhancedAnchor_ZqCz"id="authorization-code-auth"></a>Authorization Code Auth<aaria-hidden="true"tabindex="-1"class="hash-link"href="#authorization-code-auth"title="Direct link to heading">#</a></h3><p>As an example, this shows how to convert a <code>5.x</code> authorization code flow to <code>6.x</code>:</p><divclass="mdxCodeBlock_iHAB"><divclass="codeBlockContent_32p_"><buttontype="button"aria-label="Copy code to clipboard"class="copyButton_1BYj">Copy</button><divtabindex="0"class="prism-code language-csharp codeBlock_19pQ"><divclass="codeBlockLines_2n9r"style="color:#bfc7d5;background-color:#292d3e"><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">// OLD</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">var auth =</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> new AuthorizationCodeAuth(_clientId, _secretId, "http://localhost:4002", "http://localhost:4002",</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain"> Scope.PlaylistReadPrivate | Scope.PlaylistReadCollaborative);</span></div><divclass="token-line"style="color:#bfc7d5"><spanclass="token plain">auth.AuthReceived += AuthOnAu