How to get IP geolocation data via IPinfo IP Geolocation REST API? [JavaScript/AJAX Code]

An example of getting the user's location by IP address. The free IP geolocation API service is provided by IPInfo.io. The IP geolocation API key is sent to the server in the Authorization: Bearer {apikey} request header. You can request the IP geolocation API service by making HTTP GET requests. The JavaScript/AJAX code was automatically generated for the IP Geolocation API example.
How to get IP geolocation data via IPinfo IP Geolocation REST API? [JavaScript/AJAX Code] Send
GET /8.8.8.8 HTTP/1.1
Host: ipinfo.io
User-Agent: curl/7.68.0
Authorization: Bearer {ipinfo_apikey}

Updated: Viewed: 24530 times
JavaScript/AJAX code for IP Geolocation API example

JavaScript/AJAX code for IP Geolocation API Example

This JavaScript/AJAX code snippet was generated automatically for the IP Geolocation API example.
<< Back to the IP Geolocation API example

What is IP Geolocation?

With the IP Geolocation API, you can determine the approximate location of a device that is used to connect to the Internet, such as a user's mobile phone or desktop computer. IP geolocation is used to provide a better service to website users, as well as for anti-fraud checks during commercial transactions. IP geolocation is performed by looking up the user's IP address in a constantly updated database of IP addresses.

How do I request the IP Geolocation API service?

To request the IP Geolocation REST API, you must provide the IP-address that you want to check as an URL parameter and your free IP Geolocation API key as the bearer token authorization header.

GET https://ipinfo.io/8.8.8.8
Authorization: Bearer {apikey}

With the free IP Geolocation API plan, you can make 50,000 geolocation API requests per month.

Generate code snippets for JavaScript/AJAX and other programming languages

Convert your IP Geolocation API request to the PHP, JavaScript/AJAX, Node.js, Curl/Bash, Python, Java, C#/.NET code snippets using the JavaScript/AJAX code generator.