1

I am getting error 404 when running this code. It uses flipkart-affiliate-client npm package for flipkart api (https://github.com/zivost/flipkart-affiliate-client)

var flipkart = require('flipkart-affiliate-client');
const express = require('express');
const router = express.Router();

var client = flipkart.createClient({
    FkAffId: 'fkid', 
    FkAffToken: 'token',
    responseType: 'json'
});




client.keywordSearch({
    query: "iphone",
    resultCount: "1"
}, function(err, results) {
    if (err) {
        console.log(err + "!!!!!!!!");
    } else {
        console.log(results);
    }
});

The aafiliate id and token are correct.

Kartik
  • 81
  • 1
  • 5
  • I also getting the same issue.. anyone knows the solution to fix it? getting below error: Error 404 Not Found – ashish May 16 '18 at 14:16

2 Answers2

1

I fixed this issue and the reason is now flipkart is using new api.. If you need to use nodejs 'flipkart-affiliate-client' plugin. then do below changes:

  1. locate the file in nodejs project path '\node_modules\flipkart-affiliate-client\lib\utils.js'.

  2. find the check ' if (method === 'keywordSearch') {'.

  3. replace the flipkart api url as below:

for xml response replace api url ==> https://affiliate-api.flipkart.net/affiliate/1.0/search.xml

for json response replace api url ==> https://affiliate-api.flipkart.net/affiliate/1.0/search.json.

now in server js file write below code to get data from either client or any tool like POSTMAN etc:

app.route('/api/getflipkartproducts/:productname').get((req, res)=>{
  var productName=req.params['productname'];
  var client = flipkart.createClient({
    FkAffId: '(trackingcode)',
    FkAffToken: '(token)',
    responseType: 'json/xml' //json or xml response
  });
  console.log('productName : '+productName);
  client.keywordSearch({
    query: productName,
    resultCount: "5"
  }, function(err, result){
      if(!err){
        console.log(result);
        res.send({'results':result});
      }else {
        console.log(err);
        console.log('result :'+result);
        res.send({'error':err});
      }
  });

and this will make success in getting data from flipkart.

ashish
  • 247
  • 2
  • 3
  • Can you please explain me how you are using this API in angular CLI . I'm using the angular 8 cli. Don't have any idea how i use this api in angular 8. – Aman Gupta Sep 26 '19 at 06:32
0

Alternatively You can use this npm package which is build based on javascript promises.

flipkart-api-affiliate-client

Chandra Shekhar
  • 3,550
  • 2
  • 14
  • 22