I’m currently working on a workflow where I need to pass dynamically generated access tokens to multiple GraphQL nodes. The workflow involves logging into our admin page to retrieve an access token, which is required for further GraphQL API requests. However, there are two key issues I’m facing:
Login Flow: I need to send a login request to our admin page to retrieve an access token via a GraphQL mutation. This token is sent in the response body, and it’s required to authenticate subsequent API calls.
Token Expiry: The access token refreshes every minute, so I need to dynamically retrieve and pass the new token into future GraphQL API calls within the same workflow.
I’ve already set up an HTTP Request node to handle the login request and retrieve the token. But I’m struggling with how to:
Extract the token from the response body or headers.
Store it dynamically and use it in future GraphQL requests (which require the Authorization: Bearer <token> header).
Handle token refreshes efficiently during the workflow execution.
Any tips on how to structure this in n8n would be greatly appreciated!
If the token expires after a minute I wouldn’t store it and just generate it each time. If the token is in the output you can use this and set it in the credentials of the node using an expression to fetch it from your input node.
Alternatively, if you have to do another request to get the access token you can store it across executions using the built-in getWorkflowStaticData property.
Here’s a very simple demo workflow to illustrate how it works:
Thanks, Ria! Which node should I use to log into our admin page to retrieve the access tokens? It seems I’m stuck at this point. When I use the HTTP request node, it doesn’t return the header containing the access token.