ClickBank Blog ClickBank Blog Home ClickBank Blog Home Follow us on Twitter Become a ClickBank fan on Facebook ClickBank How To Videos on Youtube Subscribe via Email ClickBank flickr photo galleries

Programmatically Accessing Data from ClickBank.com

Posted by: Greg Lems, VP of Information Technology

Please note: This post is intended for readers with knowledge of web programming.

Some Clickbank clients have expressed the desire to retrieve transaction information from their accounts programmatically. In the future, we expect to implement a web-based solution for programmatic access to client data.

For now, clients who wish to programmatically access their Clickbank account data can do so using a special link on the Clickbank site that creates a CSV file with one day’s worth of transactions from an account. A sample of PHP code which accesses this data is shown below. However, any language which provides http access and session management can be used to access Clickbank account data.

To access Clickbank transaction data, a program must perform two operations:

1)      Authenticate by performing an HTTPS POST to https://nickname.accounts.clickbank.com/account/login (note: no trailing slash) and passing authentication information (see example below for specifics).

2)      Call the CSV download URL for the desired date. The format of the request is:

https://nickname.accounts.clickbank.com/account/dailyTxnCsv.htm?dt=YYYY-MM-DD

Below is an example of PHP code which authenticates, calls the CSV, then parses the data and prints it out. Make sure to replace ACCOUNT_NICKNAME and ACCOUNT_PASSWORD with your appropriate credentials, and select the date you want (in this example we use 2008-11-06).

<?php

# Get transactions for 2008-11-06

#

$account_nickname = ‘<ACCOUNT NICKNAME>’;

$baseurl = “https:// <https:/> ” . $account_nickname . “.accounts.clickbank.com”;

$login_args = array(

‘j_username’ => $account_nickname,

‘j_password’ => ‘ACCOUNT_PASSWORD’

);

$curl = curl_init();

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_HEADER, 1);

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($curl, CURLOPT_COOKIEJAR, ‘cookie.txt’);

curl_setopt($curl, CURLOPT_URL,

$baseurl.’/account/login’);

curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($login_args));

$login = curl_exec($curl);

curl_setopt($curl, CURLOPT_HEADER, 0);

curl_setopt($curl, CURLOPT_URL,

$baseurl.’/account/dailyTxnCsv.htm?dt=2008-11-06?);

$csvfile = curl_exec($curl);

curl_close ($curl);

$lines = explode(”\n”, $csvfile);

foreach ($lines as $line) {

if (strlen($line) > 0) {

list($date,$time,$receipt,$tid,$pmt,$txntype,$item,$amount,$publisher,

$affiliate,$countrycode,$state,$lastname,$firstname,$email) = explode(”,”, $line);

printf(”%-20s %s\n”,”Date:”, $date);

printf(”%-20s %s\n”,”Time:”, $time);

printf(”%-20s %s\n”,”Receipt”, $receipt);

printf(”%-20s %s\n”,”Tracking ID:”, $tid);

printf(”%-20s %s\n”,”Payment Type:”, $pmt);

printf(”%-20s %s\n”,”Transaction Type:”, $txntype);

printf(”%-20s %s\n”,”Item:”, $item);

printf(”%-20s %s\n”,”Amount:”, $amount);

printf(”%-20s %s\n”,”Publisher:”, $publisher);

printf(”%-20s %s\n”,”Affiliate:”, $affiliate);

printf(”%-20s %s\n”,”Country Code:”, $countrycode);

printf(”%-20s %s\n”,”State:”, $state);

printf(”%-20s %s\n”,”Lastname:”, $lastname);

printf(”%-20s %s\n”,”Firstname:”, $firstname);

printf(”%-20s %s\n”,”Email:”, $email);

echo “—————\n”;

}

}

?>

Fields returned for each line in the CSV file:

Column: Example:
Date 2007-01-29
Time 07:23
Receipt 7BXK1N4J
TID ADSENSE1
Pmt VISA
Txn Type Sale
Item 1 (note, this field may also contain alpha characters)
Amount $120.18 (note, negative amounts appear as $-120.18)
Publisher PUBNAME
Affiliate AFFNAME
CC US
St. WA
Last Name THOMPSON
First Name JERRY
Email JERRY@YAHOO.COM

By using this type of script, you should be able to get all the information you need about ClickBank transactions in your account. Let me know if you have any questions or concerns by leaving a comment.

Take a look at these related posts:

  1. The Power of Data
  2. Help Us Help You
  3. ClickBank Data and Outside Analytics

5 Responses to “Programmatically Accessing Data from ClickBank.com”

  • Michael says:

    Thank you for this.

    Extremely useful and very powerful…

    I’ll be putting it to use right away!

    Michael

    P.S. I’m planning on making a blog post about this great news. Keep up the awesome work CB!

  • Yuliadon says:

    i am glad can joint to clickbank

  • Shafir Ahmad says:

    Awesome. This feature is finally available on clickbank. Thanks

  • It’s interesting that CB publishes all of these great sources for automation and integration with clickbank, yet hardly any uses them.

    It’s definitely something I use everyday to automate my business and I’m glad that clickbank looks out for the technical affiliate marketers by making this information easily available.

  • dipesh sharma says:

    I tried the script,but i am just getting the code source printed in the output,without any results.I am running it on PHP wamp server.

    Please let me know how to configure the script.

    Regards
    Dipesh

Leave a Reply

Please do not enter a keyword phrase, product, or service name as your name in the comment section, or your comment may be deleted as spam.

Anti-Spam Question:

Upcoming Events
Archives
Recent Comments
  • Darren: Basically, this will help because there are a lot of review website portals i have come across that are just...
  • Bigmodo: Thank you clickbank for your kind gestures. I love you.
  • David Wilcoxson: As an Affiliate Marketer that lives in Aurora CO, thank you for continuing to support us despite the...
  • Brie: You explained these 7 steps so nicely, thank you for these tips. THe Email list and newsletter increase your...
  • Derek Williams: Hi, I have read your Newsletter Strategy and I am impressed, but I have to say, I am a newbie and not...