@@include('../meta.html') @@include('../link_deps.html')
@@include('../nav.html')

# How to Integrate the API Data Center Check with Your Application

You can integrate the API Data Center Check with your application by making an API call to `https://ipdatacentercheck.com/api/ip/:ip` authorized by `x-api-key`. Below are examples in different programming languages. The response will include the name of the data center, such as `{datacenter: 'AWS'}`, if the IP is from a data center, or `{datacenter: null}` if it is not.

JavaScript (Node.js) Python Ruby PHP Java

    const axios = require('axios');

    const apiKey = 'your-api-key';
    const ip = '8.8.8.8'; // Example IP

    axios.get(`https://ipdatacentercheck.com/api/ip/${ip}`, {
        headers: {
            'x-api-key': apiKey
        }
    })
    .then(response => {
        console.log(response.data); // {datacenter: 'AWS'} or {datacenter: null}
    })
    .catch(error => {
        console.error(error);
    });

    import requests

    api_key = 'your-api-key'
    ip = '8.8.8.8'  // Example IP

    url = f'https://ipdatacentercheck.com/api/ip/{ip}'
    headers = {'x-api-key': api_key}

    response = requests.get(url, headers=headers)
    print(response.json())  // {'datacenter': 'AWS'} or {'datacenter': null}

    require 'net/http'
    require 'uri'
    require 'json'

    api_key = 'your-api-key'
    ip = '8.8.8.8' # Example IP

    uri = URI.parse("https://ipdatacentercheck.com/api/ip/#{ip}")
    request = Net::HTTP::Get.new(uri)
    request["x-api-key"] = api_key

    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
        http.request(request)
    end

    puts JSON.parse(response.body) # {'datacenter': 'AWS'} or {'datacenter': null}

     [
            "header" => "x-api-key: $api_key"
        ]
    ];

    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);
    $data = json_decode($response, true);

    print_r($data); // ['datacenter' => 'AWS'] or ['datacenter' => null]
    ?>

    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.URL;

    public class Main {
        public static void main(String[] args) {
            try {
                String apiKey = "your-api-key";
                String ip = "8.8.8.8"; // Example IP
                URL obj = new URL(url);
                HttpURLConnection con = (HttpURLConnection) obj.openConnection();
                con.setRequestMethod("GET");
                con.setRequestProperty("x-api-key", apiKey);

                int responseCode = con.getResponseCode();
                BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String inputLine;
                StringBuffer response = new StringBuffer();

                while ((inputLine = in.readLine()) != null) {
                    response.append(inputLine);
                }
                in.close();

                System.out.println(response.toString()); // {'datacenter': 'AWS'} or {'datacenter': null}
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

@@include('../price_card.html') @@include('../footer.html') @@include('../script_deps.html')