Spotify node-red interface

Thank you - I have it installed and run it with pm2, so I got that covered.

However I cant get my head around why you are calling “cookies”
var cookies = JSON.stringify(msg.req.cookies,null,4);

when “cookie”'s own docu calls “cookie”

Thanks so much for creating this, at the moment I have imported your snippets exactly, and set the variables. When I try to run your example I am getting an error no response object, please see the log entries below:

Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [info] [function:isAuthenticated?] beginning spotify authentication
Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [info] [function:isAuthenticated?] getting access_token
Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [info] [function:isAuthenticated?] received access token
Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [info] [function:isAuthenticated?] spotify_access_token: undefined
Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [info] [function:isAuthenticated?] yes
Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [info] [function:isAuthenticated?] No Tokens flow
Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [info] [function:Generate state value] spotify state: j5TrtgI4j84V2kfD
Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [info] [function:Spotify Authorization] Spotify building request to callback
Dec 10 22:52:20 automation node-red[2203]: playlist-modify-private playlist-read-private playlist-modify-public playlist-read-collaborative user-follow-read user-follow-modify user-read-private user-read-email user-read-birthdate user-top-read user-read-recently-played user-library-modify user-library-read user-read-playback-state user-read-currently-playing user-modify-playback-state streaming
Dec 10 22:52:20 automation node-red[2203]: 10 Dec 22:52:20 - [warn] [http response:Error] No response object

I need better debugging.

The problem appears to be In the Spotify Authorization function node on line 12 where it’s building the msg object.

It could be the querystring.stringify call. I believe that’s a separate module that needs to be loaded outside of node-red. The easiest way to test that would be to wrap a debug around a querystring.stringify call. Something like.

node.log("start")
var q = querystring.stringify({
    response_type: 'code',
    client_id: client_id,
    scope: scope,
    redirect_uri: redirect_uri,
    state: msg.state
});
node.log("q");
node.log("stop");

Now check to see if you actually got output for q. My guess is no. If that’s the case go ahead and npm install querystring and restart node-red.

How are you getting the Spotify authorization site to pop-up for a user to log into the first time this is executed?

In my case it just pops up and asks me to authorize. If you aren’t seeing that then I wonder if it’s breaking somewhere before that point. Have you tried constructing your URL and pasting it into a browser to see if it works? I’ve had problems with the callback not perfectly matching what I setup in Spotify but the initial auth request has never been a problem. Might also be an issue with the way Node Red is doing the redirect. Are you getting any debug info?

Hi Jay,

Great job! But I can’t seem to get it working… I always get /spotify/login message

I don’t know what to do anymore.

Thanks in advance for the help.

Hugo

You’d have to provide more information.

So, after some more debugging, I found out that the querystring.stringify call is not working. I tried what you suggested on your reply of 1st of Dec. 18, installed querystring, but it still does not work.

Any idea?

Thank you so much for your help.

Get to a terminal prompt in your /data directory and do a npm install —save querystring. Restart node-red. See if that fixes it.

Hi, pretty new to this and just posted this on another topic:

I have troubles following our post and not sure “what” to exactly do. Can you help out?

Same question :-), can someone help?

Hi @Jay_Heavner since it looks like you are an expert :slight_smile:

Could you have a look into this question for me?

Interesting @sender could you Share your flow for play pause etc ?

Hi, here it is. But I would also like some help with my question :slight_smile:

I will not share my wntrie flow due to I think that will also share mu spotify id and crendtials.

But here is office device id function (to select alexa in the office):
msg.params = [ {deviceIds: ["85202189a6blablsca22818c7383"], play: 'true'} ]; return msg;
Other id plays another room. device id you can find somewhere in the online api tool from spotify.

my question is regarding “selecting” a playlist…

BTW i think I will never use pause or play via spotify due to I do that with alexa pause/play.

1 Like

hi, thanks for sharing to see
where did you get this id ?

See post above.

Hi, I need help!
How did you install “guery-string” I am running node-red in Home Assistant on a VM. I can see the settings.js file and can edit it, but don’t know what to put there. My issue is the code “querystring.stringify(…)” is returning nothing. I am trying to get this working.

Any details and examples you could share would be great.
Thanks

The easiest way is to get a console and npm i query-string. You’ll then need to add that as an external package.

Here’s the documentation https://nodered.org/docs/user-guide/writing-functions#loading-additional-modules

This Node API for Spotify is the most complicated thing I have came across not straight forward

There is no proper documentation on how to setup the flows and what goes where

what do you need help with?

your best bet will be to understand the API

if you need help with a specific command let us know