{
  "id": "pc2HHg8DLhcpoMg5",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Automated API Uptime Monitoring with Instant Downtime Alerts",
  "tags": [],
  "nodes": [
    {
      "id": "6050fae8-e86d-481f-bcf5-98461f796b5f",
      "name": "Read API List",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -2640,
        260
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VKlDZSHicdZhhj-fl-vIIH0mC6VDwdCS4-LqaDIeyw0/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1VKlDZSHicdZhhj-fl-vIIH0mC6VDwdCS4-LqaDIeyw0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VKlDZSHicdZhhj-fl-vIIH0mC6VDwdCS4-LqaDIeyw0/edit?usp=drivesdk",
          "cachedResultName": "URL For Status Check"
        },
        "combineFilters": "AND"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "68940a15-d216-4366-8673-71b71305084d",
      "name": "Init Retry Counter",
      "type": "n8n-nodes-base.code",
      "position": [
        -2200,
        185
      ],
      "parameters": {
        "jsCode": "// Initialize retry counter for each API\nconst apiData = $json;\nif (!apiData.retryCount) {\n  apiData.retryCount = 0;\n}\nreturn apiData;"
      },
      "typeVersion": 2
    },
    {
      "id": "06b0731a-81c3-449f-b302-0e9f5e2f9b0d",
      "name": "Test API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1980,
        185
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "method": "={{ $json.method }}",
        "options": {
          "timeout": 10000
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "continueOnFail": true
    },
    {
      "id": "f4450c0b-48fe-40d2-9b68-c54b12980a01",
      "name": "Check Response",
      "type": "n8n-nodes-base.code",
      "position": [
        -1760,
        185
      ],
      "parameters": {
        "jsCode": "// Check if API responded\nconst response = $json;\nconst apiData = $('Init Retry Counter').first().json;\n\nlet hasResponse = response && typeof response === 'object' && Object.keys(response).length > 0;\n\nreturn {\n  ...apiData,\n  hasResponse: hasResponse\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "886d69dd-e847-4cf7-badb-5d5a02e8cfcd",
      "name": "If No Response",
      "type": "n8n-nodes-base.if",
      "position": [
        -1540,
        185
      ],
      "parameters": {
        "options": {
          "looseTypeValidation": true
        },
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "no-response",
              "operator": {
                "type": "boolean",
                "operation": "true"
              },
              "leftValue": "={{ $json.hasResponse }}",
              "rightValue": "=false"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "be9792e7-be19-47e3-9621-613f1cc8d611",
      "name": "Wait 10 Min",
      "type": "n8n-nodes-base.wait",
      "position": [
        -1320,
        110
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "4fdd9d39-af72-42d7-9d81-0e878920709b",
      "name": "Increment Retry",
      "type": "n8n-nodes-base.code",
      "position": [
        -1100,
        35
      ],
      "parameters": {
        "jsCode": "// Increment retry count\nconst data = $json;\ndata.retryCount = (data.retryCount || 0) + 1;\nreturn data;"
      },
      "typeVersion": 2
    },
    {
      "id": "c71871bb-7416-4a58-b5b6-d0c326856c62",
      "name": "Retry API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -880,
        35
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "method": "={{ $json.method }}",
        "options": {
          "timeout": 10000
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "continueOnFail": true
    },
    {
      "id": "5567bff2-495e-4b96-adbc-9d5aa290398a",
      "name": "Check Retry Response",
      "type": "n8n-nodes-base.code",
      "position": [
        -660,
        35
      ],
      "parameters": {
        "jsCode": "// Check retry response\nconst response = $json;\nconst apiData = $('Increment Retry').first().json;\n\nlet hasResponse = response && typeof response === 'object' && Object.keys(response).length > 0;\n\nreturn {\n  ...apiData,\n  hasResponse: hasResponse\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "56590da0-6e35-430b-b380-066322cdb528",
      "name": "If Still No Response",
      "type": "n8n-nodes-base.if",
      "position": [
        -440,
        35
      ],
      "parameters": {
        "options": {
          "looseTypeValidation": true
        },
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "still-no-response",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.expectedStatusCode === null || $json.expectedStatusCode === undefined || $json.expectedStatusCode === '' }}",
              "rightValue": "=false"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "1c206215-fe56-48f6-87f0-e1875e664d80",
      "name": "Format Down Alert",
      "type": "n8n-nodes-base.code",
      "position": [
        0,
        -40
      ],
      "parameters": {
        "jsCode": "// Create down alert message\nconst api = $json;\n\nconst alertMessage = `\ud83d\udea8 API DOWN ALERT\\n\\n\ud83d\udccb ${api.name}\\n\ud83c\udf10 ${api.url}\\n\u23f0 ${new Date().toISOString()}`;\n\nreturn {\n  ...api,\n  alertMessage: alertMessage\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "96024d21-5201-4629-9eef-547c49994d4f",
      "name": "Send WhatsApp Alert",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        220,
        -40
      ],
      "parameters": {
        "textBody": "={{ $json.alertMessage }}",
        "operation": "send",
        "phoneNumberId": "550325331503475",
        "additionalFields": {},
        "recipientPhoneNumber": "+1234567890"
      },
      "credentials": {
        "whatsAppApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "42753397-1223-4fc5-8df0-a340a64fc731",
      "name": "Continue Next API",
      "type": "n8n-nodes-base.code",
      "position": [
        440,
        260
      ],
      "parameters": {
        "jsCode": "// Continue to next API\nconst data = $json;\nif (data.hasResponse) {\n  data.retryCount = 0;\n}\nreturn data;"
      },
      "typeVersion": 2
    },
    {
      "id": "1f5c7218-68d3-4878-a238-36ca0ad31764",
      "name": "Process Each API1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -2420,
        260
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "0b1af6a3-bf8e-4398-917e-f2526449ad6b",
      "name": "If Still No Retry > 4",
      "type": "n8n-nodes-base.if",
      "position": [
        -220,
        -40
      ],
      "parameters": {
        "options": {
          "looseTypeValidation": true
        },
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "still-no-response",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.retryCount >= 4}}",
              "rightValue": "=false"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d2bb51d4-2ace-4a9c-8a7c-25c588de3063",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -2860,
        260
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "3fda8d5d-5311-4804-afef-4ec25ed3c92f",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2420,
        -340
      ],
      "parameters": {
        "color": 4,
        "width": 1220,
        "height": 340,
        "content": "## How It Works\n* **Schedule Trigger** \u2192 Triggers every 15 minutes.\n* **Read API List** \u2192 Fetches all API URLs from a Google Sheet.\n* **Process Each API1** \u2192 Loops through each API entry.\n* **Init Retry Counter** \u2192 Initializes `retryCount = 0`.\n* **Test API** \u2192 Sends the first request to the API.\n* **Check Response** \u2192 Checks if a valid response was received.\n* **If No Response** \u2192 Branches into retry flow if down.\n* **Wait 10 Min \u2192 Increment Retry \u2192 Retry API \u2192 Check Retry Response** \u2192 Wait and retry API call once.\n* **If Still No Response** \u2192 Verifies if retry also failed.\n* **If Still No Retry > 4** \u2192 Checks if retry limit is reached (\u2265 4).\n* **Format Down Alert** \u2192 Formats the WhatsApp alert with API details.\n* **Send WhatsApp Alert** \u2192 Sends API down alert to configured number.\n* **Continue Next API** \u2192 Moves to the next API in the list."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2eee3704-de38-4436-9d22-57252c0ff118",
  "connections": {
    "Test API": {
      "main": [
        [
          {
            "node": "Check Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retry API": {
      "main": [
        [
          {
            "node": "Check Retry Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 10 Min": {
      "main": [
        [
          {
            "node": "Increment Retry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read API List": {
      "main": [
        [
          {
            "node": "Process Each API1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Response": {
      "main": [
        [
          {
            "node": "If No Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If No Response": {
      "main": [
        [
          {
            "node": "Wait 10 Min",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Continue Next API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Increment Retry": {
      "main": [
        [
          {
            "node": "Retry API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Read API List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Continue Next API": {
      "main": [
        [
          {
            "node": "Process Each API1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Down Alert": {
      "main": [
        [
          {
            "node": "Send WhatsApp Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Each API1": {
      "main": [
        [],
        [
          {
            "node": "Init Retry Counter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Init Retry Counter": {
      "main": [
        [
          {
            "node": "Test API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp Alert": {
      "main": [
        [
          {
            "node": "Continue Next API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Retry Response": {
      "main": [
        [
          {
            "node": "If Still No Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Still No Response": {
      "main": [
        [
          {
            "node": "If Still No Retry > 4",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Continue Next API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Still No Retry > 4": {
      "main": [
        [
          {
            "node": "Format Down Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 10 Min",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}