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.
https://affiliate.snapdeal.com/
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.
snapdealApiClass.php
<?php /* * Author: Rohit Kumar * Website: iamrohit.in * 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( 'Accept:application/'.$dataType, '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); 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 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.
<?php include_once("snapdealApiClass.php"); // Get affiliateID and token from https://affiliate.snapdeal.com // Set snapdeal affiliateID and token $affiliateID = 'YOUR_AFFILIATE_ID'; $token = 'YOUR_TOKEN'; $sdObj = new snapdealApi($affiliateID, $token); $url = 'http://affiliate-feeds.snapdeal.com/feed/72967.json'; $result = snapdealApi::getData($url, 'json'); var_dump($result); ?> |
See live demo and download full source code.
DEMO | DOWNLOAD |
Hello,
I am not able to download “Snapdeal affiliate api in php” , already subscribed on there.
i mailed you
how can i include both api to wordpress and show rendom product of both
I want to get n level categories from snapdeal. How can I get this. plz help.
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
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=http://affiliate-feeds.snapdeal.com/feed/api/category/v1:6:1721861471?expiresAt=1464733800001&signature=zzavjdhfbajutcskbzfz) 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
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.
how do we perform search in snapdeal affiliate api.
is there possible to search.
how to i get product by sku
i have some sku list of snapdeal website
Need to create wordpress plugin
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.
Regards,
Maries
i was looking at demo link but nothing is showing up.
Demo is working fine now..
Demo is working fine now..
hei again,
I hope you updated your download code too. because it doesnt seems to be working. same issue as demo was showing
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.
hi,
yes it is working fine now. you are champ.
Thank you 🙂
You’r welcome
Hi..
I am able to get response for product feed using this http://affiliate-feeds.snapdeal.com/feed/81714.json.but not able to get any response for urls that product feeds. example for Beauty_Personal_Care”: {
“http://affiliate-feeds.snapdeal.com/feed/api/category/v1:586:643411205317?expiresAt=1470738600002&signature=ddopgoqnwotokvplyddj”.
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.
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.
i am searching API code from last 5 to 6 days finally my search ends here. Thanks
How to install this to wordpress???
Need to create plugin for using in wordpress
Hi..Can you please share how to fetch best selling products , deal of the day and featured products using this Snapdeal API..?
Hi
I am not able to download snapdeal or flipkart api in php please mail me thanks in advance