# Filling http request field automatically

**URL:** <https://discourse.nodered.org/t/filling-http-request-field-automatically/11239>\
**Category:** General\
**Created:** [17 May 2019 11:56 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239 "2019-05-17T11:56:16Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DillonW](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@DillonW](https://discourse.nodered.org/u/DillonW)\
**Post date:** [17 May 2019 11:56 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/1 "2019-05-17T11:56:16Z")

</div>

Hi,  
I am using two seperate http request nodes separately to access a service's api in Node-Red.  
The first one requests a token used for an extra level of authentication which is returned in the debug tab. The second requires this token, but I want to know if there is any way to automatically get the token into the authentication field, any help would be appreciated. Pictures are below.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3a77ee1747d59806b347bb29e0fbc4046776a785.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/17ed375bb4e201cc9b583e2e5d30967c37c7559e.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3db4bb9ce07f6e9953183a58cb4a52da6e568b02.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3f13596adefa6a7cae02f7e00b9b25f5f8bc4615.png)

So far I can only manual set the following fields: Use authenticaton, type, username, password and token. Is there ways to automatically set at least the passwords if not 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:** [17 May 2019 12:03 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/2 "2019-05-17T12:03:07Z")

</div>

Hi @DillonW

the HTTP Request node does not let you provide the username/password fields through msg properties. But you can set the required HTTP headers yourself - which achieves the same result.

Leave the 'use authentication' box unticked and in a Function node do:

```auto
msg.headers = {};
msg.headers['Authorization'] = "Bearer "+YOUR_ACCESS_TOKEN
return msg;

```

Obviously you have to figure out where to get `YOUR_ACCESS_TOKEN` from...

---

<div class="post-metadata">

**Author:** ![DillonW](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@DillonW](https://discourse.nodered.org/u/DillonW)\
**Post date:** [17 May 2019 12:45 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/3 "2019-05-17T12:45:53Z")

</div>

Hi, I have done an attempt. I tried storing the token received from the first http request node into a flow variable and then use this in the function as you said. But this gave an error as shown.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8cca2be152825a5825986a98078bced6cf74a2ae.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cc875dc570f33d3cdc024f68333d7cd4b77e6073.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/90d302dbaee5f8b439bceb5114c26f6859dc27f1.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/38a1ad3440108e8911da1a0a1fe654ff0df05c6d.png)

But if I manually copied it into the field(after trying this way first) it works in the copied format.

---

<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:** [17 May 2019 12:51 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/4 "2019-05-17T12:51:01Z")

</div>

It looks like you are missing a space after the word `Bearer`. Your code is generating a header like: `BearerYOUTOKEN` where it should be `Bearer YOURTOKEN`.

---

<div class="post-metadata">

**Author:** ![DillonW](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@DillonW](https://discourse.nodered.org/u/DillonW)\
**Post date:** [17 May 2019 12:58 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/5 "2019-05-17T12:58:30Z")

</div>

tried adding the space, still get the same error. I've checked the output and the token is the same as from the first request node.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/acd7a0495da37dab4858ef20ac99253bd2cc8617.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a1ba781a9575565c227dc0c8b6e0e8c9279209df.png)

---

<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:** [17 May 2019 13:03 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/6 "2019-05-17T13:03:13Z")

</div>

I don't know what to suggest... that _is_ the right format for the Bearer header.

At this point I would use something like [https://requestbin.fullcontact.com](https://requestbin.fullcontact.com/) in order to compare the exact requests sent when the token is hardcoded into the node versus when you set the header.

---

<div class="post-metadata">

**Author:** ![DillonW](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@DillonW](https://discourse.nodered.org/u/DillonW)\
**Post date:** [20 May 2019 10:16 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/7 "2019-05-20T10:16:37Z")

</div>

I tried adding the links to the site, but it doesn't register, always changes back to the default, is that normal? Any other ways to check?

Thanks. It still hasn't worked thus far

---

<div class="post-metadata">

**Author:** ![zouhir](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zouhir](https://discourse.nodered.org/u/zouhir)\
**Post date:** [24 June 2022 15:10 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/8 "2022-06-24T15:10:00Z")

</div>

> [@knolleary](#):
>
> ```auto
> msg.headers = {};
> msg.headers['Authorization'] = "Bearer "+YOUR_ACCESS_TOKEN
> return msg;
> 
> ```

Hi @DillonW, where you able to solve this issue ?

---

<div class="post-metadata">

**Author:** ![pzarczyn](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@pzarczyn](https://discourse.nodered.org/u/pzarczyn)\
**Post date:** [16 September 2022 14:14 UTC](https://discourse.nodered.org/t/filling-http-request-field-automatically/11239/9 "2022-09-16T14:14:31Z")

</div>

I can confirm this work for me pretty good!
