# Set Global context variable using Http request

**URL:** <https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672>\
**Category:** Feature Requests\
**Created:** [17 December 2020 20:14 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672 "2020-12-17T20:14:35Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tombcat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tombcat/32/33861_2.png) [@Tombcat](https://discourse.nodered.org/u/Tombcat)\
**Post date:** [17 December 2020 20:14 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/1 "2020-12-17T20:14:36Z")

</div>

Hello i want to change the global variable in the flow using the http request.  
I already saw it's possible to GET flow global variable using HTTP request.

Also i have checked that it's possible to send POST/PUT request.  
But unfortunately i cannot get it working

This is what comes to my mind:

curl --location --request POST 'https://\<flow\_instance\>/context/global/some\_variable'   
--header 'Authorization: Bearer \<access\_token\>'   
--header 'Content-Type: text/plain'   
--data-raw 'test'

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [17 December 2020 20:28 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/2 "2020-12-17T20:28:33Z")

</div>

Try doing a post with the body as json instead.

---

<div class="post-metadata">

**Author:** ![Tombcat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tombcat/32/33861_2.png) [@Tombcat](https://discourse.nodered.org/u/Tombcat)\
**Post date:** [17 December 2020 20:36 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/3 "2020-12-17T20:36:57Z")

</div>

The same. It doesn't work

---

<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:** [17 December 2020 20:44 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/4 "2020-12-17T20:44:52Z")

</div>

The `/context` end point doesn't support setting values - you can only GET or DELETE them.

---

<div class="post-metadata">

**Author:** ![Tombcat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tombcat/32/33861_2.png) [@Tombcat](https://discourse.nodered.org/u/Tombcat)\
**Post date:** [17 December 2020 20:47 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/5 "2020-12-17T20:47:30Z")

</div>

Is there a diffrent approach that i can try?

---

<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:** [17 December 2020 21:07 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/6 "2020-12-17T21:07:28Z")

</div>

Something like...

`http-in` (e.g. URL `/ctx/:name`) → `function node`\* (pick up the name in msg.params and values in msg.payload, set global(name, value)) → `http-out` node.

then send a value like `http://localhost:1880/ctx/myVar?id=abcde&size=12&age=25` (or whatever you desire)

\* use a debug node set to show complete message to see where your variables and payloads end up then re-arrange them to write into global context as required.

---

<div class="post-metadata">

**Author:** ![Tombcat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tombcat/32/33861_2.png) [@Tombcat](https://discourse.nodered.org/u/Tombcat)\
**Post date:** [17 December 2020 23:00 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/7 "2020-12-17T23:00:58Z")

</div>

I needed to do it 100% by remote.

I will just use `POST /flow` with change node containing desired variables and inject node with auto inject.

But i would prefer `POST` or `PUT` method to the `/context` endpoint

---

<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:** [17 December 2020 23:34 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/8 "2020-12-17T23:34:07Z")

</div>

> [@Tombcat](#):
>
> I needed to do it 100% by remote.

Do what - I thought you wanted to change a node-red global variable by POSTing from a curl?

---

<div class="post-metadata">

**Author:** ![Tombcat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tombcat/32/33861_2.png) [@Tombcat](https://discourse.nodered.org/u/Tombcat)\
**Post date:** [18 December 2020 09:30 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/9 "2020-12-18T09:30:30Z")

</div>

Maybe I did use bad vocabulary, I wanted to change or set new variable in the target flow only using CURL without preparing the `HTTP IN` node etc.

---

<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:** [18 December 2020 09:58 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/10 "2020-12-18T09:58:44Z")

</div>

> [@Tombcat](#):
>
> Maybe I did use bad vocabulary, I wanted to change or set new variable in the target flow only using CURL without preparing the `HTTP IN` node etc

Yes, that is understood.

The runtime does not provide an HTTP API for doing that. The workaround (and quite natural way of doing it) is, as you know, to create the flow yourself.

---

<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 February 2021 09:59 UTC](https://discourse.nodered.org/t/set-global-context-variable-using-http-request/37672/11 "2021-02-16T09:59:00Z")

</div>

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