In this tutorial i am going to discuss about affiliate marketing of flipkart. First of all you should know about affiliate marketing. In india affiliate marketing growing day by day and people are earning very good amount of money from affiliate marketing.

What is affiliate marketing

Affiliate marketing is the process of earning a commission by promoting other people’s (or company’s) products. You find a product you like, promote it to others, and earn a piece of the commission for each sale that you make.
Or for more info about affiliate marketing you can google it.
flipkart-api-1
So here i have created a flipkart affiliate api in php, So by using this API you can easily fetch flipkart offer and deals and display on your website.




Now Lets start the tutorial.

For using this api, You have to create flipkart affiliate account on https://affiliate.flipkart.com

After that you will able to generate your affiliate id and token to authenticate yourself during item request.

So here is the class file.

flipkartApiClass.php

<?php
/*
* Author: Rohit Kumar
* Website: iamrohit.in
* Version: 0.0.1
* Date: 16-01-2016
* App Name: FlipKart Affiliate Api
* Description: Simple flipkart api in php to create your online deals or e-commerce affiliate market place 
*/
 class flipkartApi {
 
    private static $affiliateID;
 
    private static $token;
 
    private static $timeout = 45;
 
    //Set filpkart affilate id and token at the time of class init.
 
     public function __construct($affiliateID, $token) {
       self::$affiliateID = $affiliateID;
       self::$token = $token;
      }
 
 
     public static function getData($url, $dataType) {
 
         try {
 
         	if(!isset($url) && !empty($url)) {
         		throw new exception("URL is not available.");
         	}
 
         	if(!isset($dataType) && !empty($dataType)) {
         		throw new exception("Please set datatype json or xml");
         	}
 
         	if (!function_exists('curl_init')){
                throw new exception("Curl is not available.");
         	}
         	 // Set header to make authentication
	        $headers = array(
	            'Cache-Control: no-cache',
	            'Fk-Affiliate-Id: '.self::$affiliateID,
	            'Fk-Affiliate-Token: '.self::$token
	            );
 
	        $cObj = curl_init();
	        curl_setopt($cObj, CURLOPT_URL, $url);
	        curl_setopt($cObj, CURLOPT_HTTPHEADER, $headers);
	        curl_setopt($cObj, CURLOPT_TIMEOUT, self::$timeout);
	        curl_setopt($cObj, CURLOPT_RETURNTRANSFER, TRUE);
	        $result = curl_exec($cObj);
	        curl_close($cObj);
             // render result as per format.
             if($dataType == 'json') {
               return $result ? json_decode($result, true) : false;
             } else if($dataType == 'xml') {
                return $result ? new SimpleXMLElement($result) : false;
             } else {
             	return false;
             }
 
         }  catch (Exception $e) {
            return $e->getMessage();
         }
      }
 }
 
?>




After that initialize flipkartApi class and call the getData function.
But before calling the function you have to pass two parameter url and datatype.
Here i am going to fetch flipkart offer in json format, You can get flipkart offer url from your affiliate account see attached image.
fkart-api

Pass these two parameter on getData function. Don’t forget to pass affilateID and token at the time of flipkartApi class inilization.

include_once("flipkartApiClass.php");
 
// Get affiliateID and token from https://affiliate.flipkart.com/
// Set flipkart affiliateID and token
$affiliateID = 'YOUR_AFFILIATE_ID';
$token = 'YOUR_TOKEN';
$fkObj = new flipkartApi($affiliateID, $token);
 
// fetch flipkart offer
$offerJsonURL =  'https://affiliate-api.flipkart.net/affiliate/offers/v1/all/json';
 
$result = flipkartApi::getData($offerJsonURL, 'json');
var_dump($result);

“datagemba.com” is using this code for their deals section, See live running example CLICK HERE

See live demo and download full source code.


DEMO


DOWNLOAD

If you like this post please don’t forget to subscribe my public notebook for more useful stuff