# HTTP endpoint creation problem

**URL:** <https://discourse.nodered.org/t/http-endpoint-creation-problem/75875>\
**Category:** General\
**Tags:** http-request\
**Created:** [28 February 2023 14:50 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875 "2023-02-28T14:50:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Acii](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Acii](https://discourse.nodered.org/u/Acii)\
**Post date:** [28 February 2023 14:50 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875/1 "2023-02-28T14:50:48Z")

</div>

Hello everyone, I explain the context, it is very simple to understand,

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

I have a flow that compares two numerical variables, these values come from an HTTP request. Depending on the values of the two numeric variables, I SET another variable to a certain string :

IF VAR1 \>VAR2 THEN MSG.TEST=VAR1 MORE IMPORTANT  
IF VAR1 \<VAR2 THEN MSG.TEST=VAR1 LESS IMPORTANT  
IF VAR1 == VAR2 THEN MSG.TEST=OK

And now I JUST want to be able to retrieve the value of msg.TEST by making an HTTP request, so I searched on the internet how to do it, and I saw a flow that allows me to do what I want, and that is very simple, So I imported the flow :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20315551f2ec5847a86ce985464ba144df5ab5c3.png)

Configuration of function Node :

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97458f9e5e6d6ab73989df6e30c857124bd3410c.png)

So now thanks to this flow I am able to retrieve the value of the payload variable by making an http request

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/6119c9fb1e7a94703fc8cec4c133f670f80b0bf9.png)

So at this point I think great, this is simple, so I try to modify the flow so that it does what I want

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/77d3f3092cfa8f534adccb8a98c15ad9e133c9f3.png)

Configuration of function Node :

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/86b6ab46b6fb92411d97a57ef1e98eaa63232639.png)

So after that I just naively thought I'd make an HTTP request and then be able to see the beautiful values of my msg.result variable, but when I go to the web page to see the values I get :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e6638b25933a9d4f1204831ccccde04a06a6f472.png)

Absolutely nothing 🤣

I don't understand what I'm doing wrong, I don't know much about NodeRed I'm a real beginner so I don't even see a basic error that would be obvious to any regular user.

Thanks in advance for your help

---

<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:** [28 February 2023 14:55 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875/2 "2023-02-28T14:55:34Z")

</div>

The function needs the two request and join to function.  
So your http in would be the inject and the response after the function.  
make sure msg.res is not overwritten it has to make it from the http in node to response node, set debugs to complete msg.

---

<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:** [28 February 2023 15:15 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875/3 "2023-02-28T15:15:17Z")

</div>

In node-red, each node / Function has no awareness of the last time it ran.

Therefore, "function 86" is ran fresh / clean every time a msg arrives.

What I mean by that is, when the HTTP Endpoint `/test` is triggered it fires a `msg` into "function 86`- but it is NOT the same as the`msg` your HTTP-Requests & the join node created. - a debug node before the function will clearly demonstrate this.

#### What to do

You need to store the value from the join node in context THEN retrieve if from context when the `/test` endpoint is called.

_Another improvement you can make is to lose the join node & simplify things by performing the requests in series (store each result in context after the HTTP Requests)_

#### In basic terms...

##### Flow 1.

`inject -> HTTP Req -> Change Node (SET flow.reqOne to value of msg.payload) -> HTTP Req -> Change Node (SET flow.reqTwo to value of msg.payload)`

##### Flow 2.

`HTTP-in -> change node (set msg.payload.requestOne to value of flow.reqOne) -> change node (set msg.payload.requestTwo to value of flow.reqTwo) -> HTTP-Response`

---

<div class="post-metadata">

**Author:** ![Acii](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Acii](https://discourse.nodered.org/u/Acii)\
**Post date:** [28 February 2023 15:17 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875/4 "2023-02-28T15:17:08Z")

</div>

It worked, thank you very much good day

---

<div class="post-metadata">

**Author:** ![Acii](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@Acii](https://discourse.nodered.org/u/Acii)\
**Post date:** [28 February 2023 15:26 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875/5 "2023-02-28T15:26:21Z")

</div>

Thanks for ur reply,  
I have a problem with this method, the two HTTP requests return the same variable, they just don't have the same values so if 2 different HTTP requests return a variable that has the same name  
How do I differentiate this variable?

Like if the 1st HTTP request returns a variable named totalcount which is equal to 663  
And if the 2nd HTTP request returns a variable named totalcount which is equal to 664

how do I differentiate between the totalcount from the 1st request and the totalcount from the 2nd request

---

<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:** [28 February 2023 15:39 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875/6 "2023-02-28T15:39:43Z")

</div>

I believe I did suggest to run the request sequentially in another topic you created, but I was ignored, after each request move the payload to another property. [The same condition does different things - #10 by E1cid](https://discourse.nodered.org/t/the-same-condition-does-different-things/75675/10)

---

<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:** [28 February 2023 15:45 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875/7 "2023-02-28T15:45:24Z")

</div>

> [@Acii](#):
>
> Like if the 1st HTTP request returns a variable named totalcount which is equal to 663  
> And if the 2nd HTTP request returns a variable named totalcount which is equal to 664
> 
> how do I differentiate between the totalcount from the 1st request and the totalcount from the 2nd request

You move them into unique named context variables as I said above (e.g. `flow.reqOne` and `flow.reqTwo`). You can then pick out what you need from the flow context - e.g using a change node with 2 entries, you can SET `msg.payload.v1` to the appropriate flow variable e.g. `flow.reqOne.totalcount` and SET `msg.payload.v2` to the appropriate flow variable e.g. `flow.reqTwo.totalcount`

##### Flow 1.

inject -\> HTTP Req -\> Change Node (SET flow.reqOne to value of msg.payload) -\> HTTP Req -\> Change Node (SET flow.reqTwo to value of msg.payload)

↑ See the 1st request has its `msg.payload` copied into `flow.reqOne`. The second request gets its `msg.payload` copied into `flow.reqTwo`.

##### Flow 2.

HTTP-in -\> change node (set `msg.payload.requestOne` to value of `flow.reqOne.totalcount`) -\> change node (set `msg.payload.requestTwo` to value of `flow.reqTwo.totalcount`) -\> HTTP-Response

↑ Here, when the HTTP-In fires, you simply "grab" the values you wish from `flow.reqOne` and `flow.reqTwo` and build your payload (however you want) ready to be posted back in the HTTP-Response.

---

<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:** [14 March 2023 15:46 UTC](https://discourse.nodered.org/t/http-endpoint-creation-problem/75875/8 "2023-03-14T15:46:24Z")

</div>

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