Eric Nagel

Eric Nagel

CTO, PHP Programmer, Affiliate Marketer & IT Consultant

Commission Junction Web Services

I have been, or can be if you click on a link and make a purchase, compensated via a cash payment, gift, or something else of value for writing this post. Regardless, I only recommend products or services I use personally and believe will be good for my readers.

Next in my series of affiliate network API programming examples, I’ve decided to tackle Commission Junction. The goal was to get a list of my stats from yesterday for one website, and store them in my custom tracking script.

Commission JunctionCJ has two choices when it comes to how to interface with them: REST and SOAP. Since I already had some SOAP code laying around, I decided to go that route (using the Daily Publisher Commission Service) . However, after I had my script done (took about 20 minutes), I realized CJ was only giving back half of my sales! From their website, I saw 6 sales for this one website:

  • 971450243
  • 971361785
  • 971179939
  • 971144045
  • 971097290
  • 971086202

Yet the SOAP API only returned 3 of them:

  • 971086202
  • 971144045
  • 971450243

So I emailed CJ about this (have yet to hear back from them) but being the impatient person that I am, I checked out the REST API. To my surprise, there is no equivalent to their SOAP Daily Publisher Commission Service – the closest I saw was their Commission Detail Service (REST). However, this service doesn’t take in any date parameters – your choice is yesterday or nothing. For this project, that’s OK as that’s what I want.

So the first thing to do is build the query. Starting with the base URL, add on the parameters you’d like. In my case, it’s the date-type and website-ids.

$cURL = 'https://commission-detail.api.cj.com/v3/commissions?';
$cURL .= 'date-type=event&';
$cURL .= 'website-ids=' . $nWebSiteID;

Then, using curl, grab the results:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $cURL);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			  'Authorization: ' . $cDevKey,
			  'User-Agent: "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 GTB6 (.NET CLR 3.5.30729)"'
			));

curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);

$cHTML = curl_exec($ch);
if (curl_error($ch)) {
	echo "Curl error: " . curl_error($ch);
} // ends if (curl_error($ch))
else {
	$cXML = simplexml_load_string($cHTML);
	// var_dump($cXML);

	for ($i = 0; $i < count($cXML->commissions->commission); $i++) {
		addCJCommission($cXML->commissions->commission[$i]);
	} // ends for ($i = 0; $i < count($cXML->commissions->commission); $i++)
} // ends else from if (curl_error($ch))

What I have in the loop is a function, addCJCommission(), which takes the commission object as a parameter. This function will add the commission to my database. I’m not going to get into details about that (as it’s specific to my project, and not what you’re doing) but one thing I found out is that objects with a dash in the property name require some special coding. For example, getting the date from the event-date property:

Don’t do this:

$dDate = date("Y-m-d", strtotime($oCJCommission->event-date));

Do this:

$dDate = date("Y-m-d", strtotime($oCJCommission->{'event-date'}));

To get started with Commission Junction Web Services, visit http://help.cj.com/en/web_services/web_services.htm. Thanks to forums.digitalpoint.com for the discussion on setting the Authorization header with curl.

Comments
  • Scott Jangro
    Posted December 16, 2009 3:05 pm 0Likes

    Good stuff Eric. I’ve been meaning to write this blog post for months now. I’m glad to see that there’s a second person in the world who has looked at their API. 😉

    If my memory serves, they’re moving toward REST and away from SOAP. I’ll see if I can check in with someone there on their plans to support each.

  • Jason
    Posted March 30, 2010 5:04 pm 0Likes

    Hey Eric,

    I would be interested to see if changing the “countries” parameter in the soap call to “all” fixed it for you. It seemed to fix it for me. I had the exact same issue, basically I was only getting back 1 result when I should have been getting back 3. I changed it from “US” to “all” and it returned all 3 results for me.

    Let me know your results if you would not mind.

    Cheers,

    Jason

  • Eric Nagel
    Posted March 30, 2010 5:31 pm 0Likes

    Hi Jason – interesting idea… and it worked! Nice find!

    However, after I wrote this, Alex from CJ reached out to me and told me to use the REST method. “Some consideration has been put into an eventual migration off SOAP.” Which is fine with me – I like REST better.

    Thanks for the tip!

  • Jason
    Posted March 30, 2010 5:50 pm 0Likes

    So, it should be noted that I basically removed all I could from the filtering:

    $results = $client->findPublisherCommissions(array(
    ‘developerKey’ => $developerKey,
    ‘date’ => $date,
    ‘dateType’ => ‘posting’,
    ‘countries’ => ‘all’,
    ));

  • Jason
    Posted March 30, 2010 5:55 pm 0Likes

    Until they can give us the date parameter in the REST request, I cannot move off of SOAP. I don’t have a preference for one over the other; except I prefer the stability of curl over the PHP soap client and I like the “ease of use” of the PHP soap client over curl (not that curl is THAT hard — I am specifically talking of having curl talk SOAP; otherwise curl is cake). There is also the HTTPRequest PHP object which I have not played much with: http://usphp.com/manual/en/http.httprequest.php

    Just my 2 cents.

  • Trackback: Tracking CJ Commissions with Prosper202 | Eric Nagel
  • Alwin
    Posted September 28, 2010 6:17 am 0Likes

    Hi,
    I am also working with an affiliate site and has used the SOAP. But it is not returning any data. So I googled and find this blog. Please note that I only had the Clicks inormation. So I have given the action-type as ‘click’. But it is not returnung any data for both the APIs. Do we need to have commission amount to use services..? then does anyone know is there any Sandbox avialable..? or selse how can I test the working without making purchases..?

    • Eric Nagel
      Posted September 28, 2010 6:31 am 0Likes

      Alwin,

      Find a merchant who pays a $0 commission (for a free trial download, for example) and then you’ll be able to see the commission in your account, without actually paying for anything.

      However, looking through the available services, I don’t see anything for just clicks.

  • Alwin
    Posted September 30, 2010 9:02 am 0Likes

    Thanks Eric…

    Actually I have checked it . But all of them needs one or other kinds of payments or call. But as I am outside USA it is not valid for me. I have checked with some in the site. it is also not seems to b working. So it will be a great help if you can send me one sample response of ‘Daily Publisher Commission Service(SOAP)’. I am using it because we can specify the dates there. As you have used it before , you may the sample report. I don’t need any valuable data. Just the response so I can work on the code for entering the data into database. Please help.

  • Sol Orwell
    Posted July 27, 2011 12:19 pm 0Likes

    FYI they now include date ranges – up to 31 days.

    Thanks for the code, it made life a lot easier for me.

  • Eric
    Posted June 1, 2012 9:02 pm 0Likes

    I’ve been tinkering with CJ’s web services Rest API, and it’s working great for Commission Detail reporting.

    However, I’m unable to find a way to query their Performance reports via API — for example, daily clicks per AID.

    Anybody know if this is possible?

    I’ve tried ‘action-types=click’ in the Commission Detail API for a date range which has definitely received clicks, yet the response from the server is

    We’re not using impression-based links (we use text links instead), which may be why? I just emailed CJ asking about this so will reply here if I hear back from them.

    Cheers,
    -Eric

  • Zeshan Ashraf
    Posted October 1, 2012 8:28 am 0Likes

    Hi,
    Awesome work dude
    did some changes and it is working great
    Great Work 🙂
    Thanks

Leave A Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.