How to pass context data into subflow using the

I've created a function to call some api's and return some data. All the function need is some input (in the message) and an API-key. The API-key is stored in the context data and is accessible in function nodes usinig code like:
However, since i've tuned the function to coopreate with the output of others i don't want to 'pollute' the message object with this API-key. I'd like to pass this API-key through a parameter which i've specified:
What do i put in this field to make the value of the context data "apikey" to be passed to the subflow?! For the love of god i can't figure it out, but it seems such an obvious feature that i can't believe it doesn't exist...

use a change a node as the very first node of your subflow. You can access the context data using change node in a subflow. set it to a separate msg property using that change node and then use that property to reference the API key.

Hope it'd help.


Hi @sokkensoepje

Am I right to think that screenshot is of the Subflow's edit dialog you've created?

If so, then the value of that property will be available inside the subflow as an environment variable, using whatever name you've given it in the subflow property dialog. But that is nothing to do with context - the user would have to enter the value of apikey when configuring the flow and then the nodes inside the subflow would be able to use it.

There are then a number of ways you can use env vars inside the subflow - Using environment variables : Node-RED

For example, you could use a Change node to attach the env property to the message.

Alternatively, you could config a node's property inside the subflow use the ${FOO} syntax as described in the link I've shared.

Hi thanks @knolleary for taking the time to reply.

Indeed the screenshot is the edit dialog i created. But what i can't figure out is what expression do i put in it in order to fill in the context data. I've read the page in the link, but it doesn't seem to work.

Take this flow which consists of three steps:

The second step sets some context value:

The thirs step is the subflow as described above. If i fill in a literal value in the edit dialog i'm able to use it inside the subflow, so that tells me that there is nothing wrong with the subflow. But how do i make this value come from the context variable my_key?

I've tried these:

And loads more, but none seem to work...

And this one too:

i could go on, but it's rather frustrating...

Hi @sokkensoepje

The subflow properties cannot be set from context properties. They are treated as environment variables and are set when the flow starts and cannot be changed dynamically.

Ok, clear, so i cannot pass any variables into subflows other than setting them as globally defined constants or as a parameter in the message itself... seems a bit strange, but if its like that then i'll have to change my subflow.

Thanks for the support.

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