Quick Overview
This workflow exposes a webhook that forwards a request to a primary API, retries once after a short delay if it fails, and then fails over to a backup API, returning a structured JSON success or error response to the caller.
How it works
- Receives a POST request on an n8n webhook with the primary API URL, backup API URL, HTTP method, and optional retry count.
- Sends the request to the primary API using an HTTP request with a 10-second timeout and captures the full response even on failure.
- If the primary API responds with HTTP 200, returns a JSON response to the webhook caller indicating the primary provider succeeded.
- If the primary API fails, waits 5 seconds and retries the same primary API request once.
- If the retry responds with HTTP 200, returns a JSON response indicating the primary-retry path succeeded.
- If the retry fails, sends the request to the backup API and returns success if it responds with HTTP 200.
- If both primary and backup APIs fail, returns a JSON error message with an ISO timestamp to the webhook caller.
Setup
- Activate the workflow and copy the production webhook URL from the Webhook trigger to use as your API recovery endpoint.
- Configure the calling system to POST a JSON body that includes primaryApi, backupApi, and (optionally) method and retryCount values.
- If your target APIs require authentication or custom headers/body, extend the HTTP requests to include the required headers, query parameters, or payload and adjust the timeout as needed.