IP API Documentation
Introduction
Welcome to the official IP geolocation API documentation for FindIpInfo. This guide provides detailed instructions for integrating our free IP lookup and geolocation API into your applications using PHP or Java. Access comprehensive IP tracker data, including location, timezone, and currency, to enhance your projects with precise IP geolocation insights.
Step 1: Obtain an API Key
To authenticate API requests, you need a unique API key. Follow these steps:
- Visit findipinfo.net.
- Register or log in.
- Navigate to the API Settings in your dashboard.
- Generate and copy your API key.
Step 2: Make API Requests
To know your or a customer's IP address, use the following API endpoints:
Endpoint to Get Your Public IP:
https://findipinfo.net/api/myip
(No API key required, returns your public IP as plain text.)
Use the following endpoint to retrieve IP geolocation data.
Replace
API_KEY with your key. The IP address is optional and can be provided as a query parameter
(?ip=). If omitted, it defaults to the client's public IP.
Endpoint:
https://findipinfo.net/api/ipinfo/{API_KEY}
Optional: Add ?ip=IP_ADDRESS to specify a target IP (e.g.,
?ip=123.45.67.89).
<?php
$apiKey = 'your-api-key-here';
$ipAddress = '123.45.67.89'; // Optional: Omit or set to null to use client's IP
$url = "https://findipinfo.net/api/ipinfo/{$apiKey}" . ($ipAddress ? "?ip={$ipAddress}" : "");
try {
$response = file_get_contents($url);
$data = json_decode($response, true);
if ($data['success'] === true) {
$country = $data['data']['findipinfo']['country'];
$city = $data['data']['findipinfo']['city'];
$timezone = $data['data']['findipinfo']['timeZone'];
echo "Country: {$country}\n";
echo "City: {$city}\n";
echo "Time Zone: {$timezone}\n";
} else {
echo "Error: {$data['message']}\n";
}
} catch (Exception $e) {
echo "Request failed: {$e->getMessage()}\n";
}
?>
1. Add Dependencies
dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.google.code.gson:gson:2.11.0'
}
2. Create API Manager
import com.google.gson.Gson;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
public class ApiManager {
private static final String BASE_URL = "https://findipinfo.net/api/ipinfo/%s";
private final OkHttpClient client;
private final Gson gson;
public ApiManager() {
client = new OkHttpClient();
gson = new Gson();
}
public void fetchGeolocationData(String apiKey, String ipAddress, GeolocationCallback callback) {
String url = String.format(BASE_URL, apiKey) + (ipAddress != null ? "?ip=" + ipAddress : "");
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new okhttp3.Callback() {
@Override
public void onFailure(okhttp3.Call call, IOException e) {
callback.onFailure(e.getMessage());
}
@Override
public void onResponse(okhttp3.Call call, Response response) throws IOException {
if (!response.isSuccessful()) {
callback.onFailure("Request failed: " + response.code());
return;
}
String json = response.body().string();
GeolocationData data = gson.fromJson(json, GeolocationData.class);
callback.onSuccess(data);
}
});
}
}
3. Define Callback Interface
public interface GeolocationCallback {
void onSuccess(GeolocationData data);
void onFailure(String error);
}
4. Create Data Model
public class GeolocationData {
private boolean success;
private String message;
private FindIpInfo data;
// Getters and setters
public boolean isSuccess() { return success; }
public void setSuccess(boolean success) { this.success = success; }
public String getMessage() { return message; }
public void setMessage(String message) { this.message = message; }
public FindIpInfo getData() { return data; }
public void setData(FindIpInfo data) { this.data = data; }
public static class FindIpInfo {
private String continent;
private String country;
private String city;
private String capital;
private String country_code;
private String country_alpha_3_code;
private String region;
private String postal;
private double latitude;
private double longitude;
private String network;
private String timeZone;
private String organization;
private int system_number;
private String telephone_code;
private String currency_code;
private String currency_name;
private String currency_symbol;
private String lang_code;
private String lang_name;
private String country_domain_name;
private String flag_w40;
private String flag_w80;
private String flag_w160;
private String flag_w320;
private String flag_w640;
private String flag_svg;
// Getters and setters (omitted for brevity, add as needed)
}
}
Step 3: Handle API Errors
The API returns a success field to indicate request outcomes.
Possible values include:
- success: Request succeeded, data in
findipinfo. - ip_error: Invalid IP address.
- data_error: No geolocation data found.
- api_error: Invalid or inactive API key.
<?php
$apiKey = 'your-api-key-here';
$ipAddress = '123.45.67.89'; // Optional: Omit or set to null to use client's IP
$url = "https://findipinfo.net/api/ipinfo/{$apiKey}" . ($ipAddress ? "?ip={$ipAddress}" : "");
try {
$response = file_get_contents($url);
if ($response === false) {
echo "Connection error. Please try again.";
} else {
$data = json_decode($response, true);
if ($data['success'] === true) {
echo "Country: {$data['data']['findipinfo']['country']}\n";
} else {
echo "Error: {$data['message']} (Code: {$data['error_code'] ?? 'N/A'})\n";
}
}
} catch (Exception $e) {
echo "Request failed: {$e->getMessage()}\n";
}
?>
ApiManager apiManager = new ApiManager();
apiManager.fetchGeolocationData("your-api-key-here", "123.45.67.89", new GeolocationCallback() {
@Override
public void onSuccess(GeolocationData data) {
runOnUiThread(() -> {
if (data.isSuccess()) {
dataTextView.setText("Country: " + data.getData().getFindipinfo().getCountry());
} else {
dataTextView.setText(data.getMessage() + " (Code: " + (data.getErrorCode() != null ? data.getErrorCode() : "N/A") + ")");
}
});
}
@Override
public void onFailure(String error) {
runOnUiThread(() -> dataTextView.setText("Error: " + error));
}
});
API Response Examples
Success Response
{
"success": true,
"message": "Successfully found geolocation data",
"data": {
"findipinfo": {
"continent": "Asia",
"country": "India",
"city": "Chandigarh",
"capital": "New Delhi",
"country_code": "IN",
"country_alpha_3_code": "IND",
"region": "Chandigarh",
"postal": "160036",
"latitude": 30.7339,
"longitude": 76.7889,
"network": "2401:4900:1c6e::/47",
"timeZone": "Asia/Kolkata",
"organization": "Bharti Airtel Ltd., Telemedia Services",
"system_number": 24560,
"telephone_code": "91",
"currency_code": "INR",
"currency_name": "Indian Rupee",
"currency_symbol": "₹",
"lang_code": "HI",
"lang_name": "Hindi, English",
"country_domain_name": "in",
"flag_w40": "https://findipinfo.net/assets/flags/png/w40/in.png",
"flag_w80": "https://findipinfo.net/assets/flags/png/w80/in.png",
"flag_w160": "https://findipinfo.net/assets/flags/png/w160/in.png",
"flag_w320": "https://findipinfo.net/assets/flags/png/w320/in.png",
"flag_w640": "https://findipinfo.net/assets/flags/png/w640/in.png",
"flag_svg": "https://findipinfo.net/assets/flags/svg/in.svg"
}
}
}
Error Response (Invalid IP)
{
"success": false,
"message": "Invalid IP address",
"error_code": "ip_error"
}
Support
For assistance with API integration, contact our support team via WhatsApp Live Support Chat.