I was using N8N Rest API and it was working on the desktop version. Now I switched n8n to npm version and the API ist not working any more. I am calling it via http://localhost:5678/api/v1/workflows?active=true&limit=100’ using newly generated API KEY.
I also tried with API playground and there it is working fine.
What is the error message (if any)?
ERROR: The service refused the connection - perhaps it is offline
connect ECONNREFUSED ::1:5678
The default localhost is 127.0.0.1. In Windows I added 127.0.0.2 to the hosts file. Then I can reach the UI via both IPs. But the problem still persists also in 127.0.0.2.
This is happening because localhost is resolving to ::1 (IP v6), and n8n isn’t listening to that IP because N8N_LISTEN_ADDRESS defaults to 0.0.0.0 (all IP v4).
Please try setting N8N_LISTEN_ADDRESS to ::.
Another option would be to force n8n to use IPv4 by setting NODEJS_PREFER_IPV4 to true.