Bearer auth on http request



I need your help, first sorry for my bad english, i'm french :confused:

How can i made an http request with bearer token authentification to put json code. I have just one option " basic authentification" on http request nodes.

Thanks for all,



Hi @cyderbot97

you can create the required http header yourself in a Function node and pass it in to the HTTP Request node:

msg.headers = {
    Authorization: "Bearer "+YOUR_TOKEN_HERE
return msg;

We are also just about to merge a change that adds Bearer auth into the node's configuration options - but for now, the example above will let you do it.

1 Like


Thanks for your fast reply !

I have tried your solution but i have a json parse error
I think, i've made a mistake.
This is what i did :

[{"id":"a4a33996.4e6aa","type":"http request","z":"e392a5e8.058d1","name":"","method":"PUT","ret":"obj","url":"","tls":"","x":630,"y":400,"wires":[["bb52d3a.c9bda3"]]},{"id":"a1020ca2.c78ed8","type":"function","z":"e392a5e8.058d1","name":"","func":"msg.headers = {\n    Authorization: \"Bearer \" + \"xxxxx\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":400,"wires":[["a4a33996.4e6aa"]]},{"id":"faa74fdb.3d587","type":"inject","z":"e392a5e8.058d1","name":"","topic":"","payload":"{    \"data\": [      {                \"Reactor3.Level\": 1.51860072870498,        \"Reactor3.Temp\": 27.1360543141452,        \"Reactor3.InletValve\": 0,        \"Reactor3.Step\": 7,        \"Line3.Units\": 1518,        \"Line3.Product\": \"zeubi\"      }]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":400,"wires":[["a1020ca2.c78ed8"]]},{"id":"bb52d3a.c9bda3","type":"debug","z":"e392a5e8.058d1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":890,"y":400,"wires":[]}]


I do not have a valid bearer token to try that flow.

What error are you getting?

You have configured the request node to return a parsed JSON object - if you are getting an error from that, change it to return a UTF8 string so you can see what it is returning and check it really is valid JSON.



I have change to UTF8 string and it work !
Thanks you :smiley: