I would like to use cURL to get all orders using rest API. Can I use cURL instead of Oath.
I tried with cURL but returns 403 Forbidden.
I have tried with below code :
$params = array(
 "oauth_callback" => $oauthCallback,
 "oauth_consumer_key" => $oauthConsumerKey,
 "oauth_nonce" => $oauthNonce,
 "oauth_signature_method" => $oauthSignatureMethod,
 "oauth_timestamp" => $oauthTimestamp,
 "oauth_version" => $oauthVersion,
);
$header = "";
foreach ($params as $key=>$value){
 $header .= $key.'="'.$value."\", ";
}
$header .= "oauth_signature=\"".$oauthSignature.'"';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array($header));
curl_setopt($curl, CURLOPT_URL, $endpointUrl);
$response = curl_exec($curl);
echo "<pre>";
print_r($response);
curl_close($curl);
- 
 how did you pass the credetials? Paste the code plzDetzler– Detzler2016年05月17日 12:29:33 +00:00Commented May 17, 2016 at 12:29
- 
 Hello Detzler, I have added below code.Ankit Ahilwal– Ankit Ahilwal2016年05月17日 12:49:43 +00:00Commented May 17, 2016 at 12:49
2 Answers 2
Can't event explain it better than the official magento rest documenation:
http://devdocs.magento.com/guides/m1x/api/rest/introduction.html#RESTAPIIntroduction-PHPExamples
- 
 You are right, but I need to connect with cURL not using Oauth. With Oauth I can easily use.Ankit Ahilwal– Ankit Ahilwal2016年05月17日 12:58:58 +00:00Commented May 17, 2016 at 12:58
- 
 you need to follow the oauth protocol to authentificate. You can not bypass this method. If you can't use the OAuth php extension, use a php implementation like developer.github.com/v3/oauthDetzler– Detzler2016年05月17日 13:53:19 +00:00Commented May 17, 2016 at 13:53
Try Below code,it is working for me and return particular order detail in json format
$url="http://localhost/magento2/index.php/";
$token_url=$url."rest/V1/integration/admin/token";
$product_url=$url. "rest/V1/products";
$username="admin";
$password="admin@123";
//Authentication rest API magento2, get access token
$ch = curl_init();
$data = array("username" => $username, "password" => $password);
$data_string = json_encode($data);
$ch = curl_init($token_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
 'Content-Type: application/json',
 'Content-Length: ' . strlen($data_string))
 );
$token = curl_exec($ch);
$ch = curl_init("http://localhost/magento2/index.php/rest/V1/orders/1");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
$result = curl_exec($ch);
$result = json_decode($result, 1);
echo '<pre>';print_r($result);
Hope,it will help you.
- 
 hey @akgola i am getting response with 404 error page. Can you help me hereJay Momaya– Jay Momaya2020年04月17日 12:46:54 +00:00Commented Apr 17, 2020 at 12:46
- 
 @JayMomaya hope you have replaced the $url, $username and $password values and tried?Thamo– Thamo2021年06月23日 11:09:36 +00:00Commented Jun 23, 2021 at 11:09
- 
 It's been more than 1 year now. I don't remember anything now. @ThamoJay Momaya– Jay Momaya2021年06月24日 17:33:26 +00:00Commented Jun 24, 2021 at 17:33