2. Refresh Pipedrive Tokens
This workflow implements the automatic refresh functionality for OAuth 2.0 access tokens of the Pipedrive API, ensuring that tokens are automatically updated after expiration, thus avoiding manual intervention. Access and refresh tokens are stored and managed through a Supabase database, enhancing security and reliability. This mechanism is suitable for automated systems that frequently call the Pipedrive API or any business scenarios that require OAuth 2.0 token management, ensuring the continuity and stability of API calls.

Workflow Name
- Refresh Pipedrive Tokens
Key Features and Highlights
This workflow implements an automatic refresh mechanism for Pipedrive API OAuth 2.0 access tokens, ensuring tokens are updated seamlessly upon expiration without manual intervention. By integrating Supabase as the database to store and manage both access and refresh tokens, it enhances the security and reliability of token management. The workflow is designed with flexibility in mind and can be adapted for other third-party applications requiring OAuth 2.0 token refresh.
Core Problem Addressed
OAuth 2.0 access tokens typically have a limited lifespan, and API calls fail once tokens expire. This workflow resolves the issue of token expiration causing failed calls to the Pipedrive API by automatically detecting invalid tokens and invoking the refresh endpoint to update them, thereby ensuring continuous and stable API access.
Use Cases
- Automated systems that frequently call the Pipedrive API and rely on OAuth 2.0 authentication.
- Any business scenarios requiring automatic management of access and refresh tokens under OAuth 2.0 authorization.
- SaaS products or internal tools integrating Pipedrive or similar platform APIs with automated token maintenance.
- Developers who want to build their own OAuth 2.0 token refresh process for greater control.
Main Process Steps
- During user authentication, save the obtained access token and refresh token to the Supabase database.
- Upon receiving an API request, retrieve the corresponding access token from Supabase.
- Use the access token to call the Pipedrive API (e.g., the contact search API in this example).
- Check if the API response indicates failure due to an invalid access token.
- If the token is invalid, trigger the refresh process by calling a local webhook endpoint to request a token refresh.
- Use the refresh token to call the Pipedrive OAuth endpoint and obtain new access and refresh tokens.
- Update the token information stored in the Supabase database.
- Retry the API call with the new access token or return an error message if refreshing fails.
Involved Systems or Services
- Pipedrive API: For accessing contact data and managing OAuth tokens.
- Supabase Database: For storing and managing access and refresh tokens.
- n8n Automation Platform Nodes: Including HTTP Request, Webhook, Conditional (IF), and Code execution nodes.
- Local Webhook Service: Handles the token refresh business logic.
- OAuth 2.0 Authentication Mechanism: Facilitates token acquisition and refresh.
Target Audience and Value
- Technical developers and automation engineers needing stable Pipedrive API integration.
- SaaS product teams requiring autonomous management of third-party OAuth 2.0 authentication flows.
- Business systems dependent on Pipedrive data with high availability API access requirements.
- Enterprises or individual users aiming to enhance token management security and automation.
This workflow ensures continuous and stable Pipedrive API access through a complete access token refresh mechanism, reducing authentication interruptions and improving automation and security in business processes. Its generic design also facilitates easy migration to other OAuth 2.0-supported API services.