# Using fetch within endpoints registered with RED.httpadmin

**URL:** https://discourse.nodered.org/t/using-fetch-within-endpoints-registered-with-red-httpadmin/92634
**Category:** General
**Created:** [24 October 2024 12:09 UTC](https://discourse.nodered.org/t/using-fetch-within-endpoints-registered-with-red-httpadmin/92634 "2024-10-24T12:09:27Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![malee](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@malee](https://discourse.nodered.org/u/malee)
#### Post date: [24 October 2024 12:09 UTC](https://discourse.nodered.org/t/using-fetch-within-endpoints-registered-with-red-httpadmin/92634/1 "2024-10-24T12:09:27Z")

</div>

it has been noticed that with

> $.ajax

That the requests to server side API calls are injected with a bearer token as a header. This authenticates the request if adminAuth is enabled in the settings.js file.

If fetch is used within the registered endpoint then this token is not injected and the request is unauthorized a 401 error is thrown.

Is there a way of accessing this token and adding it as a header to the fetch request?

---

<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: [24 October 2024 12:31 UTC](https://discourse.nodered.org/t/using-fetch-within-endpoints-registered-with-red-httpadmin/92634/2 "2024-10-24T12:31:22Z")

</div>

Have a look in `localstorage` for the site

PS, if you are developing a node, then this should be in #Developing Nodes or if this is for a core pull request, then #Core Development

---

<div class="post-metadata">

### Author: ![malee](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@malee](https://discourse.nodered.org/u/malee)
#### Post date: [24 October 2024 12:44 UTC](https://discourse.nodered.org/t/using-fetch-within-endpoints-registered-with-red-httpadmin/92634/3 "2024-10-24T12:44:45Z")

</div>

I did and found the

> auth-token

, however it has an expires\_in property. Does this property value get updated from time to time?

I am just wondering if there is an already defined method within Node RED for extracting the token and verifying its validity. i.e. is still valid/not expired.

---

<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: [24 October 2024 12:49 UTC](https://discourse.nodered.org/t/using-fetch-within-endpoints-registered-with-red-httpadmin/92634/4 "2024-10-24T12:49:36Z")

</div>

Hi @malee

How and where the token is stored inside the editor is an internal implementation detail that could well change in the future as we reconsider some of the use of localStorage. So I would carefully consider whether it's worth the maintenance overhead just to get to use `fetch` rather than the included client.

---

<div class="post-metadata">

### Author: ![malee](https://avatars.discourse-cdn.com/v4/letter/m/ac8455/32.png) [@malee](https://discourse.nodered.org/u/malee)
#### Post date: [24 October 2024 13:07 UTC](https://discourse.nodered.org/t/using-fetch-within-endpoints-registered-with-red-httpadmin/92634/5 "2024-10-24T13:07:38Z")

</div>

This is the consideration I had also I think staying with the included client is the best thing to do

---

<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: [22 January 2025 13:08 UTC](https://discourse.nodered.org/t/using-fetch-within-endpoints-registered-with-red-httpadmin/92634/6 "2025-01-22T13:08:10Z")

</div>

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