HTTP Request node question

I am using a Node Red Alexa node that asks for me to renew my token from time to time by simply login in to 192.168.1.57:3456 (my Home Assistant IP).

I would think, usually a bad sign, that a simple HTTP request node would do this. But that is where my expertise ends.

This is what the node is asking for:

open in browser

If I open 192.168.1.57:3456 in my browser, I am prompted for my Amazon password, then told that my token is renewed and to close the browser.

flow

So, is HTTP request the correct node to accomplish this?
Which method? Put, for example, returns a 405 error:

put

Also, if I put the address into my browser again, I get a 404 error.

My goal is to open the address once every day to keep the token refreshed. A 404 error is inconsequential and to be ignored.

No http request will not work, the ip:3456 is a temp proxy address opened by the alexa remote2 node to allow authorization.

I find it best to save the authorization to flow context, and reinitialise every 24hrs and use the saved cookie in flow context
e.g.

[{"id":"48d034130f262ec8","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"86400","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"#:(file)::alexa","payloadType":"flow","x":190,"y":2060,"wires":[["f78696691771c3ee"]]},{"id":"3b6342b82af27c5f","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"#:(file)::alexa","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":2060,"wires":[[]]},{"id":"f78696691771c3ee","type":"alexa-remote-init","z":"b779de97.b1b46","name":"","account":"c8738129.d902c","option":"initialise","x":380,"y":2060,"wires":[["3b6342b82af27c5f"]]},{"id":"c8738129.d902c","type":"alexa-remote-account","name":"alexa remote 2","authMethod":"proxy","proxyOwnIp":"localhost","proxyPort":"3456","cookieFile":"","refreshInterval":"14","alexaServiceHost":"layla.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-GB","onKeywordInLanguage":"","userAgent":"","useWsMqtt":"on","autoInit":"off"}]

You then turn off auto int in the config node.


You then log on using proxy, after done once the saved auth payload will do the auth update every 24 hrs. I haven't need to manually log in for over a year.

Thanks. This makes sense, but where do I find the cookie data to save in the flow context?

When you press the inject button, first time you will see a message "open ip:3456 on browser" under the initialise node. log in as before on that proxy page. the change node then saves the auth cookie return by the initialise node. next time you press inject or every 24hrs the saved auth is sent to the initialise node, and authorises you without having to use the browser proxy address.

Make sure the context is using file and not memory.

Now it's making sense. Thanks for the assist.
But, now I can't log in on the proxy page. (Probably unrelated).
My browser takes me to an Amazon page. It's never done that before.

Also, my nodes are saying "Port 3456 is already in use where they formerly said to open IP:3456.

port 3456 is already in use

Ant the Initialize Node is a bit different, also, saying to open localhost:3456 instead of the IP:3456.

flow

Never seen that login before, no idea there

The initialise node needs to be the only one using the config and the auto int needs to be off in that config.

ip or localhost depends if you are on same machine as node-red.

Thanks- Making more progress here.
I had some issues until I realized that you are in the UK. I changed my Service Host and it appears that everything is working.

Is there a way to verify it? Also, how can I make the flow save to file?

Not sure what you mean by verify it.

If you mean a text file you can use file read and write nodes.
If you mean file context storage, then you need to edit your settings file
https://nodered.org/docs/user-guide/context#context-stores

I did not know tht option existed- thanks.
So it's as simple as adding:

contextStorage: {
   default: {
       module: "localfilesystem"
   }
}

to my settings.js file?

Now, where would the files be saved since I don't have a /.node-red folder?
(My NodeRed is an addon in Home Assistant, but you probably already figured that out).

No idea I do not use HA. Maybe ask on the HA forum Node-red section.
As to adding to settings file, there should be a section of the file already there, you probably just need to edit it or uncomment it. As always make a copy first.

@E1cid Thanks. I have it working as needed. Perhaps too well. Apparently every context is going to file because In just two days my context folder is 1.5MB.

sudo du -sh /root/config/node-red/context
 1.5M    /root/config/node-red/context

This is what I put into my settings.js file:

    // Save context data to the file-system
    // Context files are saved in /root/config/node-red/context
    // To see the disk used: sudo du -sh /root/config/node-red/context
    contextStorage: {
        default: {
        module: 'localfilesystem'
        }
   }

However, the context data that I need to survive a restart is only written once a day (an Amazon token). All other context variables are volatile and don't need to be saved.

I saw this in some of my searching:

contextStorage: {
  default: "file",
  memoryOnly: { module: 'memory' },
  file: { module: 'localfilesystem' }
},

So here's my latest question.
I am guessing that this will take care of the defaults, but how do I specify which context variable is saved in the filesystem?

contextStorage: {
  default: "memoryOnly",
  memoryOnly: { module: 'memory' },
  file: { module: 'localfilesystem' }
},

Thanks again.

In the change nodes & other nodes that permit, you will see a selector for which context store.

In function nodes, check the function signature auto completion help (assuming you are using a recent version of node-red & have Monaco editor selected) OR read the help : Writing Functions : Node-RED

In the change node you select the context in the rule.

1 Like

I appreciate that you didn't tell me to RTFM, because it is mostly there.

I also stumbled onto a YouTube video that explains the subject very well.

Again, your patience is appreciated.

BTW, where are you? I am assuming somewhere in Europe because of the timing of your assistance responses. (Boston, USA here).

You seem to have had a search, so thought you may of just missed it.
I'm in the UK,

We will be there for a few days this summer, but would like to come back and spend a month or two driving around the country.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.