WebAPI

Help - I'm playing with WebAPI and I don't seem to get any meaningful results. The result is:

LimeLM Testerr=&

Example of my test.php file:

<?phpinclude 'LimeLM.php';

echo '<p>LimeLM Test</p>';

// Valid api key and product ID$api_key = '10h------------------.--------'; // Hidden for public support post$pkey_id = '4W..-....-....-....-....-....-....'; // Hidden for public support post

////////// SetAPIKey$api_data['method'] = 'test';$api_data['api_key'] = $api_key;$result = LimeLM::SetAPIKey($api_data);echo $result;

////////// GetPKeyDetails$command_data['method'] = 'test';$command_data['api_key'] = $api_key; $command_data['pkey_id'] = $pkey_id;$command_data['format'] = 'rest';$result = new SimpleXMLElement(LimeLM::GetPKeyDetails($command_data));

$result_string = '';foreach ($result as $key => $value){ if (is_array($value)) { foreach ($value as $sub_value) { $result_string .= $key.'[]='.urlencode($sub_value).'&'; } } else { $result_string .= $key.'='.urlencode($value).'&'; }}echo $result_string;

LimeLM::CleanUp();?>

There are a number of things wrong with this code. Most of the LimeLM API functions take scalar information, not arrays. For instance, you're doing this:

$api_data['method'] = 'test';$api_data['api_key'] = $api_key;$result = LimeLM::SetAPIKey($api_data);

Which is passing an array of data when it should just be string:

$result = LimeLM::SetAPIKey($api_key);

Ditto for GetPKeyDetails. Again you're passing an array of garbage when you should be looking at the function definition in LimeLM.php to see what's needed:

public static function GetPKeyDetails($pkey_id)

This means, just pass in the pkey_id to the GetPKeyDetails() function:

$result = new SimpleXMLElement(LimeLM::GetPKeyDetails('123456'));

How do you turn the product key ''4W..-....-....-....-....-....-...." into a pkey_id? Well, again, there's a function for that. It's called GetPKeyID(). It takes a $version_id and a $pkey

GetPKeyID('100', '4W..-....-....-....-....-....-....');

Does that make sense?

Re Garbage in arrays, I was trying to derive what to do from your on-line docs. I will quote,

"All request formats, listed on the web API index page, take a list of named parameters.

The REQUIRED parameter method is used to specify the calling method.

The REQUIRED parameter api_key is used to specify your API Key.

The optional parameter format is used to specify a response format."

And this was the closest docs I could find for GetPKeyDetails()

https://wyday.com/limelm/help/api/limelm.pkey.getDetails/

So obviously I am not looking at the correct link for the docs. Could you send me the link for some decent docs that describe what you are explaining here so I don't write any more garbage.

I didn't mean that as an insult -- I was using it in the computer-talk sense: garbage-in, garbage-out. I.e. you're passing the wrong information, thus the wrong information is coming back (in this case, LimeLM is telling you something went wrong).

The LimeLM.php is a wrapper that handles the details of passing the correct information to LimeLM. So, in this case for documentation you'd use the web API docs as a guide, but use the LimeLM.php file for specific calling information. In other words, look at the function definitions.

We'll improve the documentation for these specific implementations.

Made changes and still don't seem to be getting any meaningful output to php calls. Not even errors. Here is my output:

LimeLM Test

SetAPIKey:

GetPKeyID:

Here is my script:

<?php

include 'LimeLM.php';

function printResult($result){ $result_string = ''; foreach ($result as $key => $value) { if (is_array($value)) { foreach ($value as $sub_value) { $result_string .= $key.'[]='.urlencode($sub_value).'&'; } } else { $result_string .= $key.'='.urlencode($value).'&'; } } echo $result_string;}

echo '<p><b>LimeLM Test</b></p><br>';

$api_key = '10he-----------------.--------';$product_key = '4W..-....-....-....-....-....-....';$version = '1.0';

////////// SetAPIKey$result = LimeLM::SetAPIKey($api_key);echo '<p>SetAPIKey: ' . $result . '</p>';

////////// GetPKeyID$pkey_id = LimeLM::GetPKeyID($version, $product_key);echo '<p>GetPKeyID: ' . $pkey_id . '</p>';

////////// GetPKeyDetails//$result = new SimpleXMLElement(LimeLM::GetPKeyDetails($pkey_id)); //echo 'GetPKeyDetails: ';//printResult($result);

LimeLM::CleanUp();//phpinfo();

?>

Every function, except SetAPIKey() which doesn't return anything, has to be parsed for the returned information. So one thing you're doing wrong is you're not parsing the result of LimeLM::GetPKeyID See: limelm.pkey.getID.

Here's an example of the type of response you'll get if it's a success:

<pkey id="103"/>

Another mistake is the $version. Again, see the limelm.pkey.getID. Specifically:

version_id (Required)

The id of the version of which the product key belongs. You can get the version ID by examining the URL in your browser. For instance, from the URL http://wyday.com/limelm/version/100/ you can see the version ID is 100. (Note: The Version ID is not the Version GUID).

ok, I found the version on the url when I clicked my version 1.0

https://wyday.com/limelm/version/10--/

so I changed my version to this value$version = '10--';

but even if I don't parse, I should get a return xml string from GetPKeyID() call:

$pkey_id = LimeLM::GetPKeyID($version, $product_key);echo '<p>GetPKeyID: ' . $pkey_id . '</p>';

And again, even with the correct version my output remains the same. Nothing seems to come back from GetPKeyID call.

LimeLM Test

SetAPIKey:

GetPKeyID:

and I can't even get something as simple as the echo to work correctly. My code looks like this:

////////// SetAPIKey$result = LimeLM::SetAPIKey($api_key);echo '<p>SetAPIKey: ' . $result . '</p>';

////////// TestEcho$result = LimeLM::TestEcho('Hello');echo '<p>TestEcho: ' . $result . '</p>';

and I get this error back and no result

Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/LimeLM.php on line 185TestEcho:

I feel something is fundamentally wrong with my environment but without much error feedback its hard for me to understand the problem.

LimeLM returns XML. You're trying to just pump that XML right into your HTML output. Do you know what happens when you do that? It becomes invisible (unless you click "view source" and then you can actually see the XML response from LimeLM).

ok, I see. I thought it would just show it as a string but the xml formatting would render it invisible. I'll parse out the values and go from there. thanks