PDA

View Full Version : What's wrong with the API??


emmfield
03-12-09, 15:34
I'm so annoyed with the Shopwindow/Productserve API. I've been working on it for 6 hours now and I'm completely stuck. I know this might be better off in the API section, but it's also a rant about the lack of documentation for beginners on getting a basic install up and running. All I've found is this (http://wiki.affiliatewindow.com/index.php/ProductServe_API_v3) and I don't get it.

I've followed this guide (http://www.awinapi.com/2009/06/29/the-first-example-get-list-of-merchants/). And my code looks like this:

<?php

$pageContents = <<< EOPAGE
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html lang="en" xml:lang="en">
<head>
<title>
AWin Test Page
</title>
<body>
<h1>Test Products</h1>
EOPAGE;
echo $pageContents;

echo "Hello World!";

define('API', 'PS');
require_once('constants.inc.php');
require_once('classes/class.ClientFactory.php');
$oClient = ClientFactory::getClient(API_USERNAME, API_PASSWORD, API_USER_TYPE);

$listmerchants = array('iCategoryId'=> 97, 'iMaxResult' => 10);
$oResponse = $oClient->call('getMerchantList', $listmerchants);
foreach($oResponse->oMerchant as $details){
$name = $details->sName;
$strapline = $details->sStrapline;
$description = $details->sDescription;
$logo = $details->sLogoUrl;
$showurl = $details->sDisplayUrl;
$deeplink = $details->sClickThroughUrl;
$id = $details->iId;

if ($logo<>'') {
echo "<a href=".$deeplink." title='".$name."'><img src=".$logo.
" style='float:left; margin:5px;' alt='".$name.
" :: ".$strapline." :: ".$description." :: ".$showurl.
"' width=\"88\" height=\"31\" border=\"0\"></a>";
}

}


?>

All I'm getting is:

Test Products
Hello World!
Warning: Invalid argument supplied for foreach() in (big long path...)/index.php on line 27

I'm good with HTML and CSS. I don't know any PHP. All I want to do is get it working then I should be able to tweak around myself. All the API files have been uploaded, and I've input my ID, API password and API key.

Please help!

GeorgeGaz
03-12-09, 15:44
Hello Emmfield,

I am sorry to hear that you are having trouble but is there any particular reason that you are using the API as opposed to the Client Software?

The Client Software is an out of the box solution aimed at web editors who have good knowledge in CSS and HTML and seems like it would be suited to your skills.

Regards

emmfield
03-12-09, 16:03
I already have the main site set up, and a page for each product. All I want to put on each product page is a price comparison table, and a description of what is included with the cheapest offer (free delivery? free gifts?) etc.

I thought Shopwindow client would be a full blown interface like on shopwindow.com ?

Do you have the link to my site there?

Thanks for the quick response too, really appreciate it.

GeorgeGaz
03-12-09, 16:19
Hello emmfield,

The Client Software is essentially a full shop "out of the box". See the default install here (http://default.shopwindow.com).

Customisation to the level that you want it (i.e. price comparison) would mean having to use the API because that is a heavily modded version if it is planned as I envisage it.

Regards

emmfield
03-12-09, 16:23
Yeah, that's what I've read - and that was my decision for using the API.

So how can I fix the problem I'm getting with my current code?

emmfield
04-12-09, 17:19
Well, anything? I really need to get this sorted.

If the arguments of the foreach on line 27 are the merchant list/product details and I'm getting argument invalid then surely there's an issue retrieving the list of merchants/products?

Andy
05-12-09, 13:17
It's your syntax. Forget about using EO and go for standard encapse syntax instead.

Try this:


<?php

$pageContents = '<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html lang="en" xml:lang="en">
<head>
<title>
AWin Test Page
</title>
<body>
<h1>Test Products</h1>';

$pageContents .= 'Hello World!';

define('API', 'PS');
require_once('constants.inc.php');
require_once('classes/class.ClientFactory.php');
$oClient = ClientFactory::getClient(API_USERNAME, API_PASSWORD, API_USER_TYPE);

$listmerchants = array('iCategoryId'=> 97, 'iMaxResult' => 10);
$oResponse = $oClient->call('getMerchantList', $listmerchants);
if(count((array)$oResponse) > '0'){
foreach($oResponse->oMerchant as $details){
$name = $details->sName;
$strapline = $details->sStrapline;
$description = $details->sDescription;
$logo = $details->sLogoUrl;
$showurl = $details->sDisplayUrl;
$deeplink = $details->sClickThroughUrl;
$id = $details->iId;

if (strlen($logo)>'0') {
$pageContents .= '<a href="'.$deeplink.'" title="'.$name.'"><img src='.$logo.' style="float:left; margin:5px;" alt="'.$name.' :: '.$strapline.' :: '.$description.' :: '.$showurl.'" width="88" height="31" border="0"></a>';
}

}
}

echo $pageContents;
?>


Is that what you wanted to happen?
Notice Ive encapsed echoed strings with a single quote instead of double? That's so I dont have to escape any double quotes in the html. You then highlight the variables with '.$variable.'. That gives a (slightly) faster output, as php knows instinctively that it's a variable, instead of having to check first.

Notice also that I've built up the contents of $pageContent and echoed it once at the end. To assign content to a variable, you use = and to append content to an already assigned variable, you use .=

It's always better to have only 1 output.

Ive wrapped the foreach in a check to ensure there is something in $oResponse to loop through. If you get no output, then it's likely that you are not joined with any merchants who serve category 97. Try a different category instead.

Hope this helps

Andy

emmfield
11-12-09, 15:17
That's excellent Andy, many thanks, it's just what I needed. Now I know there's a php expert on the forums I may be back in future for more :)