Skip to main content

5. Examples of API requests

After the initial installation, you need to write a script that will change user settings. The settings are changed using HTTP requests to the ISP Go API. The examples below use curl from the command line to generate requests.

# Adding and removing user IP
curl -X PUT -d "[\"192.168.5.1\"]" http://api.isp.com/users/aep/ip/ 
curl http://api.isp.com/users/aep/ip/ 
curl -X DELETE http://api.isp.com/users/aep/ip/ 
curl http://api.isp.com/users/aep/ip/ 
curl -X PUT -d "[\"192.168.5.1\"]" http://api.isp.com/users/aep/ip/ 

# Categories list in json format. 
curl http://api.isp.com/categories/ 
curl http://api.isp.com/categorygroups/ 

# Global white list # Replacing the entire list 
curl -X PUT -d '["magazine.com", "feed.com"]' http://api.isp.com/whitelist/ 
curl http://api.isp.com/whitelist/ 

# Add and remove one record at a time 
curl -X POST -d '["magazine.com"]' http://api.isp.com/whitelist/ 
curl -X DELETE http://api.isp.com/whitelist/feed.com 
curl http://api.isp.com/whitelist/ 

# Global black list works similarly 
curl http://api.isp.com/blacklist/ 

# Filter configuring:
# Complete replacement of the list of blocked categories: 
curl -X PUT -d '[3, 4, 5, 11]' http://api.isp.com/users/aep/filter/ 

# Add and remove one category at a time: 
curl -X POST -d '[6]' http://api.isp.com/users/aep/filter/ 
curl -X DELETE http://api.isp.com/users/aep/filter/5 
curl http://api.isp.com/users/aep/filter/ 

# black and white lists of users: 
# complete replacement:
curl -X PUT -d '["dark.com", "orange.com", "red.com", "cyan.com"]' http://api.isp.com/users/aep/blacklist/ 

# Add and remove one domain at a time: 
curl -X POST -d '["antigreen.com"]' http://api.isp.com/users/aep/blacklist/ 
curl -X DELETE http://api.isp.com/users/aep/blacklist/orange.com 
curl http://api.isp.com/users/aep/blacklist/ 

# White list works similarly 
curl http://api.isp.com/users/aep/whitelist/

To enable the mode "Use the white list only" for a user you need to add a root domain to the black list:

curl -X POST -d '["-"]' http://api.isp.com/users/aep/blacklist/

To remove the root domain, use:

curl -X DELETE http://api.isp.com/users/aep/blacklist/-

There is a non-removable and non-editable whitelist with the highest priority, which is not accessible through any administration interface, which includes safedns.com addresses, antivirus update sites, Windows update sites, etc.


An example of a PHP script for accessing the API
<?php
// The examples file requires PHP curl extension installed 
// Address of the API server 
$server = 'http://api.isp.com'; 
function api_request($url, $method = 'GET', $data = null) { 
	$ch = curl_init($url); 
	curl_setopt ($ch, CURLOPT_HEADER, 0); 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); 
	if (!is_null($data)) curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 
	$out = curl_exec($ch); 
  
  	$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
  
  	switch ($return_code) { 
      case 200: 
        if (strlen($out)) return json_decode($out); 
        else return "OKrn"; 
        break; 
      case 400: 
        throw new Exception('Bad request'); 
        break; 
      default: throw new Exception('Error');
    } 
} 
/* 
User record is created automatically when trying 
To record any information about the user
*/ 

// Add to a user with an identifier aep ip-address 192.168.5.1 
print api_request($server."/users/aep/ip/", 'POST', '["192.168.5.1"]');

// Replace the list of ip-addresses of the user aep to 192.168.5.1, 192.168.5.2 
print api_request($server."/users/aep/ip/", 'PUT', '["192.168.5.1", "192.168.5.2"]'); 

// Delete ip-addresses 192.168.5.1 from the list of addresses of the user aep 
print api_request($server."/users/aep/ip/192.168.5.1", 'DELETE'); 

// Return a list of ip-addresses for the user aep 
$result = api_request($server."/users/aep/ip/", 'GET'); 
var_dump($result); 

// Delete the whole list of ip-addresses of the user aep 
print api_request($server."/users/aep/ip/", 'DELETE'); 
?>