-1

Hi Good evening currently working on flipkart / snapdeal rest api in which we have to curl the data . In command prompt its working fine and give me desired output . But now i want to call that in code and unable to do that . Kindly help me out for that . Api contain the token and token id . here my command which is working fine.

curl -H "Fk-Affiliate-Id:abhishekbh" -H "Fk-Affiliate-Token:2dacb05681b8481eb65201283dac2630" "https://affiliate-api.flipkart.net/affiliate/1.0/feeds/abhishebh/category/7jv.json?expiresAt=1489539219049&sig=ad5ef1af7f41d68d9f8f1c1ae85e20b6" 
Indian Thinking
  • 103
  • 1
  • 8
  • Have a look at the [PHP cURL library](http://php.net/manual/en/book.curl.php), you'll be able to build an equivalent for your cmd line in PHP. – roberto06 Mar 14 '17 at 15:30
  • ya i check that but i am confused in that – Indian Thinking Mar 14 '17 at 15:32
  • Based on your tags, I'm assuming you want PHP code? Are you wanting to use any specific library? You might also try using Guzzle http://docs.guzzlephp.org/en/latest/ If you make an attempt at it, you can post that code back here, and it will be better for us to help you debug rather than write code for you. – Loren Mar 14 '17 at 16:32

1 Answers1

0

Here is the php code to send request using curl.

$s = curl_init(); 
curl_setopt($s,CURLOPT_URL,'https://affiliate-api.flipkart.net/affiliate/1.0/feeds/abhishekbh/category/7jv.json?expiresAt=1489539219049&sig=ad5ef1af7f41d68d9f8f1c1ae85e20b6'); 
curl_setopt($s,CURLOPT_HTTPHEADER,array('Fk-Affiliate-Id:abhishekbh', 'Fk-Affiliate-Token:2dacb05681b8481eb65291283dac2630')); 
curl_setopt($s,CURLOPT_HEADER,true);
$result = curl_exec($s);

echo "<pre>";print_r($result);echo "</pre>";
siddiq
  • 1,693
  • 3
  • 17
  • 44
  • 1
    Don't mention the actual secret credentials (affiliate-id,affiliate-token) in the forums. Everyone can see the actual output then. – siddiq Mar 14 '17 at 16:14
  • ok sir its does not give any error but does not show any json – Indian Thinking Mar 14 '17 at 16:20
  • Open the http://phpfiddle.org/ and in code-pace run the above code. you can see the output in json format. If that works, it means it is working. http://dl.flipkart.com/dl/colavita-fusilli-pasta/p/itmea7z22ruvxtga?pid=PSAEA7Z2YGAFGGYW&affid=abhishekbh this is product url i got in the response. – siddiq Mar 14 '17 at 16:28
  • ya its working but why its not working on local server – Indian Thinking Mar 14 '17 at 16:34
  • http://sabkideal.com/snap/curl.php ya its working but not coming in proper json view – Indian Thinking Mar 14 '17 at 16:36
  • Set CURLOPT_HEADER as false like `curl_setopt($s,CURLOPT_HEADER,false);` this. I have set as true in the answer i posted. When this param is set as true, you will get the output header also in the response. – siddiq Mar 14 '17 at 16:48
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/138039/discussion-between-siddiq-and-indian-thinking). – siddiq Mar 14 '17 at 16:50