Home PHP JavaScript CSS WordPress APIs .htaccess Other How-To Useful Scripts What I Recommend
Posted on by Aleksandar Gichevski ()
ClickBank is known as powerful online marketplace for digital information products. It is widely used like payment processor by owners because it gives a way to offer high commission rates to your JV partners and affiliates which leads to more exposure and purchases on your products.

Few weeks ago I needed to extract and analyze some data from ClickBank from our company accounts which lead me to ClickBank API service built in REST architecture giving secure access to your ClickBank account information.

What can be done with ClickBank API

ClickBank API offers variety of functions that can be used to manipulate with your account. Some of them are:
  • Request a refund for a customer's purchase
  • Request a cancellation for a customer's subscription
  • Retrieve a list of transactions in a ClickBank account for a given time-frame
Mainly there are 3 applications in ClickBank that can be accessed by API and be used:
  • ClickBank Data Dashboard
  • Subscription Management Tool
  • Analytics Package

Integrating ClickBank API in PHP

So now let's see how you can integrate ClickBank API in PHP and create a code that will work with your account. I will divide in sections all main important stuff that you must implement to be sure your request will be valid and authenticate.


As every secure script and ClickBank API requires authorization and their server will return 403 [Forbidden] status code on every request that is sent without the right credentials. ClickBank Authorization is based on Authorization header parameter that contains the following keys: - Developer key - The Developer key grants the user the "ROLE_HAS_DEVELOPER_KEY" role. This is a token that is used to allow access to API's. - Clerk user key - The Clerk key grants the user either the "ROLE_API_ORDER_READ" or "ROLE_API_ORDER_WRITE" role. This is a key that is associated with a particular api user. So the header parameter must contain both roles and they must be separated by colon. Here is example how it should look:

Depending on what you use in some requests you won't need both keys.


ClickBank API Output can be chosen between
  • XML
  • JSON
  • CSV (works only with the Orders API)
In the http header along with keys we must add Accept parameter with one from the above values. If not added the server will return 500 [Internal Server Error]. Example on http header including the desired output and both keys:


This is also vital part from your request because ClickBank API never return more than 100 rows for any service call. So for every data that is bigger than 100 rows it returns first 100 rows and a status code of 206 [Partial Content]. To get also other results from the output you must include Page After you create the header in this format you won't have any problems with authorization. Now what is left is to create a code for sending request to ClickBank API. I'm going to get first 10 pages from output ( all sale transactions between 2 dates for specific item). The code will look like this.
PAGE: '.$n.'
'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.3/orders/list?&item=5&type=SALE&startDate=2012-05-05&endDate=2012-12-31"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept:application/json", "Authorization:[YOUR_DEVELOPER_KEY]:[YOUR_CLERK_API_KEY]", "Page:".$n)); curl_setopt($ch, CURLOPT_HTTPGET, true); $return = curl_exec($ch); $result = json_decode($return); curl_close($ch); print_r($result); }
What we do above is sending GET request using curl to ClickBank API to specific URL depending from what service we access (in our case Orders API) The URL need to be updated regarding what service API u need, For version 1.3, the following API's are supported: Analytics API: https://api.clickbank.com/rest/1.3/analytics The Analytics API allows you to get subscription and statistical information given certain account permissions. Images API: https://api.clickbank.com/rest/1.3/images The Images API is related to the Product API in that it lists images associated with a site. Orders API: https://api.clickbank.com/rest/1.3/orders The Orders API allows you to get order information by receipt or date/time parameters. Products API: https://api.clickbank.com/rest/1.3/products The Products API allows full CRUD product management operations. Shipping API: https://api.clickbank.com/rest/1.3/shipping The Shipping API allows you to get shipping information for one or many physical good orders by receipt or date/time parameters. Tickets API: https://api.clickbank.com/rest/1.3/tickets The Ticket API allows you to update an order's status to returned or canceled thru the creation of a transaction ticket. Additionally, you may search for existing tickets by user. Sandbox API: https://sandbox.clickbank.com/rest/1.3/sandbox The Sandbox API provides an environment to create test accounts, developer keys, and orders. Once established, it can be used to test the tickets and order API's. Upsell API: https://api.clickbank.com/rest/1.3/upsells The Upsell API allows qualified users to create upsells via the API. Ship Notice API: https://api.clickbank.com/rest/1.3/shipping/shipnotice The Ship Notice API is a child of the shipping API and allows for ship notice generation. Sandbox Product Creation API: https://sandbox.clickbank.com/rest/1.3/sandbox/product The Sandbox Product Creation API is a child of the sandbox API and allows users to create products in the sandbox environment. Quickstats API: https://api.clickbank.com/rest/1.3/quickstats The Quickstats API provides stats about the user's account.

Other Posts You Might Like

Get a fast, free website audit

Enter your URL below to get full in-depth SEO report and tips.


Useful Scripts

Most Popular Posts

Recent Posts

June 14th, 2014
Website Optimization Using Gzip Compression

June 10th, 2014
Google Search AutoComplete API

May 14th, 2014
What is a Tag Cloud and How to Calculate it by Formula

March 27th, 2014
Error writing file /tmp (errcode 28) Solved!

February 15th, 2014
Fixed CSS & HTML Navigation Bar

February 9th, 2014
Benchmark Your Server (CPU, File IO, MySQL) with SysBench

February 8th, 2014
JavaScript Array Basics

January 29th, 2014

January 25th, 2014
Payoneer Debit Card for Freelancers to receive money online

January 24th, 2014
How HTML Color Codes are generated?

Read Latest Posts directly on Facebook