Getting 100-Invalid API Key (Key not found)

private $api_key; private $request;

public function SetAPIKey($api_key) { $this->$api_key = $api_key;

//NOTE: If you're using the self-hosted version of LimeLM (that is, // LimeLM running on your own servers), then replace the URL with your own.

// Almost all users should leave this line unchanged. $this->$request = curl_init('https://wyday.com/limelm/api/rest/'); }

public function CleanUp() { // close curl object curl_close($this->$request); }

public function AddFeature($version_id, $name, $required, $type = null) { $post_data = array( 'method' => 'limelm.feature.add', 'version_id' => $version_id, 'name' => $name, 'required' => $required ? 'true' : 'false' );

if ($type) $post_data['type'] = $type;

return $this->PostRequest($post_data); }

public function DeleteFeature($feature_id) { $post_data = array( 'method' => 'limelm.feature.delete', 'feature_id' => $feature_id );

return $this->PostRequest($post_data); }

public function EditFeature($feature_id, $name = null, $required = null) { $post_data = array( 'method' => 'limelm.feature.edit', 'feature_id' => $feature_id );

if ($name) $post_data['name'] = $name;

if ($required !== null) $post_data['required'] = $required ? 'true' : 'false';

return $this->PostRequest($post_data); }

public function FindPKey($version_id, $email) { $post_data = array( 'method' => 'limelm.pkey.find', 'version_id' => $version_id, 'email' => $email );

return $this->PostRequest($post_data); }

public function GeneratePKeys($version_id, $num_keys = 1, $num_acts = 1, $email = null, $feature_names = null, $feature_values = null) { $post_data = array( 'method' => 'limelm.pkey.generate', 'version_id' => $version_id, 'num_keys' => $num_keys, 'num_acts' => $num_acts );

if ($email) $post_data['email'] = $email;

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

return $this->PostRequest($post_data); }

public function GetPKeyDetails($pkey_id) { $post_data = array( 'method' => 'limelm.pkey.getDetails', 'pkey_id' => $pkey_id );

return $this->PostRequest($post_data); }

public function GetPKeyID($version_id, $pkey) { $post_data = array( 'method' => 'limelm.pkey.getID', 'version_id' => $version_id, 'pkey' => $pkey );

return $this->PostRequest($post_data); }

public function ManualActivation($xml_act_request) { $post_data = array( 'method' => 'limelm.pkey.manualActivation', 'act_req_xml' => $xml_act_request );

return $this->PostRequest($post_data); }

public function SetPKeyDetails($pkey_id, $num_acts = null, $email = null, $feature_names = null, $feature_values = null) { $post_data = array( 'method' => 'limelm.pkey.setDetails', 'pkey_id' => $pkey_id );

if ($num_acts !== null) $post_data['num_acts'] = $num_acts;

if ($email !== null) $post_data['email'] = $email;

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

return $this->PostRequest($post_data); }

public function GenerateTrialExtension($version_id, $is_online, $length, $expires, $customer_id = null, $max_uses = null) { $post_data = array( 'method' => 'limelm.trialExtension.generate', 'version_id' => $version_id, 'is_online' => $is_online ? 'true' : 'false', 'length' => $length, 'expires' => $expires );

if ($is_online) $post_data['max_uses'] = $max_uses;

if ($customer_id !== null) $post_data['customer_id'] = $customer_id;

return $this->PostRequest($post_data); }

public function TestEcho($params) { $params['method'] = 'limelm.test.echo'; return $this->PostRequest($params); }

private function PostRequest($post_data) { if (!$this->$api_key) throw new Exception('You must specify your LimeLM API key and set it using SetAPIKey().');

$post_data['api_key'] = $this->$api_key;

// This section takes the input fields and converts them to the proper format // for an http post. For example: "method=limelm.pkey.find&version_id=100" $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, '& ');

curl_setopt($this->$request, CURLOPT_HEADER, 0); // eliminate header info from response curl_setopt($this->$request, CURLOPT_ENCODING, ""); // support gzip & deflate responses if available curl_setopt($this->$request, CURLOPT_RETURNTRANSFER, 1); // Returns response data instead of TRUE(1) curl_setopt($this->$request, CURLOPT_POSTFIELDS, $post_string); // use HTTP POST to send form data curl_setopt($this->$request, CURLOPT_SSL_VERIFYPEER, FALSE); // uncomment this line if you get no gateway response.

return curl_exec($this->$request); // execute curl post and store results in $post_response } public function ProdKeys($quantity, $email){ //Note: we put LimeLM in this directory. Change it as needed.

$LimeLM_ApiKey = 'xxxxx';

// the version id is found in the url.// For example http://wyday.com/limelm/version/100/ the version id is '100'. $LimeLM_VersionID = 'xxxxxx';// global $LimeLM_VersionID, $LimeLM_ApiKey;

//$errors = false;

// set your API key $this->SetAPIKey($LimeLM_ApiKey);

//try //{ // Generate the product key - set the number of activations using the quantity $xml = new SimpleXMLElement($this->GeneratePKeys($LimeLM_VersionID, 1, $quantity, $email)); if ($xml['stat'] == 'ok') { foreach ($xml->pkeys->pkey as $pkey) { // add a newline if you're generating more than one key if ($product_keys) $product_keys .= "\r\n";

// set the product key $product_keys .= $pkey['key']."\r\n"; } } else //failure { // use the error code & message $product_keys = $xml->err['code']."-".$xml->err['msg'];//debug_log('Failed to generate product keys: ('.$xml->err['code'].') '.$xml->err['msg'],false); } //} //catch (Exception $e) //{ // debug_log('Failed to generate product keys, caught exception: '.$e->getMessage(),false); //}

return $product_keys; $this->CleanUp();}

$pk = $this->ProdKeys($product['quantity'].$order_info['email']);

i am using this code in opencart order page. when my order confrm it sends email with opencart mail code. but it sends 100 error

We can't debug your code for you. Tell me exactly what line is failing. My guess, you're passing a "product key" (pkey) in a place that calls for a "product key id" (pkey_id).

But, like I said, narrow the example down to something small and tell me exactly what is failing.

public function SendPKeys($quantity, $email){ $LimeLM_VersionID = 'xxxxxxx'; $LimeLM_ApiKey = 'xxxxxxxxxxxxxxx';

$errors = false;

// set your API key $this->SetAPIKey($LimeLM_ApiKey);

// Generate the product key - set the number of activations using the quantity $xml = new SimpleXMLElement($this->GeneratePKeys($LimeLM_VersionID, 1, $quantity, $email)); if ($xml['stat'] == 'ok') { foreach ($xml->pkeys->pkey as $pkey) { // add a newline if you're generating more than one key if ($product_keys) $product_keys .= "\r\n";

// set the product key $product_keys .= $pkey['key']."\r\n"; } } else //failure { // use the error code & message $product_keys = $xml->err['code'].'-'.$xml->err['msg']; } return $product_keys; $this->CleanUp();}

if condition is not running the program is run in else condtion and the product_keys returns my else conditions error message.

the error message is 100 - invalid api key

if ($xml['stat'] == 'ok'){is not ok my code is going in else condition

That's because you're not passing the API key to LimeLM. You're creating a lot of problem for yourself by copying & pasting the contents of the LimeLM.php into your code, without first understanding. So, don't do that. Just include LimeLM.php with your other files and use require('LimeLM.php');

Then, set the API key like many of the examples show:

require('LimeLM.php');


//TODO: set your API key found in http://wyday.com/limelm/settings/LimeLM::SetAPIKey('PASTE THE API KEY HERE');


// now you can actually make the calls you want to make:$xml = new SimpleXMLElement($this->GeneratePKeys($LimeLM_VersionID, 1, $quantity, $email));


/// etc.

i use all functions of LimeLM.php in above code all functions are in same page. u can check in my first post

i am using this $this->$request = curl_init('https://wyday.com/limelm/api/rest/'); in SetAPIKey function this url is right or wrong ?

i use all functions of LimeLM.php in above code all functions are in same page. u can check in my first post

No they're not. I did check it. Trust me.

i am using this $this->$request = curl_init('https://wyday.com/limelm/api/rest/'); in SetAPIKey function this url is right or wrong ?

Honestly, just use our LimeLM.php file. You're creating a bunch of problems for yourself because you're just copying & pasting code without understanding it.

The reason you're getting the "Invalid API Key" error is because you're not passing the API key. If you can't see how you're not passing the API key, then just use our LimeLM.php file.

thanku so much for your help. my problem is solved. i am getting error becoz my client gave me wrong version ID and wrong api key. thanks for ur help.