Clearing the Cache of a Site Identity Without Knowing the Site ID nor the Site Identity

The following code is written in PHP and assumes that the client knows only the domain and protocol of the Site Identity where it intends on purging the cache:

  1. The client goes to the discovery page and retrieves all Site Identities through the “siteidentites” link relation.
  2. The client parses the returned JSON, which includes embedded individual Site Identities, and finds the Cache Purge resource through the “cachepurge” link relation of the Site Identity that matches the correct domain and protocol.
  3. The client creates a cache purge job by making a POST request to the Cache Purge resource and grabs the URL of the cache purge job from the response (also available in the Location header) and prints this URL on the screen. At this point anyone can hit the cache purge job URL and be notified if the cache is still processing (Status Code 202 and processing message in JSON response) or if the cache purge is complete (status code 200 and completed message in JSON response).

//functuion for making cURL requests
function curl($url,$method,$data){

//cURL call
$ch = curl_init();

curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);

if($output !== false || curl_error($ch)) {

$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($status,$output);



//list of known variables
$protocol = "http";
$ip = "";

//call the discovery page
$discovery = """;

//Part 1 and 2: Client makes an API request to discover page, finds the all site identities resource,
calls it and finds the correct site identity and its cachepurge resource
$request = curl($discovery);

if ($request[0] == 200){
$json = json_decode($request[1],true);

$siteidentities = $json['_links']['siteidentities']["href"];


$request = curl($siteidentities);

if ($request[0] == 200){
$json = json_decode($request[1],true);

//how many site identies
$length = count($json["_embedded"]);


//find the site identity that matches ip and protocol
if($json["_embedded"][$i]["BackEndIPAddress"] == $ip && $json["_embedded"][$i]["BackEndProtocol"] ==
$cachepurge = $json["_embedded"][$i]["_links"]["cachepurge"]["href"];

//Part 3: Client creates a cache purge job and prints the cache purge job id URL on the screen to be checked for progress

$request = curl($cachepurge,"POST"," "); //POST request

//we expect to get a created cache purge job, meaning status code 201
if($request[0] == 201){

$json = json_decode($request[1],true);

//print the cache purge job URL on the screen
echo $json['_links']['self']["href"];