How to Use Flipkart API to Fetch Products with PHP

Flipkart API

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.

Advertisement

Tags: |

Deepanker Verma is the founder of Techlomedia. He is a tech blogger, developer and gadget freak.


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.

2020 UseThisTip | Part of Techlomedia Internet Pvt Ltd Developed By Deepanker