NAV
curl ruby python php Node.js jQuery java

Introduction

Documentation for IP address location API from ipapi.co.

You can use our API to lookup an IP address and get its location information.
The documentation below uses json format as an example. Other supported formats are xml, csv, yaml, jsonp.
Both IPv4 & IPv6 type addresses are supported.

Get Complete Location

Specific IP Address

require 'net/http'
require 'json'

loc = Net::HTTP.get(URI('https://ipapi.co/8.8.8.8/json/'))
puts JSON.parse(loc)
from requests import get

loc = get('https://ipapi.co/8.8.8.8/json/')
print loc.json()
<?php
    $loc = file_get_contents('https://ipapi.co/8.8.8.8/json/');
    echo $loc;
    $obj = json_decode($loc);
?>
var https = require('https');

https.get('https://ipapi.co/8.8.8.8/json/', function(resp){
    var body = ''
    resp.on('data', function(data){
        body += data;
    });

    resp.on('end', function(){
        var loc = JSON.parse(body);
        console.log(loc);
    });
});
$.getJSON('https://ipapi.co/8.8.8.8/json/', function(data){
  console.log(data)
})
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Ipapi {

    public static void main(String[] args) throws IOException {
        URL ipapi = new URL("https://ipapi.co/8.8.8.8/json/");

        URLConnection c = ipapi.openConnection();
        c.setRequestProperty("User-Agent", "java-ipapi-client");
        BufferedReader reader = new BufferedReader(
          new InputStreamReader(c.getInputStream())
        );
        String location = reader.readLine();
        reader.close();

        System.out.println(location);
    }

}
curl 'https://ipapi.co/8.8.8.8/json/'

The above command returns JSON structured like this:

{
    "ip" : "8.8.8.8", 
    "city" : "Mountain View", 
    "region" : "California", 
    "country" : "US", 
    "postal" : "94040", 
    "latitude" : 37.3845, 
    "longitude" : -122.0881,
    "timezone" : "America/Los_Angeles"
    "asn" : 15169
    "org" : "Google Inc."
}

This endpoint retrieves location for the IP address specified in the URL.

HTTP Request

GET https://ipapi.co/<IP>/json/

URL Parameters

Parameter Description
IP The IP address for which you want to retrieve the location

Your IP Address

require 'net/http'
require 'json'

loc = Net::HTTP.get(URI('https://ipapi.co/json/'))
puts JSON.parse(loc)
from requests import get

loc = get('https://ipapi.co/json/')
print loc.json()
<?php
    $loc = file_get_contents('https://ipapi.co/json/');
    echo $loc;
    $obj = json_decode($loc);
?>
var https = require('https');

https.get('https://ipapi.co/json/', function(resp){
    var body = ''
    resp.on('data', function(data){
        body += data;
    });

    resp.on('end', function(){
        var loc = JSON.parse(body);
        console.log(loc);
    });
});
$.getJSON('https://ipapi.co/json/', function(data){
  console.log(data)
})
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Ipapi {

    public static void main(String[] args) throws IOException {
        URL ipapi = new URL("https://ipapi.co/json/");

        URLConnection c = ipapi.openConnection();
        c.setRequestProperty("User-Agent", "java-ipapi-client");
        BufferedReader reader = new BufferedReader(
          new InputStreamReader(c.getInputStream())
        );
        String location = reader.readLine();
        reader.close();

        System.out.println(location);
    }

}
curl 'https://ipapi.co/json/'

Retrieve location for your IP address formatted as JSON
(say your IP address is “208.67.222.222”)

{
    "ip" : "208.67.222.222", 
    "city" : "San Francisco", 
    "region" : "California", 
    "country" : "US", 
    "postal" : "94107", 
    "latitude" : 37.7697, 
    "longitude" : -122.3933,
    "timezone" : "America/Los_Angeles"
    "asn" : 36692
    "org" : "OpenDNS, LLC"
}

This endpoint retrieves location for your IP address.

HTTP Request

GET https://ipapi.co/json/

Get Specific Location Field

Specific field for an IP

require 'net/http'

puts Net::HTTP.get(URI('https://ipapi.co/8.8.8.8/country/'))
from requests import get

print get('https://ipapi.co/8.8.8.8/country/').text
<?php
    echo file_get_contents('https://ipapi.co/8.8.8.8/country/');
?>
var https = require('https');

https.get('https://ipapi.co/8.8.8.8/country/', function(resp){
    var body = ''
    resp.on('data', function(data){
        body += data;
    });

    resp.on('end', function(){
        console.log(body);
    });
});
$.get('https://ipapi.co/8.8.8.8/country/', function(data){
  console.log(data)
})
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Ipapi {

    public static void main(String[] args) throws IOException {
        URL ipapi = new URL("https://ipapi.co/8.8.8.8/country/");

        URLConnection c = ipapi.openConnection();
        c.setRequestProperty("User-Agent", "java-ipapi-client");
        BufferedReader reader = new BufferedReader(
          new InputStreamReader(c.getInputStream())
        );
        String location = reader.readLine();
        reader.close();

        System.out.println(location);
    }

}
curl 'https://ipapi.co/8.8.8.8/country/'

The above command returns the value for the requested field (e.g. country):

US

This endpoint retrieves a specific location field for the IP address provided in the URL.

HTTP Request

GET https://ipapi.co/<IP>/<Field>/

URL Parameters

Parameter Description
IP The IP address for which you want to retrieve the location
Field ip, city, region, country, postal, latitude, longitude, timezone, latlong, asn, org










Specific field for your IP

require 'net/http'

puts Net::HTTP.get(URI('https://ipapi.co/ip/'))
from requests import get

print get('https://ipapi.co/ip/').text
<?php
    echo file_get_contents('https://ipapi.co/ip/');
?>
var https = require('https');

https.get('https://ipapi.co/ip/', function(resp){
    var body = ''
    resp.on('data', function(data){
        body += data;
    });

    resp.on('end', function(){
        console.log(body);
    });
});
$.get('https://ipapi.co/ip/', function(data){
  console.log(data)
})
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Ipapi {

    public static void main(String[] args) throws IOException {
        URL ipapi = new URL("https://ipapi.co/ip/");

        URLConnection c = ipapi.openConnection();
        c.setRequestProperty("User-Agent", "java-ipapi-client");
        BufferedReader reader = new BufferedReader(
          new InputStreamReader(c.getInputStream())
        );
        String location = reader.readLine();
        reader.close();

        System.out.println(location);
    }

}
curl 'https://ipapi.co/ip/'

Retrieve specific field (e.g. your IP address)

208.67.222.222

This endpoint retrieves a specific location field for your IP address.

HTTP Request

GET https://ipapi.co/<Field>/

URL Parameters

Parameter Description
Field ip, city, region, country, postal, latitude, longitude, timezone, latlong, asn, org










Errors

The API uses the following standard error codes:

Error Code Reason Response
400 Bad Request
404 URL Not Found
405 Method Not Allowed
429 Daily quota exceeded { “error” : true, reason": “RateLimited” }

Additional possible errors with a 200 response may be :

For an invalid IP address, the response would be
{ "error" : true, "reason": "Invalid IP Address" }

For a reserved / non-public IP address, all fields except IP address would be null
{ "ip" : "127.0.0.1", 'city':null, ... }

If there’s no information available for a field, that particular field would be assigned a value of null