How to geolocate an IP Address in Salesforce Apex

Want to control your customer demographics while also gaining valuable user data at the same time? IP geolocation can do all of that and more. But you need an easy way to implement this. That’s where one of our handy APIs comes in.

We can start things off by downloading and unzipping our API client into your Apex project folder.

Hoofing it right along, we can now call iPAddressPost:

SwagIpAddressApi api = new SwagIpAddressApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'value' => 'value_example'};try {// cross your fingersSwagGeolocateResponse result = api.iPAddressPost(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

And there you have it, the easy way to identify IP address locations.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store