I've created a php script that will allow the removal of user properties. The script first finds all properties associated with a user and then loops to remove all of them.
When I run this for a certain user, it gets down to the foreach loop and it prints out all the the properties ($name2) but it seems to get stuck on the curl_fetch part. When I then try to pull the properties, they still exist for the user. Any ideas why this is happening? The code is below for you to take a look. Thanks in advance.
<?php
$user=$_GET['userid'];
$user_id=str_replace(array('@', '#'), array('%40', '%23'), $user);
print "User-id: $user";
print "<br /><br />";
$url=("https://admin:[email protected]/@api/users/=$user_id/properties");
$xmlString=file_get_contents($url);
$delete = "https://admin:[email protected]/@api/users/=$user_id/properties/";
$xml = new SimpleXMLElement($xmlString);
function curl_fetch($url,$username,$password,$method='DELETE')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");
return curl_exec($ch);
}
print "The following properties have been removed: ";
print "<br />";
if(!count($xml->property)) die('No properties exist for this user');
foreach($xml->property as $property) {
$name = $property['name'];
$name2=str_replace(array('@', '#'), array('%40', '%23'), $name);
print $name2;
print "<br />";
curl_fetch($delete . $name2,'admin','password');
}
?>