JSONP/CORS Requests


JSONP and CORS are supported, allowing you to use ipinfo.io entirely in client-side code. For JSONP you just need to specify the callback parameter, e.g. https://www.ip.cc/?callback=callback&token=$TOKEN.

Request visitor data using Fetch API (Promise)

fetch("https://api.ip.cc/json?token=$TOKEN").then(
  (response) => response.json()
).then(
  (jsonResponse) => console.log(jsonResponse.ip, jsonResponse.country)
)

Request visitor data using Fetch API (Async/Await)

const request = await fetch("https://api.ip.cc/json?token=$TOKEN")
const jsonResponse = await request.json()

console.log(jsonResponse.ip, jsonResponse.country)

Request visitor data using JSONP

<script>
  function recordData (data) {
    console.log(data.ip, data.country)
  }
</script>
<script src="https://api.ip.cc/json?callback=recordData"></script>

JSONP/CORS Requests


JSONP and CORS are supported, allowing you to use ipinfo.io entirely in client-side code. For JSONP you just need to specify the callback parameter, e.g. https://www.ip.cc/?callback=callback&token=$TOKEN.

Request visitor data using Fetch API (Promise)

fetch("https://api.ip.cc/json?token=$TOKEN").then(
  (response) => response.json()
).then(
  (jsonResponse) => console.log(jsonResponse.ip, jsonResponse.country)
)

Request visitor data using Fetch API (Async/Await)

const request = await fetch("https://api.ip.cc/json?token=$TOKEN")
const jsonResponse = await request.json()

console.log(jsonResponse.ip, jsonResponse.country)

Request visitor data using JSONP

<script>
  function recordData (data) {
    console.log(data.ip, data.country)
  }
</script>
<script src="https://api.ip.cc/json?callback=recordData"></script>