Call API and set credential

I need guidance on configuring a workflow to manage API tokens dynamically. Here’s the desired functionality:

  1. Call the /login API with a username and password to retrieve a token.
  2. Set the retrieved token in credentials for subsequent API calls.
  3. Before making each API call, check if the token is valid.
  4. If the token is invalid, call the /login API again to obtain a new token and update the credentials.

How can I implement this workflow efficiently in n8n, ensuring the token is refreshed only when needed?

  • n8n version: 1.39.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system:

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

Hi @abcxyz

Thanks for posting here and welcome to the community! :tada:

I’ve made a workflow template demonstrating the $getWorkflowStaticData function in n8n using the concept of access token validation.

Please have a look if this could be a solution for your use case.

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