How to Use Flipkart API to Fetch Products with PHP

For affiliate marketers, coupon websites and comparison websites, Flipkart offers its API. With its API, one can get products, prices, deals and even orders done by one’s affiliate. Most of the companies still rely on crawling or using but use of API is not recommended for better management. If you are one of those who want to get products from Flipkart by using its API, you must know how to use curl. Because I will be using CURL in this code.
For using the API, you must first have affiliate account. If you are reading this post, It means you already have one. I also recommend you to check the Affiliate management program by Techlomedia Gadgets. Basically this program is for those who are related to smartphones affiliate. But you can contact for more custom banners.
Now come to the Flipkart API.
You can get the products feed by using this URL:
https://affiliate-api.flipkart.net/affiliate/api/<your affiliate_tracking_id>.json
If you prefer XML, you can use this URL
https://affiliate-api.flipkart.net/affiliate/api/<your affiliate_tracking_id>.json
Here, add your tracking id of Flipkart where it asks.
This URL will give you the URLs of different flipkart categories. If you want to fetch data from all categories, you can get it. You can also just use it for specific data.
<?php $tracking= "your flipkart tracking" $flpkrturl="https://affiliate-api.flipkart.net/affiliate/api/$tracking.json"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$flpkrturl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec($ch); curl_close ($ch); $allurls = json_decode($server_output); print_r($allurls); ?>
Just parse this JSON to get URLs. For these categories specific URLs, we need authentication. You will be provided the authentication credentials in your Flipkart affiliate section.
$nexturl='flipkart category specific URL'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$nexturl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $headers = array(); $headers[] = 'Fk-Affiliate-Id: fkID'; $headers[] = 'Fk-Affiliate-Token: fkToken'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $server_output = curl_exec ($ch); curl_close ($ch); $products = json_decode($server_output);
This code will give only 50 products of that specific category. You will also get the URL to the next 50 products in each iteration until there is no product left. You can access next URL with this line:
$nexturl = $products->nextUrl;
I didn’t want to share my credential or affiliate tracking in code. This is why, you will have to test the code with your own affilaite tracking and credentials.
If you have any confusion, you can ask in comments.
Similar Articles
1 Comments
Leave a comment
Comment policy: We love comments and appreciate the time that readers spend to share ideas and give feedback. However, all comments are manually moderated and those deemed to be spam or solely promotional will be deleted.
Hi Deepankar,
Is there any way to upload the retrieved data in the database?
Yes, you can do that..
Hello deepanker,
I wants to upload products from 1 site to flipkart using flipkart API , is there any solution.?
I am not sure if there is any way to upload. Maybe there have given some option to the merchant. I never checked merchant section.
hi Deepankar
Its giving category list,
how extract product only ?
How to parse this JSON to get URLs for Product Feed API.
It is easy in PHP.. Try available tutorials.
hi how can get details of specific product like
in mobiles I want product information of IPHONE 6S
please help
By using API, you cannot do that. You need to create crawling script in PHP
How to get special price ? it returns only maximum price and selling price…
If that data is not available in API, you can use scraping process to get that data.
hi , how i can implement flipkart api in laravel ?
It is JSON or XML. You can easily implement in Laravel.
it is working online . but not working in localhost . it is getting null in array …
it is not working in xampp localhost . it is giving null ..but it is running on online server ..what is reason ?
Check response code.
Just set “curl_setopt($ch, CURLOPT_SSL_VERIFYPEER ,false);”
Thanks a Lot Bro . A detailed code without any confusion. You saved my time. Hope we’ll meet in future -> I owe you a party 🙂
I still didn’t post much, but you can always contact me for any help.
That worked out just fine . TYSM