<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Cannot authenticate to Spotify API with Node.JS app in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/Cannot-authenticate-to-Spotify-API-with-Node-JS-app/m-p/5020788#M976</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Free&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;CH&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Programming Language&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Node.JS 12.13.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm creating a bot using the Spotify API. This bot should update one of my playlist by adding a specific song.&lt;/P&gt;&lt;P&gt;My problem is that I cannot obtain an access token with the /authorize endpoint.&lt;/P&gt;&lt;P&gt;Here's my code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function getToken() {
    let generateRandomString = function (length) {
        let text = '';
        let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

        for (let i = 0; i &amp;lt; length; i++) {
            text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
    };

    let spotifyApi = new SpotifyWebApi({
        clientId: data.spotify.client_id,
        redirectUri: data.spotify.redirect_uri
    });

    /**
     * Authenticating the app to Spotify Web API
     * @type {string[]}
     */
    let scopes = ['user-read-private', 'user-read-email', 'playlist-modify-public'],
        state = generateRandomString(16);

    // Create the authorization URL
    let authorizeURL = spotifyApi.createAuthorizeURL(scopes, state, false);

//Obtained URL -&amp;gt; https://accounts.spotify.com/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Duser-read-private%2Buser-read-email%2Bplaylist-modify-public%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A8888%252Fcallback%26state%3DlD3Ijyz5ucTZ9L5B%26client_id%3D516af068412341e69675da2c0f364846%26show_dialog%3Dfalse

    // Create request to the callback Express route
    https.get(authorizeURL, response =&amp;gt; {
        if (response) {
            return console.log(response);
        }
    }).on('error', err =&amp;gt; {
        console.error(err);
    });
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I process the GET request to authenticate my app (see the https.get part above) and when I check what is given in my console (output given by the return console.log(response)), I get that :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;...
responseUrl: 'https://accounts.spotify.com/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Duser-read-private%2Buser-read-email%2Bplaylist-modify-public%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A8888%252Fcallback%26state%3DlD3Ijyz5ucTZ9L5B%26client_id%3D516af068412341e69675da2c0f364846%26show_dialog%3Dfalse',
...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is the reponse URL I have. It seems that I'm not logged, thus I cannot access the Spotify Web API.&lt;/P&gt;&lt;P&gt;My callback route is working since I can copy/paste the authorizeUrl in a browser, and I'll get the token written in a text file. It's only when I try to process a request with https.get that it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;SPAN&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Aug 2020 12:52:00 GMT</pubDate>
    <dc:creator>LeRouteur</dc:creator>
    <dc:date>2020-08-20T12:52:00Z</dc:date>
    <item>
      <title>Cannot authenticate to Spotify API with Node.JS app</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/Cannot-authenticate-to-Spotify-API-with-Node-JS-app/m-p/5020788#M976</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Plan&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Free&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;CH&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Programming Language&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Node.JS 12.13.0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My Question or Issue&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm creating a bot using the Spotify API. This bot should update one of my playlist by adding a specific song.&lt;/P&gt;&lt;P&gt;My problem is that I cannot obtain an access token with the /authorize endpoint.&lt;/P&gt;&lt;P&gt;Here's my code :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;function getToken() {
    let generateRandomString = function (length) {
        let text = '';
        let possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

        for (let i = 0; i &amp;lt; length; i++) {
            text += possible.charAt(Math.floor(Math.random() * possible.length));
        }
        return text;
    };

    let spotifyApi = new SpotifyWebApi({
        clientId: data.spotify.client_id,
        redirectUri: data.spotify.redirect_uri
    });

    /**
     * Authenticating the app to Spotify Web API
     * @type {string[]}
     */
    let scopes = ['user-read-private', 'user-read-email', 'playlist-modify-public'],
        state = generateRandomString(16);

    // Create the authorization URL
    let authorizeURL = spotifyApi.createAuthorizeURL(scopes, state, false);

//Obtained URL -&amp;gt; https://accounts.spotify.com/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Duser-read-private%2Buser-read-email%2Bplaylist-modify-public%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A8888%252Fcallback%26state%3DlD3Ijyz5ucTZ9L5B%26client_id%3D516af068412341e69675da2c0f364846%26show_dialog%3Dfalse

    // Create request to the callback Express route
    https.get(authorizeURL, response =&amp;gt; {
        if (response) {
            return console.log(response);
        }
    }).on('error', err =&amp;gt; {
        console.error(err);
    });
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I process the GET request to authenticate my app (see the https.get part above) and when I check what is given in my console (output given by the return console.log(response)), I get that :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;...
responseUrl: 'https://accounts.spotify.com/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Duser-read-private%2Buser-read-email%2Bplaylist-modify-public%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A8888%252Fcallback%26state%3DlD3Ijyz5ucTZ9L5B%26client_id%3D516af068412341e69675da2c0f364846%26show_dialog%3Dfalse',
...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This is the reponse URL I have. It seems that I'm not logged, thus I cannot access the Spotify Web API.&lt;/P&gt;&lt;P&gt;My callback route is working since I can copy/paste the authorizeUrl in a browser, and I'll get the token written in a text file. It's only when I try to process a request with https.get that it doesn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;SPAN&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Aug 2020 12:52:00 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/Cannot-authenticate-to-Spotify-API-with-Node-JS-app/m-p/5020788#M976</guid>
      <dc:creator>LeRouteur</dc:creator>
      <dc:date>2020-08-20T12:52:00Z</dc:date>
    </item>
  </channel>
</rss>

