IPQS
Stats & Averages

About

Third-party services and your platform can access average fraud rates, total devices, and total page views based on the optional custom variables passed, such as "userID" and "transactionID". This API makes it easy to retrieve average fraud rates so your platform can perform the necessary business logic to mitigate any potential risk.

  • You can search for any custom tracking variable established in your account's custom tracking variables passed as part of your original API lookup requests by attaching it to the stats API request, such as "userID" and "transactionID" in the example below. These variables are completely optional, so you may remove them from the API request.
  • The country variable accepts the two-letter country code format (e.g., "US", "FR", etc.)
  • start_date and end_date use the "yyyy-mm-dd" format.
  • The ConversionStatus variable, when attached to the request, allows you to search by leads that have received postback notices. The three options for ConversionStatus are true (converted), false (denied), and not_marked (default status).

Example Request

Replace COUNTRY_CODE with the two-letter country code, YYYY-MM-DD with your start and end dates, and USER_ID and TRANSACTION_ID with your custom tracking variables.

https://www.ipqualityscore.com/api/YOUR_API_KEY_HERE/proxy/average?country=COUNTRY_CODE&start_date=YYYY-MM-DD&end_date=YYYY-MM-DD&userID=USER_ID&transactionID=TRANSACTION_ID

Request Parameters

Field Description Possible Values
country The 2 character country code of the IP lookups to average or 'all'. (OPTIONAL) US, UA, etc...
start_date The start date for generating the average. (OPTIONAL) yyyy-mm-dd hh:mm:ss formatted date
end_date The end date for generating the average. (OPTIONAL) yyyy-mm-dd hh:mm:ss formatted date
transactionID Custom variable string
userID Custom variable string
subUserID Custom variable string
campaignID Custom variable string
subCampaignID Custom variable string
publisherID Custom variable string
gclid Custom variable string
email Custom variable string
clickID Custom variable string
conversionID Custom variable string
// Create a function to process fetching our average.
function getIPQAVG($user, $country, $apiKey) {
	
	// Create the URL depending on if country is passed or not.
	if(!empty($country) && $country !== 'all') {
		$json_string = "https://www.ipqualityscore.com/api/".$apiKey."/proxy/average?userID=".$user."&country=".$country;
	} else {
		$json_string = "https://www.ipqualityscore.com/api/".$apiKey."/proxy/average?userID=".$user;
	}
	
	$jsondata = file_get_contents($json_string);
	$obj = json_decode($jsondata, true);
	return $obj;
}

// Set example variables.
$user = 1;
$apiKey = 'YOUR_API_KEY_HERE';

$IPQstats = getIPQAVG($user, 'all', $apiKey);
if($IPQstats['fraud_average'] !== null) {
	$fraud_avg = $IPQstats['fraud_average'];
} else {
	$fraud_avg = '0.00';
}

// Print average.
echo $fraud_avg;
# THIS SHOULD NEVER BE USED IN PRODUCTION AS IS!

# You may need to install Requests pip
# python -m pip install requests

from http.server import BaseHTTPRequestHandler, HTTPServer
import json
import requests

hostName = "localhost"
serverPort = 8080

class IPQS:
    key = "YOUR_API_KEY_HERE"

    def proxy_vpn_averages_api(self, vars: dict = {}) -> dict:
        """Method used to lookup Proxy & VPN Detection Stats & Averages API 

        Args:
            vars (dict, optional): Reffer to https://www.ipqualityscore.com/documentation/proxy-detection-api/averages for variables. 
                                    You would add your custom tracking variables here as well

        Returns:
            dict: Returns json response in an array.
        """
        url = "https://www.ipqualityscore.com/api/%s/proxy/average" % (self.key)
        if bool(vars):
            x = requests.get(url, params = vars)
        else:   
            x = requests.get(url)
        return (json.loads(x.text))




class MyServer(BaseHTTPRequestHandler):
    """This is an example basic web server. we limited it to handle "/" path only."""

    def do_GET(self):
        if self.path == "/":
            self.send_response(200)
            self.send_header("Content-type", "text/html")
            self.end_headers()
            ipqs = IPQS()
            
            #Example using a custom Tracking such as UserID 
            #print(ipqs.proxy_vpn_averages_api({'UserID':1})["fraud_average"])

            print(ipqs.proxy_vpn_averages_api({})["fraud_average"])
            self.wfile.write(bytes("<p>This is an example do not simply copy paste.</p>", "utf-8"))
            self.wfile.write(bytes("</body></html>", "utf-8"))

if __name__ == "__main__":        
    webServer = HTTPServer((hostName, serverPort), MyServer)
    print("Server started http://%s:%s" % (hostName, serverPort))

    try:
        webServer.serve_forever()
    except KeyboardInterrupt:
        pass

    webServer.server_close()
    print("Server stopped.")

Ready to eliminate fraud?

Start fighting fraud now with 1,000 Free Lookups!

We're happy to answer any questions or concerns.

Chat with our fraud detection experts any day of the week.

Call us at: (800) 713-2618