Hello
I need to fetch client ip address in webhook node but I cant find the ip(like 192.168.x.x).
what should I do?
Hi there, you can find it in the webhook header response
itâs on the headers.x-real-ip, tht variable holds the ip address of your client
Hello @hossein_sharifi
In n8n, the Webhook node doesnât expose the client IP directly in the default JSON body. By default, you only see the headers, params, query and body.
Firstly, if youâre using a production/behind proxy environment, you may use headers in the Webhook node:
- Create a Set or Function node after your Webhook node:
- You can access them with an expression:
{{$json[âheadersâ][âx-forwarded-forâ] || $json[âheadersâ][âx-real-ipâ]}}
Or in a Function node:
return [
{
ip: $json.headers[âx-forwarded-forâ] || $json.headers[âx-real-ipâ]
}
]
If your reverse proxy is not configured, youâll just see the proxy/container IP (like 172.x.x.x or 127.0.0.1).
Secondly, if youâre testing locally (for devs), all requests look like theyâre coming from 127.0.0.1, so you wonât see the real client IP in the webhook data. Browsers also donât send the LAN IP (like 192.168.x.x) for security reasons.
I have created and tested an example to fetch the clientâs public IP in your frontend (e.g., Vue app) and include it in the payload that you may send to n8n. For example:
//function to get client id
async function getClientIp() {
const res = await fetch(âhttps://api.ipify.org?format=jsonâ) //example client IP
const data = await res.json()
return data.ip
}
Then send it along with your form data:
//calling the function
const ip = await getClientIp()
await fetch(âhttp://localhost:5678/webhook-test/your-webhook-idâ, {
method: âPOSTâ,
headers: { âContent-Typeâ: âapplication/jsonâ },
body: JSON.stringify({
amount: 20,
term: 5,
purpose: âHouseâ,
clientIp: ip,
}),
})
Now n8n will receive:
//payload for Webhook node in n8n
âbodyâ: {
âamountâ: 20,
âtermâ: 5,
âpurposeâ: âHouseâ,
âclientIpâ: â37.201.153.64â
}
Hereâs the preview:
Sending the IP in the body is just for used logging, analytics, or demonstration, not for trust/security. Always rely on headers (x-forwarded-for / x-real-ip), not the body as mentioned above.
Hope this answers your question. ![]()
Thanks
![]()
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
