How to get all products from flipkart seller api in php

521 Views Asked by At

Please let me know how I can get the all products through the Flipkart seller API. I am not able to get this api.

I have tried this but it gives me error:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.flipkart.net/sellers/listings/v3');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$headers = array();
$headers[] = 'Authorization: Bearer xxxxxx-8be7-429c-xxx-xxxx';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}else{
    echo $result;
}
curl_close($ch);

output: {"errors":[{"severity":"ERROR","code":10000,"description":"HTTP 405 Method Not Allowed"}]}

Please help me to get all products.

Thanks in Advance!!

1

There are 1 best solutions below

5
Baptiste On

You should read the doc. The error is pretty clear, you're using GET instead of POST for this url endpoint.

Following the doc you can see this section:

Retrieve the information listed against the provided SKU Ids.

https://seller.flipkart.com/api-docs/listing-api-docs/LMAPIRef.html#get-listings-v3-sku-ids

I guess that it's what you want.

<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.flipkart.net/sellers/listings/v3/my-sku-id",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_POSTFIELDS => "",
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer XXXXXX"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

And please, do not share your token in a public post.