Problem with Generating Keys via Web API

I am trying to generate Keys using Web API and the code below and I am having hard time. No errors received and keys are not generated. Can someone please check my code and let me know if I am missing/doing something wrong? Here is the code:

require('LimeLM.php');LimeLM::SetAPIKey('xxxxxxxxxxxxxxxxxxx');$version_id = 'xxxx'; $to="johndoe@yahoo.com";$featNames = array('SalesOrder');$featValues = array($_POST["SalesOrder"]);

$xml = new SimpleXMLElement(LimeLM::GeneratePKeys($version_id, 1, 1, $to, $featNames, $featValues));

if ($xml['stat'] == 'ok'){ echo "success"; }else { if ($xml2->err['code'] == '1'){ echo "failed"; } else{ } }

LimeLM::CleanUp();

Your if statement won't show all errors. It will only show an error in the case of error code "1" (which is not an error that limelm.pkey.generate will return. See: https://wyday.com/limelm/help/api/limelm.pkey.generate/

So really you'll never show any error. Which is bad. A better if-statement would be:

if ($xml['stat'] == 'ok'){ echo "success";}else{ echo "error ".$xml->err['code'].': '.$xml->err['msg'];}

Which will print out exactly what the error is, and what the message for the error is.

Thank you Sam. That did show me what the problem was.... not posting "required fields".

🙂