# Http get with header problem

**URL:** https://discourse.nodered.org/t/http-get-with-header-problem/42440
**Category:** General
**Created:** [11 March 2021 01:22 UTC](https://discourse.nodered.org/t/http-get-with-header-problem/42440 "2021-03-11T01:22:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![umtksa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/umtksa/32/38322_2.png) [@umtksa](https://discourse.nodered.org/u/umtksa)
#### Post date: [11 March 2021 01:22 UTC](https://discourse.nodered.org/t/http-get-with-header-problem/42440/1 "2021-03-11T01:22:52Z")

</div>

Hi all I'm getting data from an api with a bearer token.  
when I enter bearer token to http node I can connect to server and get my api data  
when ever token expires I copy the new one and paste it to http node and deploy ://  
I'm trying to come up with an easy solution for this situation.

So I'm listening [http://192.168.1.45:1880/google](http://192.168.1.45:1880/google) to get new token messages sent from my phone by siri shortcuts (just a post request to [http://192.168.1.46:1880/google?token=blablablablablablablablabla](http://192.168.1.46:1880/google?token=blablablablablablablablabla))  
but I cannot use this token as header of my post request I tried alot of combinations without success

here is my flow

```auto
[{"id":"8df21d5.cdb3ae","type":"http in","z":"f5f01ef7.09a1a","name":"","url":"/google","method":"get","upload":false,"swaggerDoc":"","x":250,"y":740,"wires":[["54c1e70d.ab3e18","59335758.c6cb9"]]},{"id":"54c1e70d.ab3e18","type":"template","z":"f5f01ef7.09a1a","name":"page","field":"payload","fieldType":"msg","format":"html","syntax":"plain","template":"<html>\n <head></head>\n <body>\n <h1>THANKS</h1>\n </body>\n</html>","x":270,"y":840,"wires":[["266c286f.d993d8"]]},{"id":"266c286f.d993d8","type":"http response","z":"f5f01ef7.09a1a","name":"","x":410,"y":840,"wires":[]},{"id":"a2cbddc7.1cd338","type":"debug","z":"f5f01ef7.09a1a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":740,"wires":[]},{"id":"59335758.c6cb9","type":"json","z":"f5f01ef7.09a1a","name":"","property":"token","action":"obj","pretty":false,"x":430,"y":740,"wires":[["ec79908c.6fb2"]]},{"id":"ec79908c.6fb2","type":"change","z":"f5f01ef7.09a1a","name":"","rules":[{"t":"set","p":"globtoken","pt":"flow","to":"payload.token","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":740,"wires":[["a2cbddc7.1cd338"]]},{"id":"435adb93.9ee1dc","type":"http request","z":"f5f01ef7.09a1a","name":"","method":"GET","ret":"txt","paytoqs":"body","url":"testest.com","tls":"","persist":false,"proxy":"","authType":"bearer","x":630,"y":940,"wires":[["a7d99da4.5cd938"]]},{"id":"8d5dcc1.db91ab","type":"inject","z":"f5f01ef7.09a1a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":940,"wires":[["1594a5cc.91a492"]]},{"id":"d0e2df30.a484f","type":"ui_text","z":"f5f01ef7.09a1a","group":"8f918d7.5af32f","order":4,"width":2,"height":2,"name":"","label":"","format":"{{msg.online}}","layout":"col-center","x":1150,"y":940,"wires":[]},{"id":"a7d99da4.5cd938","type":"json","z":"f5f01ef7.09a1a","name":"","property":"payload","action":"obj","pretty":false,"x":790,"y":940,"wires":[["2c25c5f6.75fd6a"]]},{"id":"2c25c5f6.75fd6a","type":"change","z":"f5f01ef7.09a1a","name":"","rules":[{"t":"set","p":"online","pt":"msg","to":"payload.totalsForAllResults[\"rt:activeUsers\"]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":940,"wires":[["d0e2df30.a484f"]]},{"id":"1594a5cc.91a492","type":"function","z":"f5f01ef7.09a1a","name":"","func":"var tokengelen = flow.get('globtoken');\nvar bearer = 'Bearer ' + tokengelen;\n\nmsg.headers = {\n 'Authorization': bearer, \n \"Content-Type\" : \"application/json\"\n};\n\nmsg.payload = {\n \n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":940,"wires":[["435adb93.9ee1dc"]]},{"id":"8f918d7.5af32f","type":"ui_group","name":"all","tab":"c1dcfb03.ffed9","order":5,"disp":false,"width":13,"collapse":false},{"id":"c1dcfb03.ffed9","type":"ui_tab","name":"dash","icon":"dashboard","order":1}]

```

and here is my failed function

```auto
var tokengelen = flow.get('globtoken');
var bearer = 'Bearer ' + tokengelen;

msg.headers = {
  'Authorization': bearer, 
  "Content-Type" : "application/json"
};

msg.payload = {
  
}

return msg;

```

thanks alot ✌

---

<div class="post-metadata">

### Author: ![henrycosta05](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/henrycosta05/32/36350_2.png) [@henrycosta05](https://discourse.nodered.org/u/henrycosta05)
#### Post date: [11 March 2021 03:09 UTC](https://discourse.nodered.org/t/http-get-with-header-problem/42440/2 "2021-03-11T03:09:43Z")

</div>

hi @umtksa,  
unfortunatly I do not know yout api data, because of that I cant help you with functions if nedded. but you could debug msg{} imediatelly after HTTP request just to see payload from your api.

in your http request I noticed that you checked "use authentication"...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/ba5e49d474275fd82f0c1048ed8c38e6270b818a.png)  
you already tried with unchecked field?

---

<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: [10 May 2021 03:10 UTC](https://discourse.nodered.org/t/http-get-with-header-problem/42440/3 "2021-05-10T03:10:01Z")

</div>

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