<?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 On fetch call getting PUT https://api.spotify.com/v1/me/player 502 in Spotify for Developers</title>
    <link>https://community.spotify.com/t5/Spotify-for-Developers/On-fetch-call-getting-PUT-https-api-spotify-com-v1-me-player-502/m-p/5427751#M6229</link>
    <description>&lt;P&gt;The console.log(response) object says the status code is 202 in my developer console (google chrome).&lt;/P&gt;&lt;P&gt;But then it gives me 502 bad gateway for the PUT request.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    useEffect(() =&amp;gt; {
        const script = document.createElement("script");
        script.src = "https://sdk.scdn.co/spotify-player.js";
        script.async = true;

        document.body.appendChild(script);

        window.onSpotifyWebPlaybackSDKReady = () =&amp;gt; {
            const player = new window.Spotify.Player({
                name: "Web Playback SDK",
                getOAuthToken: (callback) =&amp;gt; {
                    callback(props.token);
                },
                volume: 0.5,
            });

            setPlayer(player);

            player.addListener("ready", ({ device_id }) =&amp;gt; {
                console.log("Ready with Device ID", device_id);

                async function connect_to_device() {
                    await fetch('https://api.spotify.com/v1/me/player', {
                        method: "PUT",
                        headers: ({
                            'Content-type': 'application/json',
                            'Authorization': `Bearer ${props.token}`
                        }),
                        body: JSON.stringify({
                            device_ids: [device_id],
                            play: false,
                        })
                    }).then((response) =&amp;gt; {
                        console.log(response)});
                }
                connect_to_device();
                
            });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Fri, 09 Sep 2022 21:45:49 GMT</pubDate>
    <dc:creator>bungee_gum</dc:creator>
    <dc:date>2022-09-09T21:45:49Z</dc:date>
    <item>
      <title>On fetch call getting PUT https://api.spotify.com/v1/me/player 502</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/On-fetch-call-getting-PUT-https-api-spotify-com-v1-me-player-502/m-p/5427751#M6229</link>
      <description>&lt;P&gt;The console.log(response) object says the status code is 202 in my developer console (google chrome).&lt;/P&gt;&lt;P&gt;But then it gives me 502 bad gateway for the PUT request.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    useEffect(() =&amp;gt; {
        const script = document.createElement("script");
        script.src = "https://sdk.scdn.co/spotify-player.js";
        script.async = true;

        document.body.appendChild(script);

        window.onSpotifyWebPlaybackSDKReady = () =&amp;gt; {
            const player = new window.Spotify.Player({
                name: "Web Playback SDK",
                getOAuthToken: (callback) =&amp;gt; {
                    callback(props.token);
                },
                volume: 0.5,
            });

            setPlayer(player);

            player.addListener("ready", ({ device_id }) =&amp;gt; {
                console.log("Ready with Device ID", device_id);

                async function connect_to_device() {
                    await fetch('https://api.spotify.com/v1/me/player', {
                        method: "PUT",
                        headers: ({
                            'Content-type': 'application/json',
                            'Authorization': `Bearer ${props.token}`
                        }),
                        body: JSON.stringify({
                            device_ids: [device_id],
                            play: false,
                        })
                    }).then((response) =&amp;gt; {
                        console.log(response)});
                }
                connect_to_device();
                
            });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 09 Sep 2022 21:45:49 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/On-fetch-call-getting-PUT-https-api-spotify-com-v1-me-player-502/m-p/5427751#M6229</guid>
      <dc:creator>bungee_gum</dc:creator>
      <dc:date>2022-09-09T21:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: On fetch call getting PUT https://api.spotify.com/v1/me/player 502</title>
      <link>https://community.spotify.com/t5/Spotify-for-Developers/On-fetch-call-getting-PUT-https-api-spotify-com-v1-me-player-502/m-p/5427826#M6240</link>
      <description>&lt;P&gt;Error 502 could mean that the server is (temporarily) overloaded, so I recommend you to try it again at a later moment.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Sep 2022 06:29:37 GMT</pubDate>
      <guid>https://community.spotify.com/t5/Spotify-for-Developers/On-fetch-call-getting-PUT-https-api-spotify-com-v1-me-player-502/m-p/5427826#M6240</guid>
      <dc:creator>Ximzend</dc:creator>
      <dc:date>2022-09-10T06:29:37Z</dc:date>
    </item>
  </channel>
</rss>

