Set Global context variable using Http request

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'

Try doing a post with the body as json instead.

The same. It doesn't work

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

Is there a diffrent approach that i can try?

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.

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

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

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.

1 Like