Announcements
From 28th September 2026, Community private messages will no longer be available. If you have any private messages you'd like to keep, please save or copy them using these steps before this date. Thank you.

Help Wizard

Step 1

NEXT STEP

On fetch call getting PUT https://api.spotify.com/v1/me/player 502

On fetch call getting PUT https://api.spotify.com/v1/me/player 502

The console.log(response) object says the status code is 202 in my developer console (google chrome).

But then it gives me 502 bad gateway for the PUT request. 

 

 

 

 

    useEffect(() => {
        const script = document.createElement("script");
        script.src = "https://sdk.scdn.co/spotify-player.js";
        script.async = true;

        document.body.appendChild(script);

        window.onSpotifyWebPlaybackSDKReady = () => {
            const player = new window.Spotify.Player({
                name: "Web Playback SDK",
                getOAuthToken: (callback) => {
                    callback(props.token);
                },
                volume: 0.5,
            });

            setPlayer(player);

            player.addListener("ready", ({ device_id }) => {
                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) => {
                        console.log(response)});
                }
                connect_to_device();
                
            });

 

 

 

 

   
Reply
1 Reply

Error 502 could mean that the server is (temporarily) overloaded, so I recommend you to try it again at a later moment.

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Suggested posts

Let's introduce ourselves!

Hey there you,   Yeah, you! 😁   Welcome - we're glad you joined the Spotify Community!   While you here, let's have a fun game and get…

ModeratorStaff / Moderator/ 5 years ago  in Social & Random