Using pkey.find

Hi Wyday,

I am trying to use the pkey.find function on FastSpring to determine if there is a license key associated with an email address. Unfortunately, I am a C# guy and do not understand all the PHP syntax. I copied the code you posted from another post in order to successfully generate a new license. Could you tell me how to ask LimeLM for information using pkey.find? See code excerpt below with comments:

***********Begin Code************...//try to pull license data$pull_data = array( 'method' => 'limelm.pkey.find', 'version_id' => $version_id, 'api_key' => $api_key, 'email' => $email);

//**********************//how do I ask LimeLM if there is license data here???//**********************

if (count($pull_data) > 0) //there's a license associated with this email!{$post_data = array( 'method' => 'limelm.pkey.setDetails', //just set the key details 'pkey_id' => $pull_data[0], //change the data for the first associated key 'api_key' => $api_key, 'email' => $email);}else //there's no license associated with this email{$post_data = array( 'method' => 'limelm.pkey.generate', //make a new license 'version_id' => $version_id, 'num_keys' => 1, 'num_acts' => $quantity, 'email' => $email, //here is the email account to associate with it 'api_key' => $api_key, 'nojsoncallback' => 1, 'format' => 'json', 'for_tfs' => $for_turbofloat //maybe use turbo float);}if ($feature_names !== null){ $post_data['feature_name'] = $feature_names; //set the feature names $post_data['feature_value'] = $feature_values; // set the feature values}...************End of Code***************

Thanks a Ton,Jason

Hey Jason,

The code to look at is the FastSrping-PHP-Code.txt in the web API pack. Specifically the curl_* calls are what sets up, and then makes the request to the LimeLM servers. Then, of course, you have to parse the response.

Please forgive my slowness. I have been working all day to implement what you suggested. I have the following code nearly working like I want. The only problem is that I cannot access the pkey so that I can pass it to the setDetails function later in the code. I've tracked down the problem to be the line with the "ERROR HERE" marking. I would like to get the first product key out of the result of the pkey.find method, but cannot figure out how to access it.

Example of what is returned from pkey.find:<rsp stat="ok"><pkeys total="1"><pkey id="999999" key="ABCD-ABCD-ABCD-ABCD-ABCD-ABCD-ABCD" acts="1" acts_used="0"/>

Thanks again for all your help!

Code Excerpt:...//try to pull license data$pull_data = array( 'method' => 'limelm.pkey.find', 'version_id' => $version_id, 'api_key' => $api_key, 'email' => $email);

$post_string = '';foreach ($pull_data as $key => $value){$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);

try{

$jObj = json_decode(curl_exec($request));

if ($jObj-> pkeys -> total !== '0') {

echo $thispkey = $jObj -> pkeys -> pkey[0] -> key; //*****ERROR HERE****** $accountexists = 'true'; } else { // Uncomment the next line to see the error LimeLM is giving you. //echo $jObj->message; }}catch (Exception $e){ // Uncomment the next line to see the exception. //echo 'pkey Failure: '.$e->getMessage();$accountexists = 'false';}...

Example of what is returned from pkey.find:<rsp stat="ok"><pkeys total="1"><pkey id="999999" key="ABCD-ABCD-ABCD-ABCD-ABCD-ABCD-ABCD" acts="1" acts_used="0"/>

Right, and the reason the response is in XML and not JSON is because you didn't tell LimeLM you wanted the response in JSON. Again, look at the fastspring example. Notice how the $post_data array variable also has these elements:

'nojsoncallback' => 1, 'format' => 'json'