IP Targeting command

https://www.popads.net/api/ip_targeting/<your list ID>?key=<your API key>
	
https://www.popads.net/api/ip_targeting?key=<your API key>
	&list_id=<your list ID>
	

Reads or modifies IP Targeting list, depending on used method (GET/POST).

list_id=...
Specifies list for reading/modifying. You can find this value on IP Targeting List Manager page.

When GET method is used, it returns list details:

https://www.popads.net/api/ip_targeting/123456?key=2513b194f41759c0c20c92b9fd1b5e968618ce54
{"id":"123456","name":"Test","mode":"exclude","items":[["8.8.4.4","8.8.8.8"],["192.168.1.1","192.168.1.5"]]}

When POST method is used, the list is overriden by list of ranges passed as POST data. Do not use multipart/form-data nor application/x-www-form-urlencoded here, text/plain is preferred. Separate each range with new line (\r, \n, \r\n), format is the same as in IP Targeting List Manager or in Campaigns editor. All ranges must be valid, an error will be returned if any of passed ranges is invalid. Result reflects count of finally stored distinct and non-overlapping ranges.

https://www.popads.net/api/ip_targeting/123456?key=2513b194f41759c0c20c92b9fd1b5e968618ce54

192.168.248.1/24
192.168.125.66
192.168.61.34 - 192.168.61.119
192.168.17.126 - 192.168.17.181
{"result":"4"}

Correct posting of range data is essential. Below is a very simple example, how to do it using PHP (5.5+, 7) and cURL. Setting proper (informative) User Agent for each distinct API query source allows us to help you in case, for example, infinite loop in some cron job.

curl_setopt_array($curl = curl_init(), [
	CURLOPT_URL =>
	'https://www.popads.net/api/ip_targeting/123456?key=2513b194f41759c0c20c92b9fd1b5e968618ce54',
	CURLOPT_RETURNTRANSFER => 1,
	CURLOPT_USERAGENT => 'PopAds API Intf',
	CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
	CURLOPT_FOLLOWLOCATION => false,
	CURLOPT_SSL_VERIFYPEER => true,
	CURLOPT_HEADER => false,
	CURLOPT_HTTPHEADER => ['Accept: text/plain,application/json;q=0.9', 'Content-Type: text/plain'],
	CURLOPT_POST => 1,
	CURLOPT_POSTFIELDS =>
	"192.168.248.1/24\n192.168.125.66\n192.168.61.34-192.168.61.119\n192.168.17.126-192.168.17.181"
]);
$result = curl_exec($curl);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) {
	$result = json_decode($result, true);
	print "Stored " . $result['result'] . " ranges";
} else {
	/* Error */
	if ($result = json_decode($result, true))
		print "An error occurred: " . $result['errors'][0]['code'] . ' ' . $result['errors'][0]['title'];
	else
		print "Unknown response: " . $result;
}
curl_close($curl);
			

Various errors may occur. Apart from obvious ones, as in case you would like to update non-existent or non-owned list...

{"errors":[{"status":500,"code":69,"title":"IP Targeting list not found"}]}

...you may accidentally post a corrupted list.

https://www.popads.net/api/ip_targeting/123456?key=2513b194f41759c0c20c92b9fd1b5e968618ce54

192.168.248.1/
192.168..66
192.168.61.34 - 192.168.61.119
192.168.17.126 - 192.168.17.181
{"errors":[{"status":500,"code":62,"title":"Line \"192.168.248.1\/\" unrecognized as IP range"},{"status":500,"code":62,"title":"Line \"192.168..66\" unrecognized as IP range"}]}