Using Spotify through Node Red

No one can help?

i found that it seems to work :wink:

When you get this Invalid redirect URI page, copy the URL from that page
Open https://www.urldecoder.org/ and paste the URL in the top box and encode the URL
Copy the URL after the part …&redirect_uri= and before the next & (e.g. &state=)
Enter this URI in your spotify app in the redirect URI
For homeassistant users, it could look something like this:
http://homeassistant.local:8123/api/hassio_ingress/bla-bla/spotify-credentials/auth/callback

Hope this may help others as well.

Found the solution here:

5 Likes

appreciate the answer.

i have tried all I could but still no luck.

I see in your links it points to “8123” port and not 1880 port. How is that correct if I use node red running on 1880?

What do you have in the "“scopes” field in node-red? And what should happen when I click “authenticate” in node-red?

I get:
INVALID_CLIENT: Invalid client

update: remove the oauth and now working. I REALLY DONT KNOW WHAT IT WAS I DID…

spotify.authorized

Ok, now the next thing.

How to proceed now to use this… :slight_smile:

you can find a flow example on google but for the moment i don’t use it …

Hi, I am further. Can play, pause, can next, skip etc. And I can do a “transferMyPlayback” to another device (alexa) via the device id.

Only thing not wokring for me i how to find and how to select waht playlist to play there…

Like this:

What should I put in the function node and how do I get a playlist id?

This does not work:
msg.params = [ {playlistId: "37i9dQZF1DWXmlLSKkfdAk"} ]; return msg;
and a lot of others also not :slight_smile:
gives me:
{"_msgid":"2b1aaff.8d8e15","topic":"","payload":true,"params":[{"playlistId":"37i9dQZF1DWXmlLSKkfdAk"}],"error":"WebapiError: Bad Request"}

I’m having trouble finding examples, or getting the function node to supply the correct information for just simple things like specifying a playlist too.

Would you mind posting how you managed to do play pause, etc. and transfer my playback, please?

Edit: OK, I found another post with more examples: Spotify node-red interface

You an get the deviceids by sending a string of ‘true’ to get my devices, then looking at the debug console.

Then as above, use a function node with:

msg.params = [
    ['85202189a6blablsca22818c7383'],
    { play: true }
];
return msg;

@sender

msg.params = [ "3XubkIrRsDkykhyRsr8" ]; return msg;

in the function node for ‘getPlaylist’ returns my playlist in an array, but doesn’t play that playlist.

The same works for getPlaylistTracks

You can find the Spotifyid of the playlist by clicking on the 3 dots next to your playlist, then share, then copy spotify URI

Edit: Ok, you need to use play, rather than getPlaylist, and put this in the function node replacing your playlist uri

msg.params = [ {context_uri: "spotify:playlist:3XubktkkgujSVzMRsr8"} ]; return msg;

For setShuffle you need:

msg.params = [ "true" ]; return msg;

where true is to turn on shuffle. That’s probably enough edits for one post today. :slight_smile: Hope it helps.

Thing is the device ids randomly change now and then and I do not know why…

That’s alarming, and certainly puts a spanner in the works of automation. What sort of device is changing device ID? So far I’ve only used my computer, and a bunch of Alexas, but they haven’t changed so far… touch wood, but then again I’ve only just started using it.

The getmydevices node might be able to help with automation, but it will take someone with more nous than me to pass variables. Another option might be able to use Home Assistant itself, with Spotcast…despite the name, it isn’t just a chromecast thing, but can broadcast to Alexas, computers, et cetera

For me only alexas change… and no answer so far…

Thanks for this. It solved my problems with invalid URI but now I have another issue. After agreeing to the permissions all I get is “401: Unauthorized.” Anyone have an idea why?

My Spotify integration within HA is working without any issues, I just can’t seem to get this to work in Node Red.

1 Like

@sender
hello friend please help me to make a flow to play a playlist on my google mini

What have you done yourself?

for the moment same problem impossible for me to play and send playlist… could you share your flow please?

I have it working, but one thing I found (maybe it has bin mentioned) is that you have to have an active connection to the chromecast or speaker, for instance through a phone or pc, only the you can use it, the player goes idl ones not connected and it will not work

do you have a flow to share?

For Chromecast there are still some issues with invoking spotify from a non android device. Check the Spotcast custom component for a workaround.

it works with spotcast :slight_smile:

but i want to use it without home assistant :slight_smile:

Hi- @sender what do you mean by remove the oauth? From where and how, I’m facing the same issues. Would appreciate the help of you could outline the steps. Thanks!

I have done as you described but I get the error

{"_msgid":"fcbdb5bb.ed3928","topic":"","params":[{"deviceIds":["77c3c0a12cf8ef9ddca2dae79bdee811cc446f8d"],"play":"true"}],"err":"TypeError: Cannot read property 'play' of undefined"}

This is the code of my function node

msg.params = [ {deviceIds: ["77c3c0a12cf8ef9ddca2dae79bdee811cc446f8d"], play: 'true'} ]; return msg;

Any suggestions?

1 Like