# Struggling to authenticate to API in Node-RED but works in Postman

**URL:** <https://discourse.nodered.org/t/struggling-to-authenticate-to-api-in-node-red-but-works-in-postman/74100>\
**Category:** General\
**Tags:** http-request, security\
**Created:** [24 January 2023 02:32 UTC](https://discourse.nodered.org/t/struggling-to-authenticate-to-api-in-node-red-but-works-in-postman/74100 "2023-01-24T02:32:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phasor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phasor/32/74921_2.png) [@phasor](https://discourse.nodered.org/u/phasor)\
**Post date:** [24 January 2023 02:32 UTC](https://discourse.nodered.org/t/struggling-to-authenticate-to-api-in-node-red-but-works-in-postman/74100/1 "2023-01-24T02:32:08Z")

</div>

Would appreciate a little help as a Node-RED noob please.

I'm trying to authenticate to an API within Node-RED and the developers have used either HTTP Basic Authorization or JSON POST.

So my first step was to test the HTTP Basic Authorization in Postman:

I used the POST method  
and under Auth selected "Basic Auth"  
and then entered my Username and Password

When I click send the Body comes back with an array of objects and the one of interest to me is the token which is a string that I will be able to use to authenticate subsequent queries to the API presumably.

Two questions:

1. How can I replicate this Basic Auth in Node-RED and return the token? And would it be better to JSON POST instead and if so how to go about doing that?
2. How can I use the token in my subsequent requests to the API?

There is alot of information online about public API's when you can use a key. Would appreciate any words from the wise.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [24 January 2023 06:34 UTC](https://discourse.nodered.org/t/struggling-to-authenticate-to-api-in-node-red-but-works-in-postman/74100/2 "2023-01-24T06:34:05Z")

</div>

A basic auth request is already built-in

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/9895e95185edaa408978186ef4e7dcf36f5f283f.png)

Did you try this ?

---

<div class="post-metadata">

**Author:** ![phasor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/phasor/32/74921_2.png) [@phasor](https://discourse.nodered.org/u/phasor)\
**Post date:** [15 February 2023 06:39 UTC](https://discourse.nodered.org/t/struggling-to-authenticate-to-api-in-node-red-but-works-in-postman/74100/3 "2023-02-15T06:39:27Z")

</div>

Thank you for your reply. Apologies for the delay in a return post. I ended up abandoning the API integration and using an MQTT broker which I set up as an intermediary between the modbus gateway that I needed to communicate with and the end points. MQTT works very well. Still struggling with authentication on the MosQuiTTo broker so I think I've for now turned off the passwords to test comms and will re-enable them when I move this system into production.

I do need to learn the API method but I'm finding the vendors documentation to be quite weak. Wasting a lot of time trying to improve it and eventually said let me try another method

---

<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 April 2023 06:39 UTC](https://discourse.nodered.org/t/struggling-to-authenticate-to-api-in-node-red-but-works-in-postman/74100/4 "2023-04-16T06:39:49Z")

</div>

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