Using same Auth Token for multiple executions

Hi everyone!

Describe the problem/error/question

I am receiving a webhook event from a external web service, once arrived, I have to make a new HTTP request for obtain more info, for doing that, I have to request a Auth Token that can be used for the request.
The token is available for 30 minutes, but so far I am using a new token for each new request/webhook event.
I would like to find a way to use the same token for all the request within the 30 minutes of validity.

Have you ever had a similar use case? My first idea is to use an external db as Gsheet, but need to understand how to manage the 30 minutes time.

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 0.234
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): self-hosted
  • Operating system: mac

hello @Gabriele_Bracciali

According to the OAuth 2.0 standard, you should not rely on the token lifetime. Instead, your workflow should handle the 401 Error itself (if it occurs >> request new token).
As to the sharing, you can save it locally in a file or in the WorkflowStaticData (if it will be reused in the same workflow).

Hi @barn4k Thanks for replying me!
How “WorkflowStaticData” works and how should I use for this use case?

You can use it in the Code node
getWorkflowStaticData | n8n Docs

I’ve found a way to create a file in the Disk and then Read it using the Command Line:

This one is the example:

So basically the process should be:
Read the token already saved on the disk, use it for the HTTP request, then check if there is an error,
If yes: I will generate new token, save it in the disk in the same file, and run the request again,
If no: Continue the process

1 Like

yes, but you should check for the error number in the error output of the node, not in the regular output (it won’t work there)

hi @barn4k , yes good point, I was using an old version of n8n and there was not this option.
Thank you so much!

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