Get client IP Address from APIGEE Proxy API

I am looking for a solution to Need to capture the client IP and create a new headers to be passed along to the API.

@apigee , @Former Community Member 

0 4 1,750
4 REPLIES 4

You can use proxy.client.ip or request.header.X-Forwarded-For to capture the client ip in assign variable to verify & then you can create new header and pass it to backend..

==

<AssignVariable>
<Name>clientip</Name>
<Template>{proxy.client.ip}</Template>
</AssignVariable>
<AssignVariable>
<Name>X-Forwarded</Name>
<Template>{request.header.X-Forwarded-For}</Template>
</AssignVariable>

==

 

ref:

https://docs.apigee.com/api-platform/reference/variables-reference

Thanks for the reply..

I tried which you shared the code. But I am still not getting the actual client IP address.

This is what I see the ip address in the Trace window. (My IP address in my machine it starts with 10.**.*.***).

 

Here is the below code for Assign Message policy.

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
<DisplayName>AM-Client IP</DisplayName>
<Property/>
<Set>
<Headers>
<Header name="TPS-Apigee-ClientIP">{proxy.client.ip}</Header>
<Header name="TPS-Apigee-X-ForwardedT">{request.header.x-forwarded-for}</Header>
</Headers>
</Set>
<AssignVariable>
<Name>TPS-Apigee-ClientIP</Name>
<Template>{proxy.client.ip}</Template>
</AssignVariable>
<AssignVariable>
<Name>TPS-Apigee-X-Forwarded</Name>
<Template>{request.header.X-Forwarded-For}</Template>
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

 

Thanks,

Subramanya

 

subramanya1987_0-1635186318193.png

 

 

A 10.*.*.* address is an address on your local area network... 

This happens alot when you are behind a proxy or firewall within  your organization's LAN. Try call the API while on a Public network and you will capture the Client's IP