I have followed the below steps for authentication for REST API
Then I have tried to access this link
The error response which I got is
<magento_api> <messages> <error> <data_item> <code>404</code> <message>Request does not match any route.</message> </data_item></error> </messages> </magento_api>
Please help us how to make it up & reachable , how to get response from the request, which is the url to access the rest api.
Let me know if I missed anything in the above configuration.
3 Answers 3
Seems the path is wrong. Is your base install at http://127.0.0.2 or http://127.0.0.2/magento ? Try visiting both locations and make sure the base url is viable.
Once that's set. Try again, hopefully you get another response like the following: {\"messages\":{\"error\":[{\"code\":401,\"message\":\"oauth_problem=parameter_absent&oauth_parameters_absent=oauth_token\"}]}}
Please review the following resources and build on the original question for additional feedback.
Ref:
http://devdocs.magento.com/guides/m1x/api/rest/testing_rest_resources.html http://devdocs.magento.com/guides/m1x/api/rest/introduction.html
- 
 Yes 127.0.0.2/magento is my base url and tried now i am able to get the response . I am able to access Images, categories & products.Karthik Rao– Karthik Rao2016年05月20日 07:07:38 +00:00Commented May 20, 2016 at 7:07
- 
 But how to get read all the api's available in magentoKarthik Rao– Karthik Rao2016年05月20日 07:08:04 +00:00Commented May 20, 2016 at 7:08
can you try this code as your result
<?php
$userData = array("username" => "user_role_name", "password" => "user_role_password");
$ch = curl_init("http://your url/index.php/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));
$token = curl_exec($ch);
$ch = curl_init("http://testrexecom.humcommerce.com/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=created_at&searchCriteria[filter_groups][0][filters][0][value]=2017年01月02日 05:40:00.0000000Z&searchCriteria[filter_groups][0][filters][0][condition_type]=from&searchCriteria[filter_groups][1][filters][0][field]=created_at&searchCriteria[filter_groups][1][filters][0][value]=2017年11月23日T11:06:00.0000000Z&searchCriteria[filter_groups][1][filters][0][condition_type]=to&searchCriteria[currentPage]=1&searchCriteria[pageSize]=100");
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);
You can use this sample file below to connect on you Magento 1 API REST, and following this video: https://youtu.be/Mj1icy_6Cro
<?php
// Reference http://devdocs.magento.com/guides/m1x/api/rest/introduction.html#RESTAPIIntroduction-RESTResources
// Custom Resource
$apiResources = "products?limit=2";
// Custom Values
$isAdminUser = true;
$adminUrl = "admin";
$callbackUrl = "http://dev.local3.com/rest.php";
$host = 'http://dev.local3.com/magento/';
$consumerKey = '7e1339ba397c917f00066fca13543934';
$consumerSecret = '6a3bc1999d9399c655f0b28edbdb8610';
// Don't change
$temporaryCredentialsRequestUrl = $host . "oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = ($isAdminUser) ? $host . $adminUrl . "/oauth_authorize" : $host . "oauth/authorize";
$accessTokenRequestUrl = $host . "oauth/token";
$apiUrl = $host . "api/rest/";
session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
 $_SESSION['state'] = 0;
}
try {
 $authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
 $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
 $oauthClient->enableDebug();
 if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
 $requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
 $_SESSION['secret'] = $requestToken['oauth_token_secret'];
 $_SESSION['state'] = 1;
 header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
 exit;
 } else if ($_SESSION['state'] == 1) {
 $oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
 $accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
 $_SESSION['state'] = 2;
 $_SESSION['token'] = $accessToken['oauth_token'];
 $_SESSION['secret'] = $accessToken['oauth_token_secret'];
 header('Location: ' . $callbackUrl);
 exit;
 } else {
 $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
 $resourceUrl = $apiUrl.$apiResources;
 $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => '*/*'));
 // $productsList = json_decode($oauthClient->getLastResponse());
 $productsList = $oauthClient->getLastResponse();
 // echo "<pre>";
 print_r($productsList);
 // echo "</pre>";
 }
} catch (OAuthException $e) {
 echo "<pre>";
 print_r($e->getMessage());
 echo "<br/>";
 print_r($e->lastResponse);
 echo "</pre>";
}
?>