# Bearer auth on http request

**URL:** <https://discourse.nodered.org/t/bearer-auth-on-http-request/8137>\
**Category:** General\
**Created:** [19 February 2019 08:49 UTC](https://discourse.nodered.org/t/bearer-auth-on-http-request/8137 "2019-02-19T08:49:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cyderbot97](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@cyderbot97](https://discourse.nodered.org/u/cyderbot97)\
**Post date:** [19 February 2019 08:49 UTC](https://discourse.nodered.org/t/bearer-auth-on-http-request/8137/1 "2019-02-19T08:49:02Z")

</div>

Hello,

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

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,

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [19 February 2019 09:04 UTC](https://discourse.nodered.org/t/bearer-auth-on-http-request/8137/2 "2019-02-19T09:04:52Z")

</div>

Hi @cyderbot97

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![cyderbot97](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@cyderbot97](https://discourse.nodered.org/u/cyderbot97)\
**Post date:** [19 February 2019 09:25 UTC](https://discourse.nodered.org/t/bearer-auth-on-http-request/8137/3 "2019-02-19T09:25:37Z")

</div>

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 :

 ![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c317167cc58a2858a208a9e2f455354aa59954a1.png)

```auto
[{"id":"a4a33996.4e6aa","type":"http request","z":"e392a5e8.058d1","name":"","method":"PUT","ret":"obj","url":"https://online.wonderware.eu/apis/upload/datasource","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":[]}]

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [19 February 2019 09:34 UTC](https://discourse.nodered.org/t/bearer-auth-on-http-request/8137/4 "2019-02-19T09:34:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cyderbot97](https://avatars.discourse-cdn.com/v4/letter/c/4af34b/32.png) [@cyderbot97](https://discourse.nodered.org/u/cyderbot97)\
**Post date:** [19 February 2019 09:38 UTC](https://discourse.nodered.org/t/bearer-auth-on-http-request/8137/5 "2019-02-19T09:38:42Z")

</div>

THANKS !  
I have change to UTF8 string and it work !  
Thanks you 😃
