How to geolocate an IP Address in Salesforce Apex
1 min readFeb 19, 2020
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.