Mass deletion of expired keys

Hello,

We are trying to use the Web API to automate some of our maintenance task. One task that we are struggling with is to find some easy way to query the api (using php) to automatically delete all keys that have expired. We use a custom license field called update_expires that holds this information.

Any suggestions on how to solve this would be much appreciated.

Thanks in advance.

The way to do it is to find all the keys that you want to delete (use the advanced search with the custom license fields): http://wyday.com/limelm/help/api/limelm.pkey.advancedSearch/

Then, loop through the found keys, and delete them: http://wyday.com/limelm/help/api/limelm.pkey.delete/.

Does that make sense?

Also, I would recommend not deleting product keys. That's an irreversible action (you can't get the product key back once it has been deleted). A better action is to revoke the product key: http://wyday.com/limelm/help/api/limelm.pkey.revoke/

Yes, this does make sense. The problem Im having is executing the call, as there isnt much example code on advanced php queries like this. This is what I got so far:

$feature_names = array('update_expires');$feature_values = array(date('Y-m-d', strtotime('-30 days')));$feature_match = array('before');


$post_data = array('method' => 'limelm.pkey.advancedSearch','version_id' => $version_id,'api_key' => $api_key,'nojsoncallback' => 1,'format' => 'json','num' => 20);


if ($feature_names !== null){$post_data['feature_name'] = $feature_names;$post_data['feature_value'] = $feature_values;$post_data['feature_match'] = $feature_match;}


// urlencode $post_data$post_string = '';foreach ($post_data as $key => $value){if (is_array($value)){foreach ($value as $sub_value){$post_string .= $key.'[]='.urlencode($sub_value).'&';}}else$post_string .= $key.'='.urlencode($value).'&';}$post_string = rtrim($post_string, '& ');


$request = curl_init('https://wyday.com/limelm/api/rest/');curl_setopt($request, CURLOPT_HEADER, 0);curl_setopt($request, CURLOPT_ENCODING, "");curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);curl_setopt($request, CURLOPT_POSTFIELDS, $post_string);curl_setopt($request, CURLOPT_SSL_VERIFYPEER, TRUE);

In this example, I would like API to return all keys where the custom license field update_expires is more that 30 days old. However, there seems to be some error in the code, as the API doesnt return any keys. Suggestions?

Thanks

I need to know exactly what is returned to give you useful information (copy & paste the response you get from LimeLM). Also, I'm presuming you actually set the $version_id, and $api_key variables.

I get the following reply:

( [stat] => fail

 => 1    [message] => Product key not found.)


Yes, both $version_id, and $api_key variables are properly set.

We need a lot more information to help you. My guess is:

  1. You're looking in the wrong version (try changing the version_id)
  2. You're using the wrong custom license field name (double check you actually have that field name).
  3. You don't have any product keys that have a value for "update_expires" "before" 2015-03-28.

Try using the advanced search in LimeLM to find the keys first. That's easier to play around with.