There was a comment a couple of days ago about CJ WebService Version 2. I did get this to work. I found some good code another programmer put together that access the v2 WSDL. Basically, this is my API test script, so you need to manually add your keywords and advertiser ID in the code, but it's a proof of concept. I think I've abandoned the CJ API. I personally think it's not that consistent. I often get 'internal server error' in the response XML. I think it might be a riskier move to go version 2 for real time calls.. just my two cents.
This version needs PHP5 with SOAP services built into PHP (--enable-soap). Also it's using try/catch for handling SOAP exception and it's only available in PHP5.
As I mentioned above, I'm pretty much ditching CJ web services all together. I still use eBay's API, but CJ's seems a little off for me. I'm doing initial tests with CJ Data Feeds now, and this really appears to be the direction I need to go.
<?php
try {
$ini = ini_set("soap.wsdl_cache_enabled","0");
$client = new SoapClient('productSearchServiceV2.wsdl', array('trace'=> true));
$results = $client->search(
$developerKey = 'yourlongdevkey',
$websiteId = '0000000',
$advertiserIds = '0000001',
$keywords = 'your keywords',
$serviceableArea = '',
$isbn = '',
$upc = '',
$manufacturerName = '',
$manufacturerSku = '',
$advertiserSku = '',
$lowPrice = '',
$highPrice = '50',
$lowSalePrice = '',
$highSalePrice = '',
$currency = '',
$sortBy = '',
$SortOrder = '',
$startAt = 0,
$maxResults = 100
);
// DEBUG
//echo "<pre>";
//var_dump($results);
//echo "</pre>";
//exit();
echo "<h3>Your search for '$keywords' generated $results->count results</h3>";
foreach ($results->products as $product) {
if(strlen(trim($product->imageUrl)) > 0){
$price = sprintf('%01.2f', $product->price);
echo "<br>".$product->advertiserId."<br>";
echo "<br>SKU:".$product->sku."<br>";
echo "<a href='$product->buyUrl'><img src ='$product->imageUrl' height='70' ><p>$product->name <br/> Offered by $product->advertiserName($product->advertiserId) at <b>$price ($product->currency)</b></p></a>";
}
}
} catch (Exception $e){
echo "<div id='error'><p>There was an error with your request or the service is unavailable.</p></div>";
print_r ($e);
}
?>You can download productSearchServiceV2.wsdl here.





I'm looking for a developer that has experience working with these APIs. We're looking to have a custom application built that merges into our system. Please let me know if you know of any developer interested.
Kindest regards,
Stephen
Hi, im using the code just like u mentioned. But instead, i got this error:
There was an error with your request or the service is unavailable.
SoapFault Object ( [message:protected] => Fault: java.lang.ClassCastException
........
........
.......
[faultstring] => Fault: java.lang.ClassCastException [faultcode] => soap:Server )
any idea what's going on? is it error in server side?
Hello
That error is definitely server side. That's the response from the web server. The error is possibly instantiated from your end. I think CJ doesn't do a good job with catching and explaining some of those errors.
My guess it's a value that you're passing 'cast' is when you have one data type (ie: string) and try to change it into a different data type (ie: number). That could possible be the error.. not sure.
You may want to post this error on the CJ Developer forum.. good people there. They should be able to get specific about this particular error. I'm not a big fan of the CJ API, seems to have glitch exceptions.. I go with the datafeed now.. works 100% of the time.
hanji
Warning: Invalid argument supplied for foreach() on line 15. I used your code exactly (of course with my account details). And I used the Porduct search wsdl from CJ.
Looks like the return value for the foreach was NOT an array. I would var_dump() the return from the web service. My example doesn't have error to catch that. It might be a string returning a error code or statement back from CJ.
hanji
Right now my hosting use php5,
I have already used your code above but get error :
Fatal error: Class 'SoapClient' not found in /home/airbase/public_html/trycj.php on line 4
What wrong with that?
Thanks for your help.
Hans
That's a bummer. It looks like your hosting provider does not have PHP5 built with SOAP. You can verify this by creating a test script to get phpinfo()...
<?phpphpinfo();
?>
You need to have --enable-soap listed in the Configure Command block at the top. You might be able to request this, but it would involve recompiling PHP on the server. Here is a link about PHP/SOAP:
http://us2.php.net/manual/en/ref.soap.php
How to build it in php4?
Can you tell me?
Hello
This is untested.. but should work. You can take some snippets of code from this tutorial:
http://www.money-code.com/node/23
It uses the nusoap class. You can google for more information on that class. You would need to remove the try/catch handling and use nusoap instead of using PHP5's built in SOAP object. You might have to tweak with nusoap a bit, but overall it should just 'work'.
Hope this helps.
hanji
Does this list products based on keywords? What exactly does it do?
Yes, this will return products from CJ based off of keywords AND advertisers.