Coder Social home page Coder Social logo

api's Introduction

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. This includes city, region, country, latitude, longitude and time zone. Both IPv4 & IPv6 type addresses are supported.

Get Location from a specific IP Address

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

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

URL Parameters

Parameter Description
IP The IP address for which you want to retrieve the 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"
}

Code samples in common languages

ruby

require 'net/http'
require 'json'

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

python

from requests import get

loc = get('https://ipapi.co/8.8.8.8/json/')
print loc.json()

php

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

Node.js

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);
    });
});

jQuery

$.getJSON('https://ipapi.co/8.8.8.8/json/', function(data){
  console.log(data)
})

Find your public IP Address and get its location

This endpoint retrieves location for your IP address.

GET https://ipapi.co/json/

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"
}

Code samples in common languages

ruby

require 'net/http'
require 'json'

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

python

from requests import get

loc = get('https://ipapi.co/json/')
print loc.json()

php

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

Node.js

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);
    });
});

jQuery

$.getJSON('https://ipapi.co/json/', function(data){
  console.log(data)
})

api's People

Contributors

ipapi-co avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

api's Issues

Problems in some browsers

Hi, I'm using your Api to get the user location.

I'm using javascript to get this information like:

fetch('https://ipapi.co/json/')
  .then( resp =>  resp.text())
  .then( data => {
  const {country_code: countryCode} = JSON.parse(data)
  fetch(`https://xxxxxxxxxx.com?country=${countryCode}`)
    .then( response=>  response.json() )
    .then((data) => console.log('some code with ', data));
})

sometimes it works ok and other times wrong.

Sometimes in Google Chrome I have this error: Failed to fetch --> testint with Chrome 38, Chrome81, Chrome80
Sometimes in Opera I have this error: Failed to fetch --> version Chrome67
Normally in Firefox I have this error: TypeError: NetworkError when attempting to fetch resource. --> version Firefox75

Can you help me please?

Thank you

CROSS ERROR

im using this api on checkout while consuming its giving cross error, how i can handle this
my code : let getIP = await axios.get("https://ipapi.co/json/");
// .then(async (response) => {console.log("RESPONSE==>",response)})
geo_data = getIP
? getIP.data
: JSON.parse(localStorage?.getItem("visitor_data"));

Wrong region code

hi!

thanks for this api, it looks awesome :)

I just found a little bug (i think), the region code for my ip is this https://ipapi.co/81.234.60.162/json/

in the api it's "AB", which is wrong I believe.

It's not a big deal, and I really don't care about it myself, but I just wanted to point it out, in case you guys are parsing any file wrongly, the "AB" could maybe from the organization?

Blocked by CORS policy

I'm using the example script at https://ipapi.co/api/?javascript#complete-location5 to use ipapi with javascript. But I get the following error. How do I fix this?

Access to fetch at 'https://ipapi.co/8.8.8.8/json/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
visitor-test.html:52 
        
GET https://ipapi.co/8.8.8.8/json/ net::ERR_FAILED 403 (Forbidden)

script used:

fetch('https://ipapi.co/8.8.8.8/json/', )
			.then(function(response) {
			  response.json().then(jsonData => {
				console.log(jsonData);
			  });
			})
			.catch(function(error) {
			  console.log(error)
			});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.