Flipkart affiliate api in php

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.
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.


* 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);
             // 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.

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

// 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');

See live demo and download full source code.



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

22 Replies to “Flipkart affiliate api in php”

  1. Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\flipkart-affiliate-api-php-master\index.php on line 86

    not able to list day offer kindly help

  2. Hello Rohit,

    Nice article. I tried your code but so sorry as a non techi i am not able to use it properly. I changed the flipkart id and tocken from mine but still somethign is missing but i m not able to figure out that. Please suggest what to do.

  3. Hello Rohit,

    Thanks for sharing your expertise and knowledge. I wish to know can we have multiple affiliates in the same page ( E.g. Snapdeal and Flipkart). Also is there an option to search products and display it from both the sites.

    Thanks and Regards

  4. Hi All,

    I Have my own ecommerce website,how can i import or insert the flipkart catageories or product in my website same like affiliate marketing (but each only one link generate), need multiple link generation at a time or my site redirect to flipkart can any one help here??

  5. Thank you very much, Rohit for the useful snippet. I’ll definitely try it n let you know! Keep up the good work!

  6. Hi Rohit,

    Can we add multiple affiliate program on same page e.g. flipkart, google adsense, Mantra…


  7. hi,

    I installed your script and the Offers API or the Deals of the Day API are returning error “Invalid Headers”. Can you check and let me know what is the issue. I’m using correct tracking id and API Token for testing.


  8. It does not working showing error :

    There is no offer, Or Error on flipkart api server please contact to flipkart affiliate team.
    Is these are modified since the article is old?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.