# Passing Bearer Token "Can't Convert Access Token to JSON"

**URL:** https://discourse.nodered.org/t/passing-bearer-token-cant-convert-access-token-to-json/48314
**Category:** General
**Created:** [12 July 2021 13:03 UTC](https://discourse.nodered.org/t/passing-bearer-token-cant-convert-access-token-to-json/48314 "2021-07-12T13:03:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![hawks76](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@hawks76](https://discourse.nodered.org/u/hawks76)
#### Post date: [12 July 2021 13:03 UTC](https://discourse.nodered.org/t/passing-bearer-token-cant-convert-access-token-to-json/48314/1 "2021-07-12T13:03:48Z")

</div>

So i have a curl command that goes out to a Whirlpool API and pulls down some JSON. I use OAuth2 and i can get the token back no problem, but when i pass the token in a msg.headers to the http request node, i always get back this response:

{"error":"invalid\_token","error\_description":"Cannot convert access token to JSON"}

I've tried to copy the token directly into the http node with bearer authentication turned on and i get the same response.  
Here is my curl command that works fine:  
curl -XGET -H "Authorization: Bearer ${TOKEN}" -H "Content-type: application/json" '[https://api.whrcloud.com/api/v1/appliance/xxxxxxxxxxxxx](https://api.whrcloud.com/api/v1/appliance/xxxxxxxxxxxxx)'

I've google and checked the forums, but just haven't come up with a solution to this.

Thanks

---

<div class="post-metadata">

### Author: ![burtonboucher](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/burtonboucher/32/7806_2.png) [@burtonboucher](https://discourse.nodered.org/u/burtonboucher)
#### Post date: [17 July 2021 17:07 UTC](https://discourse.nodered.org/t/passing-bearer-token-cant-convert-access-token-to-json/48314/2 "2021-07-17T17:07:55Z")

</div>

I put the token in header “Authorization”:”Bearer “ + mytoken

I do not include application/json header.

I use default settings in http request node except my return type “a parsed json object” which is expected return type. Can leave default UTF-8 to test

What I found helpful is to use PostMan. Get it working there and then do Code -\> Dart - http and copy the Uri.parse for the url and copy var headers section minus the Cookie.  
I then add this to a function node prior to my http node.  
msg.url=“…”;  
msg.headers={…}

---

<div class="post-metadata">

### Author: ![hawks76](https://avatars.discourse-cdn.com/v4/letter/h/46a35a/32.png) [@hawks76](https://discourse.nodered.org/u/hawks76)
#### Post date: [18 July 2021 15:12 UTC](https://discourse.nodered.org/t/passing-bearer-token-cant-convert-access-token-to-json/48314/3 "2021-07-18T15:12:26Z")

</div>

> [@burtonboucher](#):
>
> “Authorization”:”Bearer “ + mytoken

Thanks for the input. Figured out i was passing the username and password to get the token wrong (using client credentials and passing as headers instead of using Password). While it was returning a token, discovered the length was different from what was getting anywhere else and that led me to do digging on the oauth2 token call. Everything is working now.

Thanks

---

<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: [16 September 2021 15:13 UTC](https://discourse.nodered.org/t/passing-bearer-token-cant-convert-access-token-to-json/48314/4 "2021-09-16T15:13:01Z")

</div>

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