2

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.

Teja Bhagavan Kollepara
3,8275 gold badges33 silver badges69 bronze badges
asked May 17, 2016 at 17:12

3 Answers 3

1

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

answered May 17, 2016 at 17:31
2
  • 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. Commented May 20, 2016 at 7:07
  • But how to get read all the api's available in magento Commented May 20, 2016 at 7:08
1

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);
Baby in Magento
2,97517 gold badges85 silver badges227 bronze badges
answered Dec 4, 2017 at 6:14
0

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>";
}
?>
answered Apr 4, 2018 at 14:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.