Service Refused Connection

Describe the problem/error/question

I’ve an API, I’m making POST request to it, and I’m getting domainsCount and domainsList in response. Now I’m trying to check if the URL I’ve got is valid or not valid or it redirects.

What is the error message (if any)?

I’m getting this error at the Clean URL (Http Node )

{
  "meta": {
    "instanceId": "0a422814530ee25bdff1426ee51f135e37f33752b29414f2c108179bca6ef312"
  },
  "nodes": [
    {
      "parameters": {
        "url": "={{ $json.cleanUrl }}",
        "options": {
          "redirect": {
            "redirect": {
              "maxRedirects": 30
            }
          },
          "timeout": 60000
        }
      },
      "id": "1cef7768-3e09-4f99-a2e3-b9834568926c",
      "name": "Clean URL - Visit Website",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1020,
        340
      ]
    }
  ],
  "connections": {},
  "pinData": {}
}

## Please share your workflow
{
  "meta": {
    "instanceId": "0a422814530ee25bdff1426ee51f135e37f33752b29414f2c108179bca6ef312"
  },
  "nodes": [
    {
      "parameters": {},
      "id": "14004972-8a31-41d1-bec4-7f3d58a53e79",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        380
      ]
    },
    {
      "parameters": {
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "1vSqTnX3w6iudQrbStut8RsV4ck1-Gn-ZeFEGDG8kyxE",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "domainslist",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1vSqTnX3w6iudQrbStut8RsV4ck1-Gn-ZeFEGDG8kyxE/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Original URL": "{{ $json[\"results\"][0].originalDomain }}",
            "Final URL ": "{{ $json[\"results\"][0].finalURL }}",
            "Status Code": "{{ $json[\"results\"][0].statusCode }}"
          },
          "matchingColumns": [
            "Original URL"
          ],
          "schema": [
            {
              "id": "Original URL",
              "displayName": "Original URL",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Final URL ",
              "displayName": "Final URL ",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Status Code",
              "displayName": "Status Code",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {
          "cellFormat": "USER_ENTERED"
        }
      },
      "id": "8d1d9c8c-4f50-4c9d-aaa9-091234fa94e7",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.4,
      "position": [
        2060,
        340
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "IPZqQqwd1blNWdt2",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://maskedurl.com/api/v1",
        "sendQuery": true,
        "specifyQuery": "json",
        "jsonQuery": "{\n    \"apiKey\": \"at_9OXmjQ3DMj049UJ4WJ9Fzo21TjS25\",\n    \"sinceDate\": \"2024-06-27\",\n    \"subdomains\": {\n        \"include\": [\n            \"inst\"\n        ]\n    }\n}\n",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {}
          ]
        },
        "options": {}
      },
      "id": "2ad1a315-3eb6-4270-9c7c-a82102d88e15",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        220,
        620
      ]
    },
    {
      "parameters": {
        "jsCode": "const domains = items[0].json.domainsList;\nreturn domains.map(domain => {\n  return { json: { cleanUrl: domain.replace('inst.', '') } };\n});\n"
      },
      "id": "d4a3cb01-898b-40ac-ab44-005e7c79c26d",
      "name": "Remove inst from URL",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        520
      ]
    },
    {
      "parameters": {
        "batchSize": 10,
        "options": {
          "reset": false
        }
      },
      "id": "c968b780-a3f5-4304-bdae-6f8c0c943530",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        760,
        580
      ]
    },
    {
      "parameters": {
        "mode": "combine",
        "mergeByFields": {
          "values": [
            {}
          ]
        },
        "options": {}
      },
      "id": "f70ed949-b064-44d7-b3df-e97d49bae180",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 2.1,
      "position": [
        1820,
        340
      ]
    },
    {
      "parameters": {
        "jsCode": "for (const item of items) {\n  if (item.json.error) {\n    // Handle connection refused or other errors\n    item.json.status = \"Connection failed\";\n    item.json.statusCode = null;\n    item.json.cleanUrl = null;\n  } else if (item.json.statusCode >= 200 && item.json.statusCode < 300) {\n    if (item.json.url === item.json.cleanUrl) {\n      item.json.status = \"Works without redirect\";\n    } else {\n      item.json.status = \"Works with redirect\";\n      item.json.finalUrl = item.json.cleanUrl;\n    }\n  } else {\n    item.json.status = \"Doesn't work\";\n  }\n}\nreturn items;"
      },
      "id": "b8e3b791-3583-4cb1-9afb-35840b7f7dba",
      "name": "final check",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1520,
        340
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.cleanUrl }}",
        "options": {
          "redirect": {
            "redirect": {
              "maxRedirects": 30
            }
          },
          "timeout": 60000
        }
      },
      "id": "1cef7768-3e09-4f99-a2e3-b9834568926c",
      "name": "Clean URL - Visit Website",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1020,
        340
      ]
    }
  ],
  "connections": {
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Remove inst from URL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove inst from URL": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Clean URL - Visit Website",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "final check": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Clean URL - Visit Website": {
      "main": [
        [
          {
            "node": "final check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {}
}

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)


## Share the output returned by the last node
{
  "errorMessage": "The service refused the connection - perhaps it is offline [item 0]",
  "errorDetails": {
    "rawErrorMessage": [
      "connect ECONNREFUSED ::1:80"
    ],
    "httpCode": "rejected"
  },
  "n8nDetails": {
    "nodeName": "Clean URL",
    "nodeType": "n8n-nodes-base.httpRequest",
    "nodeVersion": 4.2,
    "itemIndex": 0,
    "time": "7/5/2024, 10:59:21 AM",
    "n8nVersion": "1.47.3 (Cloud)",
    "binaryDataMode": "filesystem",
    "stackTrace": [
      "NodeApiError: The service refused the connection - perhaps it is offline",
      "    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/HttpRequest/V3/HttpRequestV3.node.js:1634:35)",
      "    at processTicksAndRejections (node:internal/process/task_queues:95:5)",
      "    at Workflow.runNode (/usr/local/lib/node_modules/n8n/node_modules/n8n-workflow/dist/Workflow.js:728:19)",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:664:51",
      "    at /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/WorkflowExecute.js:1076:20"
    ]
  }
}

Information on your n8n setup

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

Can your n8n server reach those URLs? I’d start with a simple workflow containing only one HTTP request node to try that out.

Also, you may want to look into the formatting of your post - I think several things got mangled up there.

I did see this in your workflow - are you just looping over all the items to return the last one? There are better ways to do that :wink:

image

Hey @bartv

I was implementing a few nodes wrong. I’m pasting the updated workflow below.

{
  "meta": {
    "instanceId": "8738f4405845f96c82244ea24a78e00d826f7bf571d12fc85bf2f7d1de912ff5"
  },
  "nodes": [
    {
      "parameters": {},
      "id": "a6a76495-5afe-471b-bdfd-7334b0c5b0fd",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        720,
        400
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://domains-subdomains-discovery.whoisxmlapi.com/api/v1",
        "sendQuery": true,
        "specifyQuery": "json",
        "jsonQuery": "{\n    \"apiKey\": \"at_9OXmjQ3DMj049UJ4WJ9Fzo21TjS25\",\n    \"sinceDate\": \"2024-06-27\",\n    \"subdomains\": {\n        \"include\": [\n            \"inst\"\n        ]\n    }\n}\n",
        "options": {}
      },
      "id": "2da6cb47-7592-4b1c-9120-c7e94aace23b",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        920,
        200
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "domainsList",
        "options": {}
      },
      "id": "5a01d869-a978-49ca-8933-89bc9206d60b",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "typeVersion": 1,
      "position": [
        1160,
        400
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "32935338-866b-4b9f-9add-1291ef33dc52",
              "name": "domainsList",
              "value": "={{ $json.domainsList.replaceAll(\"inst.\", \"\") }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "9feef863-7801-49cd-b61a-dcd3ad2c7677",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1360,
        180
      ]
    },
    {
      "parameters": {
        "batchSize": 10,
        "options": {
          "reset": false
        }
      },
      "id": "cc32623d-3a29-49bb-96cf-4a91808e21fa",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        1640,
        320
      ]
    },
    {
      "parameters": {
        "url": "=https://{{ $json.domainsList }}",
        "options": {
          "allowUnauthorizedCerts": true,
          "redirect": {
            "redirect": {
              "maxRedirects": 50
            }
          },
          "response": {
            "response": {
              "fullResponse": true
            }
          },
          "timeout": 10000
        }
      },
      "id": "ca76fee1-5aa0-41dc-b8a6-e77b18a78137",
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        2000,
        340
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "445668ca-3ca6-4608-8afe-c1ed084d2e04",
              "leftValue": "={{ $json.statusCode < 400 }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "9c24a0e1-b85f-4acd-b7f8-d474b3885ea9",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        2280,
        300
      ]
    }
  ],
  "connections": {
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        null,
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "HTTP Request": [
      {
        "domainsCount": 10,
        "domainsList": [
          "inst.dialsdash.com",
          "inst.trybilcoautomotive.com",
          "inst.ugcvideolab.co",
          "inst.easywhalesify.com",
          "inst.gobilcoautomotive.com",
          "inst.quicktalentcaddy.com",
          "inst.getclinicmind.com",
          "inst.go-avance.org",
          "inst.eplannerpromail.com",
          "inst.finestrecruitingpro.com",
        ]
      }
    ]
  }
}

Now, It is visiting the given URLs. Now, my goal is to save valid URLs to Google spreadsheets. Sometimes, these URLs redirect to other URLs, and I want to save the redirected final URL. Is it possible to achieve it?

You can find a solution here: