Struggling with Function Node and getWorkflowStaticData

I’m struggling with storing an authentication token received by an http request node, and then using the function node to simply store it.

How do I access the output from a Function Node in the next Node?

I can’t paste the workflow here as there is just too much confidential stuff in it.

Essentially a Webhook goes to a Function which retrieves the stored authtoken if any. Then an Httprequest uses that authtoken, then a Switch tests the http response code to see if it returns a 401 for an expired auth token. If it does 401, it tests for infinite loop, and then goes to Httprequest to retrieve a new auth token. then a Function node stores it, and loops back around to the original Function that gets the stored auth token.

the setSessionToken Function Node is this:
const staticStoredData = getWorkflowStaticData('global');
const sessionToken = $items("getNewSessionToken",0);
staticStoredData.sessionToken = sessionToken;
return sessionToken;

the getSessionToken Function Node looks like this:
const staticStoredData = getWorkflowStaticData('global');
const sessionToken = $items("getNewSessionToken",0);
staticStoredData.sessionToken = sessionToken;
return sessionToken;

the data returned by getSessionToken is:
[{“id”:“xxxxx-xx-xxx-xxxxxxxx”}]

Interestingly when I do the same httprequest in Insomnia/Postman it is just an object:
{“id”:“xxxxx-xx-xxx-xxxxxxxx”}

Can anyone help me with how to access the value of the json “id” from the Node that follows the Function?

Please and thank you (spent all day trying to debug this…)

You should be able to access it with: $node["NAME_OF_NODE"].json["id"] or even $json["id"]

1 Like

Thank you that worked.
I had been using that exact code yesterday, but it wasn’t working for some reason… perhaps late night not seeing a typo.
Appreciate the help.

1 Like