# How to put my token in http request

**URL:** <https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163>\
**Category:** General\
**Tags:** http-request\
**Created:** [20 May 2025 12:50 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163 "2025-05-20T12:50:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![AntoninPETIT](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@AntoninPETIT](https://discourse.nodered.org/u/AntoninPETIT)\
**Post date:** [20 May 2025 12:50 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/1 "2025-05-20T12:50:54Z")

</div>

This is for creating a new token, but how and where do I add the comment to the token?  
my fonction

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c3f1d32f4e61d710dcd26a5021c20505b2ab5c54.png)  
error  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/1/01acf2477baf1fead993318b310a5fa697cded50.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 May 2025 07:12 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/2 "2025-05-21T07:12:19Z")

</div>

Hi and welcome.

I think you will need to explain more, do you have documentation of this API. Maybe an exaple flow with the data you are trying to insert into your http request.

P.s best to supply functions in text form as well as data, then people who wish to help you can easily provide example back.

Some help full info for future use.

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

[How to import/export a flow](https://nodered.org/docs/user-guide/editor/workspace/import-export)

Also as you are new to node-red there are the [essentials videos](https://m.youtube.com/watch?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6&v=ksGeUD26Mw0&embeds_referring_euri=https%3A%2F%2Fnodered.org%2F&source_ve_path=OTY3MTQ&feature=emb_imp_woyt) which will give you lots of helpful insights.

---

<div class="post-metadata">

**Author:** ![AntoninPETIT](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@AntoninPETIT](https://discourse.nodered.org/u/AntoninPETIT)\
**Post date:** [21 May 2025 12:14 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/3 "2025-05-21T12:14:02Z")

</div>

Hello,  
I modified my code so that the token is saved and reused for the next function, but I still get the same error: "Token does not exist". So I don't see where my mistake is.

Here is my code:

**To create and store the token:**

```auto
// Parse msg.payload because it's a JSON string
let data = JSON.parse(msg.payload);

// Check if the code is 200 (success)
if (data.code === 200 && data.data && data.data.token) {
    let token = data.data.token;

    // Log part of the token
    node.warn("Extracted token: " + token.substring(0, 1000000000));

    // Store the token in flow memory
    flow.set("authToken", token);
} else {
    node.error("Error in response: " + msg.payload);
}

return msg;

```

**To retrieve and use the token:**

```auto
// Retrieve the token
let token = flow.get("authToken");

msg.headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer " + token,
    "x-auth-token": token,
    "x-access-token": token
};

// Data to send
msg.payload = {
    id: 1,
    storeId: "1886369875899715584",
    icon: "ico...monster",
    item: "Coucou",
    item2: "hello!",
    qrcode: "jsdqsdkfhsdjf...",
    quantity: 40,
    image: ""
};

return msg;

```

Also, when I use Postman, everything works perfectly, even when I use the token generated by this function.  
So I really don't understand where the problem is.

---

<div class="post-metadata">

**Author:** ![AntoninPETIT](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@AntoninPETIT](https://discourse.nodered.org/u/AntoninPETIT)\
**Post date:** [21 May 2025 12:17 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/4 "2025-05-21T12:17:37Z")

</div>

Also, in Postman, my cURL request looks like this:

```auto
curl --location 'http://10.64.231.215:9194/esl/goods/updateToStore' \
--header 'Content-Type: application/json' \
--header 'token: eyJhbGciOiJSUzUxMiJ9.eyJzdWIiOiIxODg2MzY4Njg5NzAwMjEyNzM2IiwiZXhwIjoxNzQ3OTE1MDIyfQ.LLTNHZyoLDzB82uqodPrKOkaegwg0zmxEHY8t7jsbGeF5tBOk8-wmYphbAdd4q2vne4RsS6wHu8pB1JKg-XFi2YVubyS5HOVhXB3MDCMPzQ2_iwlNtXe9ym_Boqs0MlgcyH3po7k5oi6CBRHxZ3EoI8txqiZf5kdksHCEH3BPac' \
--data '{
    "id": "1",
    "storeId": "1886369875899715584",
    "icon": "icofont-angry-monster",
    "item": "Coucou",
    "item2": "Hello!",
    "qrcode": "jsfdsqkfhsdjf kjqsdhf kjqsdhkjfhsdk",
    "quantity": "40",
    "image": ""
}'

```

When I use this cURL in Postman, everything works perfectly, even with the token generated by my function.

However, I can't just copy this cURL command into the Node-RED function node, because the function node expects JavaScript code, not a raw cURL or JSON string. In Node-RED, it's recommended to build the request using JavaScript objects and let the HTTP request node handle the actual HTTP call.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 May 2025 14:06 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/5 "2025-05-21T14:06:47Z")

</div>

Can you show the payload returned from the bearer authorization.

---

<div class="post-metadata">

**Author:** ![AntoninPETIT](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@AntoninPETIT](https://discourse.nodered.org/u/AntoninPETIT)\
**Post date:** [22 May 2025 07:01 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/6 "2025-05-22T07:01:49Z")

</div>

In my flow, I have two debug nodes at the top to retrieve and use the token.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/1/51ae167001ed5a5defa4cdadce16d40c6b989951.png)  
You can see my debug output below.  
Debug 5 is right after the function, and debug 4 is at the end of the flow.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/50f06b4169e8e406a3f43f98e0cc5ee09ae22447.png)  
Sorry for the bad quality of the screen.

---

<div class="post-metadata">

**Author:** ![AntoninPETIT](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@AntoninPETIT](https://discourse.nodered.org/u/AntoninPETIT)\
**Post date:** [22 May 2025 07:12 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/7 "2025-05-22T07:12:12Z")

</div>

I can see in Debug 4 that the token is missing from the headers. Is that normal?

---

<div class="post-metadata">

**Author:** ![kitori](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kitori](https://discourse.nodered.org/u/kitori)\
**Post date:** [22 May 2025 07:23 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/8 "2025-05-22T07:23:00Z")

</div>

I had a similar problem when i had to puh data through keycloak oauth. Since it is not my keycloak instance, the solution was a small wrapper script arround curl ...

i remember that the support says something that there were multiple requests where the header was send as the POST-data 🧐

---

<div class="post-metadata">

**Author:** ![xx\_Nexus\_xx](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xx\_Nexus\_xx](https://discourse.nodered.org/u/xx_Nexus_xx)\
**Post date:** [22 May 2025 07:28 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/9 "2025-05-22T07:28:37Z")

</div>

You have to put the header information in your http request ...almost like your curl.. se below example I'm using

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/a/ba573101947d14eb7adf1ef6920010c626be42d5.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [22 May 2025 09:48 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/10 "2025-05-22T09:48:50Z")

</div>

Debug 4 is the response not the request so the bearer token would not be in the header normally.

Is the http request post or get?

---

<div class="post-metadata">

**Author:** ![AntoninPETIT](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@AntoninPETIT](https://discourse.nodered.org/u/AntoninPETIT)\
**Post date:** [12 June 2025 06:50 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/11 "2025-06-12T06:50:57Z")

</div>

It was an HTTP POST request

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad5d110db635242cea2fae209a45bb2d8b7ba0f3.png)

---

<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 September 2025 06:51 UTC](https://discourse.nodered.org/t/how-to-put-my-token-in-http-request/97163/12 "2025-09-10T06:51:01Z")

</div>

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