IP Geolocation API JavaScript SDK
Overview
The official JavaScript Library for IPGeolocation.io's set of APIs, provides a quick, developer friendly way to access IP Location, Security, Timezone, Astronomy, ASN, Abuse Contact, and useragent data. Lookup your own IP or provide any IPv4, IPv6 or domain name to get structured results in JavaScript (JS), without the need for manual HTTP requests handling.
- IP Location API: Get all-in-one unified solution for location (city, locality, state, country, etc.), currency, network (AS number, ASN name, organization, asn type, date of allocation, company/ISP name, company type, company domain), timezone , useragent string parsing, security (threat score, is_tor, is_bot, proxy_provider, cloud_provider), and abuse contact (route/CIDR network, country, address, email, phone numbers) information.
- IP Security API: Get security, network, location, hostname, timezone and useragent parsing.
- ASN API: Get ASN details along with peers, upstreams, downstreams, routes, and raw WHOIS.
- Abuse Contact API: Get abuse emails, phone numbers, kind, organization, route/CIDR network and country.
- Astronomy API: Get sunrise, sunset, moonrise, moonset, moon phases with precise twilight period times in combination with location information.
- Timezone API: Get timezone name, multiple time formats, daylight saving status and its details along with location information.
- Timezone Convert API: Convert time between timezone names, geo coordinates, location addresses, IATA codes, ICAO codes, or UN/LOCODE.
- User Agent API: Get browser, Operating System, and device info from single or multiple Useragent string parsing.
This library aims to empower developers to integrate threat intelligence, personalization, fraud prevention, compliance, and analytics features directly into web based applications. Whether you're enriching signup forms with ip geolocation data, localizing content, embedding threat intelligence in back-end systems, or converting time zones and currencies, the library ensures seamless, scalable integration with IPGeolocation.io’s global API infrastructure.
Based on:
- API version: 2.0
Official Release:
- Available on
- Source Code: GitHub Repository
Requirements
- NPM or Yarm Package manager
- API Key from IPGeolocation.io
Installation
1.Using NPM
2.Using Yarn
Alternatively, if you use Yarn:
3.Manual Installation
To include the SDK manually:
or with Yarn:
API Plan Tiers and Documentation
The documentation below corresponds to the four available API tier plans:
- Developer Plan (Free): Full Documentation
- Standard Plan: Full Documentation
- Advance Plan: Full Documentation
- Security Plan: Full Documentation
For a detailed comparison of what each plan offers, visit the Pricing Page.
API Endpoints
All URIs are relative to https://api.ipgeolocation.io/v2
| Class | Method | HTTP request | Description |
|---|---|---|---|
| IPGeolocationAPI | getIpGeolocation | GET /ipgeo | Get geolocation data for a single IP address |
| IPGeolocationAPI | getBulkIpGeolocation | POST /ipgeo-bulk | Get geolocation data for multiple IP addresses |
| IPSecurityAPI | getIpSecurityInfo | GET /security | Get threat intelligence for a single IP address |
| IPSecurityAPI | getBulkIpSecurityInfo | POST /security-bulk | Get threat intelligence for multiple IP addresses |
| ASNLookupAPI | getAsnInfo | GET /asn | Get details of any ASN number |
| AbuseContactAPI | getAbuseContactInfo | GET /abuse | Retrieve abuse contact data for an IP address |
| AstronomyAPI | getAstronomyDetails | GET /astronomy | Get sun and moon timings and positions |
| TimezoneAPI | getTimezoneInfo | GET /timezone | Get timezone information based on IP, coordinates, or name |
| TimeConversionAPI | convertTimeBetweenTimezones | GET /timezone/convert | Convert time from one timezone to another |
| UserAgentAPI | getUserAgentDetails | GET /user-agent | Parse a single user-agent string |
| UserAgentAPI | parseBulkUserAgentStrings | POST /user-agent-bulk | Parse multiple user-agent strings |
| UserAgentAPI | parseUserAgentString | POST /user-agent | Alternate method to parse a single user-agent string |
Fields and Methods Availability
IP Geolocation offers four plans from billing point of view: Free, Standard, Security, Advance. The availability of each method calling from the respective class, over all plans are presented below.
| Class | Method | Free | Standard | Security | Advance |
|---|---|---|---|---|---|
| IPGeolocationAPI | getIpGeolocation | ||||
| IPGeolocationAPI | getBulkIpGeolocation | ||||
| IPSecurityAPI | getIpSecurityInfo | ||||
| IPSecurityAPI | getBulkIpSecurityInfo | ||||
| ASNLookupAPI | getAsnInfo | ||||
| AbuseContactAPI | getAbuseContactInfo | ||||
| AstronomyAPI | getAstronomyDetails | ||||
| TimezoneAPI | getTimezoneInfo | ||||
| TimeConversionAPI | convertTimeBetweenTimezones | ||||
| UserAgentAPI | getUserAgentDetails | ||||
| UserAgentAPI | parseBulkUserAgentStrings | ||||
| UserAgentAPI | parseUserAgentString |
The availability of fields in every API endpoint across all API plans is provided in the Reference Table within each respective API Documentation. e.g., for IPGeolocationApi, please visit https://ipgeolocation.io/ip-location-api.html#reference-to-ipgeolocation-api-response.
Authentication Setup
To authenticate API requests, you'll need an API key from ipgeolocation.io.
1.How to Get Your API Key
- Sign up here: https://app.ipgeolocation.io/signup
- (optional) Verify your email, if you signed up using email.
- Log in to your account: https://app.ipgeolocation.io/login
- After logging in, navigate to your Dashboard to find your API key: https://app.ipgeolocation.io/dashboard
2.ApiKeyAuth
Once you have the key, initialize the SDK client with it:
3.Request Origin - keyless access
If you don't set an API key, the IPGeolocation API can still authenticate your request using request origin. This is useful if:
- You're using the SDK from a browser or server with allowed referrer/IP
- Your keyless usage is enabled in the dashboard, by adding your domain name as Request Origin in
Add API keysection.
See this section for more details.
In this case, just skip setting the API key, and the API will automatically detect your request origin:
IP Geolocation Examples
This section shows how to use the getIpGeolocation() method from the JavaScript SDK across Free, Standard, and Advanced subscription tiers. Each example highlights different parameter combinations: fields , include , and excludes .
Parameters
-
fields: Use this parameter to include specific fields in the response. -
excludes: Use this parameter to omit specific fields from the response. -
include: Use this parameter to add optional modules to the response, such as:-
security -
user_agent -
hostname -
liveHostname -
hostnameFallbackLive -
abuse -
dma -
timezone
-
For the full list of supported fields/modules, refer to the IP Geolocation API Docs.
The ip parameter in the SDK can accept any valid IPv4 address, IPv6 address, or domain name. If the ip= parameter is not specified, the API will return information about the public IP of the machine.
1.Developer (Free) Plan Examples
a.Get Default Fields
Sample Response:
Filtering Specific Fields from the Response (Use of exclude and fields ).
Sample Response:
2.Standard Plan Examples
a.Geolocation with Default Fields
Sample Response:
3.Retrieving Geolocation Data in Multiple Languages
Here is an example to get the geolocation data for IP address '2001:4230:4890::1' in French language:
Sample Response:
a.Include Hostname, Timezone, and User-Agent
Sample Response:
The IP Geolocation API supports hostname lookup for all paid subscriptions. However, this is not included by default. To enable hostname resolution, use the include parameter with one of the following options:
-
hostname: Performs a quick lookup using the internal hostname database. If no match is found, the IP is returned as-is. This is fast but may produce incomplete results. -
liveHostname: Queries live sources for accurate hostname resolution. This may increase response time. -
hostnameFallbackLive: Attempts the internal database first, and falls back to live sources if no result is found. This option provides a balance of speed and reliability.
4.Advanced Plan Example
a.Include DMA, Abuse, and Security
Sample Response:
These examples demonstrate typical usage of the IP Geolocation API with different subscription tiers. Use fields to specify exactly which data to receive, include for optional data like security and user agent, and excludes to omit specific keys from the response.
All features available in the Free plan are also included in the Standard and Advanced plans. Similarly, all features of the Standard plan are available in the Advanced plan.
5.Bulk IP Geolocation Examples
The SDK supports bulk IP geolocation using getBulkIpGeolocation() . This is available for Standard and Advanced plans. All parameters like fields , include , and excludes can be used in bulk requests.
IP Security Examples
The getIpSecurityInfo() method lets you query threat intelligence, proxy/VPN detection, and risk metadata for IP addresses.
For full endpoint specifications, refer to the IP Security API documentation.
1.Get Security API Default Fields
Sample Response:
2.Include Multiple Optional Fields
Sample Response:
You can get all the available fields in standard plan in combination with security data, when subscribed to security plan.
3.Request with Field Filtering
Sample Response:
4.Bulk IP Security Lookup
The SDK also supports bulk IP Security requests using the getBulkIpSecurityInfo() method. All parameters like fields , include , and excludes can also be used in bulk requests.
ASN API Examples
This section provides usage examples of the getAsnInfo() method from the SDK. These methods allow developers to retrieve detailed ASN-level network data either by ASN number or by IP address.
ASN API is only available in the Advanced subscription plans.
Refer to the ASN API documentation for a detailed list of supported fields and behaviors.
1.Get ASN Information by IP Address
Sample Response:
2.Get ASN Information by ASN Number
Sample Response:
3.Combine All objects using Include
Sample Response:
Abuse Contact API Examples
This section demonstrates how to use the getAbuseContactInfo() method of the SDK. This API helps security teams, hosting providers, and compliance professionals quickly identify the correct abuse reporting contacts for any IPv4 or IPv6 address.
You can retrieve data like the responsible organization, role, contact emails, phone numbers, and address to take appropriate mitigation action against abusive or malicious activity.
Abuse Contact API is only available in the Advanced Plan.
Refer to the official Abuse Contact API documentation for details on all available fields.
1.Lookup Abuse Contact by IP
Sample Response:
2.Lookup Abuse Contact with Specific Fields
Sample Response:
3.Lookup Abuse Contact while Excluding Fields
Sample Response:
Timezone API Examples
This section provides usage examples of the getTimezoneInfo() method from the JavaScript SDK, showcasing how to fetch timezone and time-related data using different query types — IP address, latitude/longitude, timezone ID, IATA code, ICAO code, or UN/LOCODE.
For full API specifications, refer to the Timezone API documentation.
1.Get Timezone by IP Address
Sample Response:
2.Get Timezone by Timezone Name
Sample Response:
3.Get Timezone from Any Address
Sample Response:
4.Get Timezone from Location Coordinates
Sample Response:
5.Get Timezone and Airport Details from IATA Code
Sample Response:
You can also fetch Airport Details and Timezone using any ICAO code by passing the icaoCode parameter.
6.Get Timezone and City Details from UN/LOCODE
Sample Response:
Timezone Converter API Examples
This section provides usage examples of the convertTimeBetweenTimezones() method from the SDK. The Timezone Converter API allows you to convert a specific time from one timezone to another using timezone identifiers and optional date/time inputs.
For more details, refer to the Timezone Converter API documentation.
1.Convert Current Time from One Timezone to Another
Sample Response:
You can convert time from any timezone to another using:
- Coordinate (latitude & longitude)
- Locations (city or address)
- IATA codes
- ICAO codes
- UN/LOCODE
Simply provide the appropriate source and target parameters in the method.
User Agent API Examples
This section provides usage examples of the getUserAgentDetails() and parseBulkUserAgentStrings() methods from the JavaScript SDK. The User Agent API extracts and classifies information from user agent strings, including browser, engine, device, OS, and type metadata.
For full explanation, visit the User Agent API documentation.
1.Parse a Basic User Agent String
Sample Response:
If you don’t pass any userAgent string, the API will return data of the device's current User-Agent automatically.
2.Bulk User Agent Parsing Example
The SDK also supports bulk User Agent parsing using the parseBulkUserAgentStrings() method. This allows parsing multiple user agent strings in a single request. All fields available in single-user-agent parsing are returned per entry.
Bulk User Agent API is only available for paid plans.
Astronomy API Examples
This section provides usage examples of the getAstronomyDetails() method from the SDK, allowing developers to fetch sun and moon timings and position data based on coordinates, IP, or location string.
Refer to the official Astronomy API documentation for more details.
1.Lookup Astronomy API by Coordinates
Sample Response:
2.Lookup Astronomy API by IP Address
Sample Response:
3.Lookup Astronomy API by Location String
Sample Response:
4.Lookup Astronomy API for Specific Date
Sample Response:
5.Lookup Location info in Different Language
You can also get Astronomy Data in other languages. This feature is only available for paid subscriptions.
Sample Response:
Models
- ASNConnection
- ASNResponse
- ASNDetails
- Abuse
- AbuseResponse
- AstronomyEvening
- AstronomyLocation
- AstronomyMorning
- Astronomy
- AstronomyResponse
- CountryMetadata
- Currency
- ErrorResponse
- GeolocationResponse
- BulkIPGeolocationResponse
- BulkIPGeolocationResponse1
- BulkIPRequest
- BulkIPSecurityResponse
- BulkIPSecurityResponse1
- Location
- LocationMinimal
- Network
- NetworkAsn
- NetworkCompany
- NetworkMinimal
- NetworkMinimalAsn
- NetworkMinimalCompany
- BulkUserAgentRequest
- UserAgentRequest
- Security
- SecurityAPIResponse
- TimeConversionResponse
- TimeZone
- TimeZoneDetailedResponse
- TimeZoneDstEnd
- TimeZoneDstStart
- TimezoneAirport
- TimezoneDetail
- TimezoneDetailDstEnd
- TimezoneDetailDstStart
- TimezoneLocation
- TimezoneLocode
- UserAgentData
- UserAgentDataDevice
- UserAgentDataEngine
- UserAgentDataOperatingSystem