Snapdeal affiliate api in php

This tutorial about affiliate marketing of snapdeal products, Last month i have create tutorial on flipkart affiliate api to fetch flipkart products, Same process will be follow again but here i’ll show you how to fetch snapdeal products using snapdeal affiliate api.

If you are not aware about what is affiliate marketing then below is the sort definition..

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.
For fetching snapdeal products i created a simple api in php, You only need to pass three parameter, Your affiliate id, Your token no. and Product feed url.

To generate snapdeal affiliate id and token goto snapdeal affiliate panel and create an account.
Lets start the tutorial.

Create a php class file and write some curl operation, pass required header like snapdeal affiliate id, token no etc to authenticate your request.


* Author: Rohit Kumar
* Website:
* Version: 0.0.1
* Date: 7-02-2016
* App Name: Snapdeal Affiliate Api
* Description: Simple Snapdeal api in php to create your online deals or e-commerce affiliate market place 
 class snapdealApi {
    private static $affiliateID;
    private static $token;
    private static $timeout = 45;
    //Set snapdeal 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(
	            'Snapdeal-Affiliate-Id: '.self::$affiliateID,
	            'Snapdeal-Token-Id: '.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 snapdealApi class and call the getData function.
But before calling the function you have to pass two parameter url and datatype.

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

Here first i’ll fetch all snapdeal product categories and if you’ll click any category then you’ll able see all associated products of that category.

// Get affiliateID and token from
// Set snapdeal affiliateID and token
$affiliateID = 'YOUR_AFFILIATE_ID';
$token = 'YOUR_TOKEN';
$sdObj = new snapdealApi($affiliateID, $token);
$url =  '';
$result = snapdealApi::getData($url, '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

Posted in: PHP

25 Replies to “Snapdeal affiliate api in php”

  1. I have downloaded the code and index.php is working fine fetching all the category but on choose a category i am getting error
    {“errors”:[{“errorCode”:”AUTHENTICATION_FAILED”,”errorDesc”:”Incorrect Affiliate ID provided or Affiliate token has not been generated. Please provide correct affiliate ID or generate token first”}]}

    while same Affiliate ID is working fine on list page.

    Please help

  2. Hi

    I have downloaded the source code but when i am choosing category e.d “Jewellary” and landing on page with url (http://localhost/index.php?category=Jewellery&url= the curl return me error
    {“errors”:[{“errorCode”:”AUTHENTICATION_FAILED”,”errorDesc”:”Incorrect Affiliate ID provided or Affiliate token has not been generated. Please provide correct affiliate ID or generate token first”}]}

    I have check my token id and affiliate id that is all fine, do i am missing anything

    please note i am working on localhost, i need to configure some domain in the snapdeal affiliate section ?

    please help

  3. There is some misconfiguration in your token or secret key. Categories fetched without token but for fetching products it is must to validate with valid token and secret key.

  4. Hi Rohit,

    I have integrated you snapdeal API, its not working now. please in your demo itself it is not working. May be the snapdeal server down.


  5. Code is fine issue with snapdeal affiliate token that changed by mistake. Please double check is your affiliate token is valid and able to authenticate api calls.

  6. Hi..
    I am able to get response for product feed using this not able to get any response for urls that product feeds. example for Beauty_Personal_Care”: {

    I am not getting an response. affliate id and token are correct. REST client just says empty response.500: Internal Server Error

    tried reaching snap deals team but could not.

    Thanks in advance.

  7. Snapdeal won’t pay at all.. After working with 6 months earned nearly 3000+ but they never paid. My affiliate id: 81165 . Waiting for payment nearly 3 months and mailed them so many times, they never care to reply. They are cheating webmasters. Flipcart is good. They always pays on time because they validates purchases quickly. Amazon never tried yet.

  8. Hi..Can you please share how to fetch best selling products , deal of the day and featured products using this Snapdeal API..?

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.