Getting Commission Junction’s API to work

Getting Commission Junction’s API to work

I have seen a few posts on various affiliate forums that attempt to help in getting the Commission Junction (CJ) API working. The API allows one to access the data feed from an advertiser on CJ, for use on their own website. There are many things that you can do once you have that data but the tricky part is getting the API to work in the first place.

Whilst the CJ API documentation is thorough it doesn’t provide any examples for developers to use. The following PHP example for version 2 of their API will get you up and running in no time at all.

<?php

$api_key = ‘YOUR-REALLY-LONG-API-KEY-NUMBER’;
$website_id = ‘YOUR-WEBSITE-ID-NUMBER’;
$advertiser_ids = ‘joined’; // Specify which advertisers products you want, here I use the shortcode joined for only those programs that I have actually joined
$keywords = ‘stapler’; // Keyword search – find all products that have the word stapler in their title

$url = ‘https://product-search.api.cj.com/v2/product-search?website-id=’ . $website_id . ‘&advertiser-ids=’ . $advertiser_ids . ‘&keywords=”‘ . $keywords . ‘”‘;

// For testing, to make sure the $url is correct
// echo $url;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Authorization: ‘ . $api_key));

$curl_results = curl_exec($ch);

curl_close($ch);

// For testing, to make sure XML data is sent back (when echo’ing, to the browser. you would normally then use SimpleXML to process further before displaying)
// echo $curl_results;

?>

Oliver Partridge

Building websites since 2000, I have a wealth of experience in eMarketing, SEO, e-mail marketing and social media marketing. Google+ and Twitter

Leave a Reply


  • Logo Concept: Perfect Shirts

    Portfolio Website Design & Development

    This is a logo concept for a planned affiliate marketing website called Perfect Shirts Related posts: Website Build: Perfect-Shirts.co.uk Last year I blogged about a

  • Make CMSMS Cookie compliantMake CMSMS Cookie compliant

    Make CMSMS Cookie compliant

    Uncategorized

    This post will document the steps required to make CMS Made Simple compliant with the new EU Privacy Directive cookie laws. If you haven’t yet

  • Get on page one in Google in two weeks

    Website Design & Development

    How to achieve a page one position on a Google search in less than two weeks, these steps require the following: Your website domain name