{
  "name": "ScoreApp: sends new leads to your own endpoint and alerts you when the sync fails",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "id": "trigger",
      "name": "Every 15 minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.4,
      "position": [
        -40,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://api.scoreapp.com/leads",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{ $env.API_TOKEN }}"
            }
          ]
        },
        "options": {
          "response": {
            "response": {
              "neverError": true,
              "fullResponse": false
            }
          }
        }
      },
      "id": "fetch",
      "name": "Fetch new leads",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.5,
      "position": [
        200,
        300
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "alwaysOutputData": true,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "version": 2,
            "leftValue": "",
            "typeValidation": "loose"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "err",
              "operator": {
                "type": "object",
                "operation": "notEmpty"
              },
              "leftValue": "={{ $json.error }}",
              "rightValue": ""
            },
            {
              "id": "missing",
              "operator": {
                "type": "array",
                "operation": "empty"
              },
              "leftValue": "={{ $json[\"data\"] }}",
              "rightValue": ""
            }
          ]
        },
        "looseTypeValidation": true,
        "options": {}
      },
      "id": "check",
      "name": "Did the request fail?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        440,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.ALERT_WEBHOOK_URL }}",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "={{ 'ScoreApp leads sync failed: ' + JSON.stringify($json).slice(0, 400) }}"
            }
          ]
        },
        "options": {}
      },
      "id": "alert",
      "name": "Alert on failure",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.5,
      "position": [
        700,
        180
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "fieldToSplitOut": "data",
        "options": {}
      },
      "id": "split",
      "name": "One item per leads",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        700,
        420
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.DESTINATION_WEBHOOK_URL }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json) }}",
        "options": {}
      },
      "id": "send",
      "name": "Send to your endpoint",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.5,
      "position": [
        940,
        420
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "content": "## ScoreApp: sends new leads to your own endpoint and alerts you when the sync fails\n\nThree environment variables and it runs.\n\n1. `API_TOKEN` — your ScoreApp API credential, sent as the `Authorization` header.\n2. `DESTINATION_WEBHOOK_URL` — wherever you want the leads to land.\n3. `ALERT_WEBHOOK_URL` — where a failure notice should go.\n\nIt polls `/leads` every 15 minutes, retries three times with a five second gap, and routes anything that still fails to the alert branch instead of dying quietly.\n\nRate limits: the api returns a 429 rate limit response when the limit is exceeded",
        "height": 420,
        "width": 460
      },
      "id": "note",
      "name": "Setup",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        160
      ]
    }
  ],
  "connections": {
    "Every 15 minutes": {
      "main": [
        [
          {
            "node": "Fetch new leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch new leads": {
      "main": [
        [
          {
            "node": "Did the request fail?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Did the request fail?": {
      "main": [
        [
          {
            "node": "Alert on failure",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "One item per leads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One item per leads": {
      "main": [
        [
          {
            "node": "Send to your endpoint",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  }
}