Http get socket hang up!

I'm trying to send a http get request to my API to get json data. To access my API I need to pass a token in the http.header. The Node-red runs on a Simatic IOT2040 and my API is running local on my PC. With postman I can get the json response .

I have created a node but gets the folowing error:

This is my node:
[{"id":"fd84bd47.81a15","type":"http request","z":"af66aab4.ccac18","name":"GET from API","method":"GET","ret":"txt","url":"","tls":"","x":715,"y":515,"wires":[["4d2ca3ad.a559cc"]]}]

In the debug tab I get the following errors

you will need a change node or function node before that set set your msg.headers as you need.

Thank you for answearing. I added a change node . But I think I did not catch exactly your idea .
[{"id":"fd84bd47.81a15","type":"http request","z":"af66aab4.ccac18","name":"GET from API","method":"GET","ret":"txt","url":"","tls":"","x":715,"y":515,"wires":[["4d2ca3ad.a559cc"]]}]

There is no change node in the flow you shared. Can you repost the flow so we can have a look on how you are setting msg.headers ?

1 Like

Sorry, this one should be the actual

[{"id":"aaaed146.84448","type":"inject","z":"af66aab4.ccac18","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":189,"y":521,"wires":[["66d11064.8fde8"]]},{"id":"fd84bd47.81a15","type":"http request","z":"af66aab4.ccac18","name":"GET from API","method":"GET","ret":"txt","url":"","tls":"","x":715,"y":515,"wires":[["4d2ca3ad.a559cc"]]},{"id":"66d11064.8fde8","type":"function","z":"af66aab4.ccac18","name":"set payload and headers","func":"msg.headers = {};\nmsg.headers={ \n    'my_Token':  '123456789',\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":409,"y":520,"wires":[["243ecf40.745f4"]]},{"id":"4d2ca3ad.a559cc","type":"debug","z":"af66aab4.ccac18","name":"","active":false,"console":"false","complete":"false","x":942,"y":515,"wires":[]},{"id":"243ecf40.745f4","type":"change","z":"af66aab4.ccac18","name":"header","rules":[{"t":"set","p":"headers","pt":"msg","to":"123456789","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":573.5,"y":436,"wires":[["fd84bd47.81a15"]]}]

You added a change node after the function node. It happens that the change node is undoing the msg.header. What happens if you just remove the change node ?

The first version was like that with the same error.

I have 3 big questions

  1. If my http.header is in correct form
  2. I dont understand that basic authentication where I use it
    3 can be problem that I m trying to send a http request from another device than the device in which is running localy the API?

Those are good questions.

This is the code in your function node:

msg.headers = {};
    'my_Token':  '123456789',

return msg;

If your goal is to configure the Authentication header then this should be rewriten. However I have no idea on how your API works. Based on the first picture you posted, my impression is that you were using postman to send the token as an URL parameter, not as part of the header (but I may be wrong). I don´t use postman (use insomnia instead) but if you have a way to show better how do you manage to make it work with postman then, perhaps, someone will be able to understand and provide some suggestion.