IP2Location Data Connector

The IP2Location Data Connector provides access to the IP2Location.io API. This Data Connector can be used to retieve geographic locations of IP addresses.

Constructor

IP2Location(key) → {object}

We recommend that you create a Data Connector Configuration called "IP2Location" via the Verj.io Runtime Environment's Administration Application.

A IP2Location Data Connector is then available at connectors.verjio.ip2location using that configuration.

If you are unable to do that, you may use this constructor to create a new IP2Location Data Connector.

This constructor accepts an API key.

Parameters:
Name Type Description
key string

IP2Location API key.

Returns:
object

The IP2Location Data Connector.

Functions

handleError(response)

Checks an API response for errors. If an error is encountered, the appropriate Error is thrown.

Parameters:
Name Type Description
response object

The response from a services.rest request.

See:
Throws:
  • HttpRequestError

    Thrown when the year is not supported or another parameter is invalid.

  • HttpNotFoundError

    Thrown when the country code is not recognised or the requested endpoint is not found.

  • HttpServerError

    Thrown when the API responded with a server error.

Example:
try {
	connectors.verjio.ip2location.query(fields.ip.value);
}
catch (e) {
	if (e instanceof HttpRequestError) {
		event.owner.addErrorMessage(e.message);
	}
	if (e instanceof HttpServerError) {
	  event.owner.addErrorMessage('Unable to get IP location');
	}
}

query(ip) → (nullable) {object}

Retrieves the location of a specified IP address.

Parameters:
Name Type Description
ip string

IP address to query.

Returns:
object

API response object containing location and network details. Returns null if the IP address was omitted.

Examples:
// Get location details for a specific IP address
const details = connectors.verjio.ip2location.query(fields.ip.value);

fields.location.value = `${details.city_name}, ${details.region_name}, ${details.country_name}`;
fields.lat.value = details.latitude;
fields.lng.value = details.longitude;
// Get location details for the requesting user
// e.g. the IP of the user connecting to the form or service
connectors.verjio.ip2location.query(client.request.remoteAddr);
Copyright Ebase Technology 2024