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.

About

Beau is the Client Knowledge Guru for ClickBank and covers the latest trends, tips and techniques for building profitable Internet marketing businesses.

Take a look at these related posts:

  1. The Power of Data
  2. Operate in Real Time with the ClickBank API
  3. Using ClickBank Instant Notification
  4. ClickBank Data and Outside Analytics
  5. ClickBank iPhone Apps

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

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. If you need customer service help with a ClickBank order, please click here.

Recent Comments
  • Abelate Pears: Pat just gives away useful practical pieces if advice and tips, that help a great number of interested...
  • Shamelle@BetterBloggingWays: I really like Pat’s authenticity and transparency, the way he writes and speaks...
  • Brendan: I’ve been reading & listening to Pat for a couple of years now. He always gives really practical...
  • Mike: Hi Miles Very cool article – I did not know about the VTIDs which is something I will have to integrate...
  • Adrian Tudini: Hi Great Article!!!!