How do I link a HTTP Response (PUT) for login with a HTTP response (Get), such that credentials are used in the GET

I have a two flows - HTTP response (PUT) which logs me into my restAPI of my switch using https://{host}/restapi/vXX/login?username=xxxxxx&password=xxxxxx
I can successfully login
The second flow HTTP response (GET) which pulls the status of my interfaces does not work as it reporting unauthorized. I have tried to take the cookie and Authorization (base64code) with the request with no success. I have the same configuration working in postman

You will need to supply more info if you require help

Copies of the complete messages from the http nodes.
Any error messages.
The Postman info.
Any documentation for the rest api of the switch.

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

This is a very poor way to pass the uid/password. You should never put those details into the URL. As this is a PUT, can you not pass them as JSON in the body instead? Indeed, this might be the cause of your issue anyway.

After logging in with:

and running this command

The relates to this url: Reddit - Dive into anything

Not sure how to insert the set-cookies in the GET

From the login flow, store necessary headers in context (use change node after the request to set flow.cookie)

Then on the 2nd flow (the GET flow) add the stored headers. (Use a change node before the request to copy flow.cookies in to msg.headers)

Tried with set flow.cookie and copy (move) flow.cookies into the msg.header with no success. I even tried set msg.header and copy (move) msg.header into the msg.header with no success

If they are in different flow tabs then you will need to use global context rather than flow.

Same problem, the data from flow1 is never seen in flow2

Does it appear in the global context panel on the RHS?

image

I have information in flow but nothing in global

Did you set the headers in the msg that goes into your 2nd request (the GET request?)

Just in case you don't realise, storing something in context (global or flow) is just storage. It has nothing to do with your HTTP request.

In other words, you need to take the stored value and add it to the message that goes into the request node.

To verify that you have the right things in the right place, add a debug before the HTTP request GET and verify the correct headers are set in msg.headers object.


Nothing is sent

In your previous screenshot, global.cookies was empty & flow.cookies had something. In your latest screenshot, you have a change node that moved nothing (global.cookies) into the flow.cookies which did have something. Now, unsurprisingly it has nothing.

I think you are missing some fundamental basics here. You were supposed to set the msg.headers before the msg is sent to the request node


Are you new to node-red?

Just in case, here are some materials that might help...

I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

https://cookbook.nodered.org/http/set-request-header

https://nodered.org/docs/user-guide/context

Also, as you get more familiar with the msg concept, head back to my previous post - it will likely make more sense after a bit learning...

I think there is an issue with Node-Red as I have been around this prior. I have already built this in postman and it is working fine. I have two flows, I run the first one and then the second.

Why are you moving global.cookies - it will literally MOVE it out of global. it will be deleted. That's what move does. Leave it there. Use set (not move)

Next, where are you moving it to?

Lastly have you checked the output of debug 8? Does it contain msg.headers?
(Hint: set debug 8 to show the entire message)

Trust me, the issue is almost always between the keyboard and the chair :wink:

I moved into the flow cookies. Trust, I tried set flow cookies from global on the second flow w/o success. I am using the docker version, with node red version 3.0 but I can clearly tell you there is an issue with Node Red, based on all the information I read over the weekend. The link I provided above is similar to what another user saw, and where postman is solid

Current version of node-red is 4.0.2. V3.0.0 was quickly superseded by 3.0.2 as it had some issues.

There was no conclusion on that link. There was one user who linked to the cook book and his issues were solved.

Until we can prove there is a bug, let's ignore external resources where there was no thorough information provided and no conclusion & Instead get the real facts. Please answer the questions I posed in previous messages.

Also, select the relevant nodes in your flow and export them so I can check what you are doing.