ipdata/api-client

API client for ipdata.co

Package info

github.com/ipdata/php

pkg:composer/ipdata/api-client

Statistics

Installs: 97 387

Dependents: 1

Suggesters: 0

Stars: 18

Open Issues: 1

0.1.2 2026-02-24 05:43 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT a873513aa2e7821efe09fd194cb65cbb403f3fb9

  • Tobias Nyholm <tobias.nyholm.woop@gmail.com>

README

An API client to communicate with Ipdata.co.

Install

composer require ipdata/api-client

The client is built upon PSR standards. We use PSR-18 for HTTP client and PSR-17 for RequestFactory. These needs to be passed to the client's constructor.

Example packages for PSR-17 and PSR-18:

composer require nyholm/psr7 symfony/http-client
use Ipdata\ApiClient\Ipdata;
use Symfony\Component\HttpClient\Psr18Client;
use Nyholm\Psr7\Factory\Psr17Factory;

$httpClient = new Psr18Client();
$psr17Factory = new Psr17Factory();
$ipdata = new Ipdata('my_api_key', $httpClient, $psr17Factory);

EU endpoint

To route requests through ipdata's EU servers (Paris, Ireland and Frankfurt) for GDPR compliance, pass the EU base URL:

$ipdata = new Ipdata('my_api_key', $httpClient, $psr17Factory, Ipdata::EU_BASE_URL);

How to use

Look up your own IP

Call lookup() with no arguments to get the location of the calling IP address.

$data = $ipdata->lookup();

Look up a specific IP

To send a geocode request you simply need to provide the IP address you are interested in.

$data = $ipdata->lookup('69.78.70.144');
echo json_encode($data, JSON_PRETTY_PRINT);

The output will be the response from the API server with one additional status field.

{
 "ip": "69.78.70.144",
 "is_eu": false,
 "city": null,
 "region": null,
 "region_code": null,
 "country_name": "United States",
 "country_code": "US",
 "continent_name": "North America",
 "continent_code": "NA",
 "latitude": 37.751,
 "longitude": -97.822,
 "postal": null,
 "calling_code": "1",
 "flag": "https:\/\/ipdata.co\/flags\/us.png",
 "emoji_flag": "\ud83c\uddfa\ud83c\uddf8",
 "emoji_unicode": "U+1F1FA U+1F1F8",
 "company": {
 "name": "Verizon Wireless",
 "domain": "verizonwireless.com",
 "network": "69.78.0.0\/16",
 "type": "isp"
 },
 "asn": {
 "asn": "AS6167",
 "name": "Cellco Partnership DBA Verizon Wireless",
 "domain": "verizonwireless.com",
 "route": "69.78.0.0\/16",
 "type": "business"
 },
 "carrier": {
 "name": "Verizon",
 "mcc": "310",
 "mnc": "004"
 },
 "languages": [
 {
 "name": "English",
 "native": "English"
 }
 ],
 "currency": {
 "name": "US Dollar",
 "code": "USD",
 "symbol": "$",
 "native": "$",
 "plural": "US dollars"
 },
 "time_zone": {
 "name": "America\/Chicago",
 "abbr": "CST",
 "offset": "-0600",
 "is_dst": false,
 "current_time": "2020-01-25T06:14:37.081772-06:00"
 },
 "threat": {
 "is_tor": false,
 "is_vpn": false,
 "is_icloud_relay": false,
 "is_proxy": false,
 "is_datacenter": false,
 "is_anonymous": false,
 "is_known_attacker": false,
 "is_known_abuser": false,
 "is_threat": false,
 "is_bogon": false,
 "blocklists": [],
 "scores": {
 "vpn_score": 0,
 "proxy_score": 0,
 "threat_score": 0,
 "trust_score": 0
 }
 },
 "count": "6",
 "status": 200
}

If you are not interested in all the fields in the response, you may query only the fields you want.

$data = $ipdata->lookup('69.78.70.144', ['longitude', 'latitude', 'country_name']);
echo json_encode($data, JSON_PRETTY_PRINT);
{
 "longitude": -97.822,
 "latitude": 37.751,
 "country_name": "United States",
 "status": 200
}

Bulk request

If you want to look up multiple IPs at the same time you may use the bulkLookup() function.

$data = $ipdata->bulkLookup(['1.1.1.1', '69.78.70.144'], ['longitude', 'latitude', 'country_name']);
echo json_encode($data, JSON_PRETTY_PRINT);
{
 "0": {
 "longitude": 143.2104,
 "latitude": -33.494,
 "country_name": "Australia"
 },
 "1": {
 "longitude": -97.822,
 "latitude": 37.751,
 "country_name": "United States"
 },
 "status": 200
}

Available Fields

A list of all the fields returned by the API is maintained at Response Fields

Errors

A list of possible errors is available at Status Codes