# Passing Bearer Token Not Working

**URL:** <https://discourse.nodered.org/t/passing-bearer-token-not-working/25786>\
**Category:** General\
**Created:** [30 April 2020 03:47 UTC](https://discourse.nodered.org/t/passing-bearer-token-not-working/25786 "2020-04-30T03:47:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikeh](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mikeh](https://discourse.nodered.org/u/mikeh)\
**Post date:** [30 April 2020 03:47 UTC](https://discourse.nodered.org/t/passing-bearer-token-not-working/25786/1 "2020-04-30T03:47:37Z")

</div>

I was trying to pass the API key from a function:  
msg.headers = {};  
msg.headers['Authorization'] = "Bearer "+ msg.payload.token;  
return msg;

 ![node-red-2020-04-30_1128](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/11b30dc42e1ed9ee13e2a9a1ef705b60e570fdf9.png)

I keep on getting 401 error.  
But when I copied the entire API key to the http request node \> Token field it works without problem.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7afbc1409994df45b373bc4ee24f4a6b2744f7ce.png)

What seems to be the problem here?

---

<div class="post-metadata">

**Author:** ![mikeh](https://avatars.discourse-cdn.com/v4/letter/m/258eb7/32.png) [@mikeh](https://discourse.nodered.org/u/mikeh)\
**Post date:** [30 April 2020 03:50 UTC](https://discourse.nodered.org/t/passing-bearer-token-not-working/25786/2 "2020-04-30T03:50:56Z")

</div>

![node-red-2020-04-30_1149](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d2db80841ad09dba724e21e76820ab00ab9bc7f9.png)

But when I switched it to "basic authentication", everything works!  
This is weird.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [29 June 2020 03:50 UTC](https://discourse.nodered.org/t/passing-bearer-token-not-working/25786/3 "2020-06-29T03:50:59Z")

</div>

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