How can we get origin country for each API request ?

We would like to know the origin country for each API request in addition to the client IP address. Is there some way to do this ?

1 7 9,126
7 REPLIES 7

hi @AMAR DEVEGOWDA

To my knowledge there is no foolproof mechanism for this. The most commonly used approach is to use an IP address to location mapping service. So you look at the origin IP address and then use one of a whole bunch of available IP address geolocation databases. I don't have personal experience to recommend one but if you search for something like "ip address to country mapping" you'll get lots of potential options.

There are a couple of issues with the above, one of them is whether the client is using a VPN because if they are you would get the country location of the VPN not the actual client.

Another way that might be more reliable but it is more complex could be to implement additional logic into your client app that accessed the phone's geo location information and then sent that in a header in the requests.

It would add additional required permissions in the app and some people may disable location tracking so it may not work in that situation.

What does everyone else think? I'm sure there are other options - does anyone have specific experience of implementing something?

Possibly obvious, and you didn't specify where you wanted that information, so in the spirit of 'no assumptions' I'll say this.

SaaS Edge attempts to resolve country based on IP automatically. "Country" is available in the custom report dimensions dropdown under the "Advanced Dimensions" section.

Were you looking to get country information in the proxy flow for a single API call for use somewhere else, or does a report solve your problem?

@Carlos Eberhardt,

Thanks for your response. I am looking for a way log the country of origin of the request as part of the run time API calls in a meta-data transaction log which we could maintain in Splunk/Loggly. Is there a way to do this ?

There are a bunch of geo location providers that return the country of origin for a given IP address. You could use any of that to obtain the Country and log them into Loggly/Splunk. But remember these services are not very accurate.

Dear @Sudhee,

Thanks for your suggestion. Infact I found a few geo location providers yesterday and was playing around with them. It seems to be one of the ways to get the country or city of origin for a given IP address.

Regards,

Amar

akoo
Participant V

Great question. This is a cat and mouse game Netflix also tries to combat, but is on-going. From the article: 'It appears that even when companies find a technical solution Netflix finds ways to fight back.' http://www.cbc.ca/news/business/netflix-crackdown-unblocking-1.3487368

After doing some research on this issue, I have found that we can use Geo Location providers services to determine the country/city of origin for a given client IP address. While some Geo Location providers have an easy user interface where you can specify the IP address and it gives a bunch of information like country, city, latitude, longitude etc. I tried out a few of them and below I have listed a few of them for reference, which gave correct results in my simple tests:

IP Location - https://www.iplocation.net/

IP Lookup - http://whatismyipaddress.com/ip-lookup

And here are a few Geo Location providers who have offered APIs

InfoDB - http://ipinfodb.com/ip_location_api.php

IP-API GeoLocation API - http://ip-api.com/

We can use service callout policy to make requests to one of the API Geo Location providers and get the information about country/city of origin of client IP address from within the API Proxy.

Note: These are third party providers and the information provided may not be very accurate. So, please use it as appropriate for your needs after thorough testing.