As we all know, it’s a drag to refresh stats if it requires logging in, downloading a file and extracting subids. Fortunately I just discovered that CJ has had a web services API for a while now. Since I’ve been trying to use Prosper202 more recently, I wanted to see how easy it would be to pull CJ stats in. Fortunately, this turned out to be pretty simple.
Here are the steps:
1. Download nusoap. You can get it here. (You can of course use a different soap client if you prefer, but then the calls will be different.)
2. Get a CJ API developer key from here.
3. We’re going to be reusing a couple of php/curl classes originally written by Smaxor, then updated by Bandit. These are the 2 files here: curl.class.php and prosper202.class.php. You’ll need to remove the .txt extension from them.
4. Let’s say we’re going to put our subid update script in the $UPDATE_DIR. Then we want to move the nusoap files to $UPDATE_DIR/lib and the php/curl class files to $UPDATE_DIR/includes.
5. Finally, we can put the script that pulls all of these together into $UPDATE_DIR:
/*
* AUTHOR: pharmboy (http://www.interwebmonies.com)
* DATE: 2/16/09
* VERSION: 0.1
*
* This code downloads subids from Commission Junction, then uploads those subids into prosper202 as conversions.
*/
require_once('includes/curl.class.php');
require_once('lib/nusoap.php');
require_once('includes/prosper202.class.php');
//edit the next line with your p202 domain:
$p202 = new prosper202("http://www.yourp202domain.com");
$developerKey = "--your dev key--";
$soapclient = new nusoap_client("https://rtpubcommission.api.cj.com/wsdl/version2/realtimeCommissionServiceV2.wsdl", 'wsdl');
$params = array(
"developerKey" => $developerKey,
"websiteIds" => '',
"lookBackXHours" => '8',
"advertiserIds" => '',
"countries" => '',
"adIds" => '',
"includeDetails" => '',
"sortBy" => '',
"sortOrder" => 'asc');
$response = $soapclient->call('retrieveLatestTransactions', $params);
$count = $response['out']['count'];
$converted_subids = array();
for ($i = 0; $i < $count; $i++) {
$converted_subids[$i] = $response['out']['transactions']['RealTimeCommissionDataV2'][$i]['sid'];
}
$p202->p202_login(”yourprosperusername”, “yourprosperpassword”);
$p202->update_converted_subids($converted_subids);
What the code does is log in and find all of your transactions over the past 8 hours from all of your sites and uploads the sub ids. According to the API docs, 8 hours is the max look back time frame, so assuming you want your stats constantly updated, you’ll need to run this in a cron job. Enjoy.