Many affiliate marketers don’t know how easy the use of an API program is. I have been using the CJ API service for about two weeks and have noticed an increase in revenue because of it. Since I figured out how to put it to you in WordPress, I am going to share the code with you. First, you need to download and install the EXEC-PHP plugin for wordpress. It can be downloaded here: http://bluesome.net/post/2005/08/18/50/.
Next you will need a couple of bits of information from CJ. First, if you haven’t signed up for the CJ API service, you can sign up here: http://webservices.cj.com/. For the code to work, you will need you API number and the advertiser id. If you haven’t signed up for an advertiser that has a product catalog, now would be the time to do so.
Finally you will need to download the Nusoap library by clicking the link. Unzip it and ftp into your sites root directory.
Once you have an advertiser that has a product catalog, you need to click on the advertiser details and look at the url. In Firefox, you are not able to edit the url but rather only view it. The url will look like this: https://members.cj.com/member/1234567890/accounts/publisher/getadvertiserdetail.do?ispopup=true&advertiserId=123456.
I have highlighted the area by making the advertiser id bold and underlined. You will need to copy the number only and paste it into wordpad or some other text editor for now. You will also need to go to your account settings in CJ by clicking account. Click website settings and choose the site from the list of sites that you have entered that you will be making your post on. Once you get in here, copy the PID number and paste it in the same text editor file that you have saved the advertiser id on. Save the file for future reference.
Once you get your API number, you are ready to go.
Whenever you get the EXEC-PHP plugin installed into WordPress, you will now need to edit the header of your theme. You can do this by clicking Appearance –>Editor. On the right hand side of the screen, you will see header. Click it. At the bottom of the code, you will need to add this snippet of code:
<?php
/*CJ API FOR WORDPRESS
COPYRIGHT (C) 2009
SCOTT P DAUGHERTY
*/
include("nusoap/lib/nusoap.php");
?>
Save the header file with this code in it. Now you will be able to add the rest of the CJ API code on each individual post just as you would the twp-auction code for ebay. Now you are ready for your API id number and advertiser id. At the end of the post that you want the cj ads on, you will insert this code:
<?php
/*
CJ API SEARCH AND RETURN
PHPPIG
COPYRIGHT (C)2009
SCOTT P DAUGHERTY
*/
//Define user information
$developerkey ="Your API key here";
$websiteIdx ="Your website id here";
$cjword = "Your keyword here";
$advertiserIds = "Your advertiser id here";
$serviceableArea = "";
$upcOrIsbnOrEan = "";
$manufacturerName = "";
$advertiserSku = "";
$lowPrice = "";
$highPrice = "";
$currency = "";
$sortBy = "";
$orderIn = "";
$startAt = 0;
$maxResultsx = 15;
$soapclient = new nusoap_client("https://product.api.cj.com/wsdl/literal_wrapped/productSearchService.wsdl", true);
$params = array(
"developerKey" => $developerkey,
"websiteId" => $websiteIdx,
"advertiserIds" => $advertiserIds,
"keywords" => $cjword,
"serviceableArea" => "",
"upcOrIsbnOrEan" => "",
"manufacturerName" => "",
"advertiserSku" => "",
"lowPrice" => "",
"highPrice" => "",
"currency" => "",
"sortBy" => "",
"orderIn" => "",
"startAt" => $startAt,
"maxResults" => $maxResultsx
);
$proxy = $soapclient->getProxy();
$result = $proxy->search($params);
$count = $result['searchReturn']['count'];
if($count > 0) {
for($i = 0; $i < $count; $i++) {
$advertiser_id = $result['searchReturn']['products']['products'][$i]['advertiserId'];
$advertiser_name = $result['searchReturn']['products']['products'][$i]['advertiserName'];
$click_url = $result['searchReturn']['products']['products'][$i]['clickUrl'];
$currency = $result['searchReturn']['products']['products'][$i]['currency'];
$description = $result['searchReturn']['products']['products'][$i]['description'];
$image_url = $result['searchReturn']['products']['products'][$i]['imageUrl'];
$name = $result['searchReturn']['products']['products'][$i]['name'];
$price = $result['searchReturn']['products']['products'][$i]['price'];
$sku = $result['searchReturn']['products']['products'][$i]['sku'];
$upc = $result['searchReturn']['products']['products'][$i]['upc'];
echo "<table border='0'><tr><td><a href='$click_url' title='$name'><font size='3'>$name";
echo "</font></a><br><font size='2'><b>$ $price </font></b>";
echo "<br>SKU: $sku";
echo "<br><a href='$click_url'><img src='$image_url' title='$name'></a>";
echo "<br><font color='#000000'>$description</font>";
echo " <br></td></tr></table><hr size='1'>";
}}
?>
At the top of the code, you will see the following:
$developerkey ="Your API key here";
$websiteIdx ="Your website id here";
$cjword = "Your keyword here";
$advertiserIds = "Your advertiser id here";
Enter the information in on the appropriate lines and insert complete code into your post. It will return the results from the advertiser that you choose with your affiliate id. For an example, visit my site at http://scottpdaugherty.com to review the code in use.

Can I use on Joomla?
I am not sure if it will work with Joomla, however, tonight (2JAN10) around 11CST, I will have the code available for TheCollard Content Management System (cj version) which will allow you to enter in your api key, PID, and advertiser ID from CJ and will allow you to build a SEO shop without adding any products. You can visit The Collard to get the download. In the admin panel you will have settings where you put in your API key, PID, and advertiser ID. You can preview the front end of the script at Daddy’s Electronics. This is not the standard template, just a template that I downloaded to test the site out with.
There will be updates made periodically to make the script more efficient for everybody.
I will download Joomla within the next week and see if I can get it to work there as well.
Scott
I was just notified via email of a couple of issues with the code above and if you run into any errors….You may need to update your header code to show :
< ?php
/*CJ API FOR WORDPRESS
COPYRIGHT (C) 2009
SCOTT P DAUGHERTY
*/
include("nusoap/lib/nusoap.php");
?>
Also, you will need to find the line of code that looks like this:
$maxResultsx = amount of returns here;
and replace amount of returns here to show a number such as 10, 20, 100 or as many as you like.
Hi,
I am getting a fatal error at the following line
$result = $proxy->search($params);
Hi,
I am getting a fatal error at the following line
$result = $proxy->search($params);
Fatal error: Call to a member function search() on a non-object in path\to\filename.php
Nusoap library downloaded from the above location does not have the search function..
where can i get a working script..
thanks in advance…
Find this line in the code:
$maxResultsx = amount of returns here;and replace to
$maxResultsx = 10You can actually change that number to any amount that you like. Also, adjust the header to nusoap/lib/nusoap.php if that is the correct directory. Sorry about the error. I am updating the post to show that accurately.
This is pretty cool stuff. I recently developed out some CJ API integration with REST on a couple of my sites. Where you insert the code is up to the individual need, but I wrote about it over on my site at enkognedo.com. Same idea, though, and yes, you will need the ability to execute php. I used exec-php mentioned in this article for WP and the “sourcerer” plugin for my Joomla! install. There is an example of one of the API’s in use on my enkognedo.com site entitled “php programming”… check it out.
HI
The php code implementation does not work. Something is wrong with the above code, I tried with numberous wordpress themes and on my own server direct. Can you please let me know if the php code is somewhat off on the above code?
What error are you getting when you run the code?
Just tested the code again on the new version of WordPress and it doesn’t work for me either. I will get back in the next day or two with a solution. In the meantime, it worked on WordPress versions 2.8.x and 2.9.x.
It may be that you have to make a call through the REST protocol to make the connection. I will make a post on that as well this afternoon.
thanks, I love your posts and site. You are the first presenting these php feed integration for cj within wordpress. The version of wordpress is 3.01 and yes rest protocol version will also be greet.