Website Targeting command

https://www.popads.net/api/website_targeting[/<your list ID>]?key=<your API key>
	[&mode=(include|exclude)]
	[&name=<your list name>]
	[&strict=(0|1)]
https://www.popads.net/api/website_targeting?key=<your API key>
	[&list_id=<your list ID>]
	[&mode=(include|exclude)]
	[&name=<your list name>]
	[&strict=(0|1)]

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

list_id=...
Specifies list for reading/modifying. You can find this value on Website Targeting List Manager page. If not specified, creates a new list, in such case mode and name are mandatory.
mode=(include|exclude)
Specifies list mode. Valid for POST requests.
name=...
Specifies list name. Valid for POST requests.
strict=(0|1)
When set to 1, any inactive website ID triggers an error. Valid for POST requests.

When GET method is used, it returns list details:

https://www.popads.net/api/website_targeting/123456?key=2513b194f41759c0c20c92b9fd1b5e968618ce54
{"id":"123456","name":"Test","mode":"exclude","items":[12345, 23456, 34567, 45678]}

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

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

654321
765432
876543
987654
{"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/website_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 =>
	"6456547\n3425435\n254364\n2347623\n233442\n234357"
]);
$result = curl_exec($curl);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) == 200) {
	$result = json_decode($result, true);
	print "Stored " . $result['result'] . " IDs";
} 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":"Website Targeting list not found"}]}

...you may accidentally post a list containing invalid IDs.

https://www.popads.net/api/website_targeting/123456?key=2513b194f41759c0c20c92b9fd1b5e968618ce54&strict=1

12443
125fa44
3454376
{"errors":[{"status":500,"code":62,"title":"\"12443\" is not an active website ID"},{"status":500,"code":62,"title":"Line \"125fa44\" unrecognized as website ID"}]}

Campaign Website Targeting command

https://www.popads.net/api/campaign_website_targeting/<your campaign ID>?key=<your API key>
	[&mode=(none|global|include|exclude)]
	[&global_id=<your list ID>]
	[&strict=(0|1)]

Reads or modifies campaign's inline Website Targeting list, depending on used method (GET/POST).

mode=...
Switches campaign's targeting mode to either none, global, include, exclude. For the first two types, payload is ignored, for the latter two is mandatory.
global_id=...
Specifies list to attach. Valid only when mode is global. You can find this value on Website Targeting List Manager page.
strict=(0|1)
When set to 1, any inactive website ID triggers an error. Valid for POST requests.

When GET method is used, it returns campaign's targetting details:

https://www.popads.net/api/campaign_website_targeting/123456?key=2513b194f41759c0c20c92b9fd1b5e968618ce54
{"id":"123456","mode":"exclude","global_id":null,"items":[12345, 23456, 34567, 45678]}

If campaign is set to utilize Global Website Targeting list, the response is a bit different:

{"id":"123456","mode":"global","global_mode":"include","global_id":12345,"global_items":[12345, 23456, 34567, 45678]}

In such case, to alter the list, you have to use Website Targeting command instead of this one, passing received global_id as list ID.

In case mode returned is either exclude or include, you can alter the list by invoking POST request to this endpoint. Data format is the same as in the case of Global list. In case of success, server returns updated targeting details.

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

12435
2346547
34253452
{"id":"123456","mode":"exclude","global_id":null,"items":[12435, 2346547, 34253452]}