Sub-workflow to get and store API keys and be used by other workflows

Describe the problem/error/question

I have created a sub workflow, which my mainworkflow will trigger and use the output from.
Sub workflow: sub_generate_bearer_token
Main workflow: create_linked_returns

This workflow will create empty variables using a set node. Which I then intend to populate later on.

My issue is, my workflow gets a token, I then use a code node (called “store_token”) to try update that cachedToken variable earlier on but it never sets. So the workflow IF statement always returns true, that there is no cachedToken set, so get another one.

What is the error message (if any)?

No error, I just don’t know how to store the token from a later node in my earlier node.

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

The ‘last’ node just returns the token, but the store_token node is the important one here:

Information on your n8n setup

  • n8n version: 1.88.0
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): Not sure what this means
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Mac Ventura

Hi @JordanC26

In the main workflow, did you activate the option Wait For Sub-Workflow Completion for the sub workflow node?

Hi @mohamed3nan

Well, before I get to that part, this current workflow, when run will just keep going down the path of requesting a new token every time as it’s never storing it.

Not sure how best to store so I can store for 1 hour and re-use what it got back previously. I am using community edition, so “global” variables are not an option for me.

1 Like

Ah, I understand.

Have you tried implementing this feature?