# Example using http-request node with Basic authorization

**URL:** <https://discourse.nodered.org/t/example-using-http-request-node-with-basic-authorization/28205>\
**Category:** General\
**Created:** [11 June 2020 22:58 UTC](https://discourse.nodered.org/t/example-using-http-request-node-with-basic-authorization/28205 "2020-06-11T22:58:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozdw](https://avatars.discourse-cdn.com/v4/letter/o/4af34b/32.png) [@ozdw](https://discourse.nodered.org/u/ozdw)\
**Post date:** [11 June 2020 22:58 UTC](https://discourse.nodered.org/t/example-using-http-request-node-with-basic-authorization/28205/1 "2020-06-11T22:58:38Z")

</div>

I have googled and read for hours but have yet to find an example that works. I am invoking the Solcast API, which requires Basic auth and only a username containing an API key but no password.

The issue is I need to pass the username via msg.headers. When I include the username in the node properties dialog, the API call works fine, but I cannot seem to get it right passing it in msg.headers. The last code I tried, which didn't work, was this:

```auto
msg.headers = {};
APIkey = flow.get('APIkey');
var auth = 'Basic ' + new Buffer(APIkey).toString('base64');
//var auth = 'Basic ' + APIkey;

msg.ResourceID = flow.get('ResourceID');
msg.headers = {
    "Authorization": auth
}
return msg;

```

Any help is greatly appreciated.

dave

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [12 June 2020 06:41 UTC](https://discourse.nodered.org/t/example-using-http-request-node-with-basic-authorization/28205/2 "2020-06-12T06:41:08Z")

</div>

Normally the format is `Basic user:password` (with the user:password part base64 encoded)

See [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization)

---

<div class="post-metadata">

**Author:** ![ozdw](https://avatars.discourse-cdn.com/v4/letter/o/4af34b/32.png) [@ozdw](https://discourse.nodered.org/u/ozdw)\
**Post date:** [12 June 2020 06:53 UTC](https://discourse.nodered.org/t/example-using-http-request-node-with-basic-authorization/28205/3 "2020-06-12T06:53:23Z")

</div>

Steve, that was very close to what I was using. Since the API doesn't need a password, I was not including the ":". I just tried including the colon and now it works. I could've sworn I tried that before, but I guess not. 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:** [26 June 2020 06:53 UTC](https://discourse.nodered.org/t/example-using-http-request-node-with-basic-authorization/28205/4 "2020-06-26T06:53:35Z")

</div>

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