0

Using magento rest API i can see the data of product, category etc using

https://magentohost/api/rest/products, Here is can see list of products but when i access

https://magentohost/api/rest/orders it says forbidden, I have assined all access to admin and guest but still it does not show it.

http://devdocs.magento.com/guides/m1x/api/rest/Resources/Orders/sales_orders.html

Here is my PHP code which works for product data but when i change products to orders it shows blank array

<?php
$callbackUrl = "http://localhost/magento_navo/rest.php";
$temporaryCredentialsRequestUrl = "http://localhost/magento_navo/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://localhost/magento_navo/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://localhost/magento_navo/oauth/token';
$apiUrl = 'http://localhost/magento_navo/api/rest';
$consumerKey = '5d93150171fa64e87ae316646f07b0ae';
$consumerSecret = '06b312b7b8ea4e7c6319f00bf49f1e35';
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/products";
 $resourceUrl = "$apiUrl/orders";
 $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => '*/*'));
 $productsList = json_decode($oauthClient->getLastResponse());
 echo "<pre>";
 print_r($productsList);
 }
} catch (OAuthException $e) {
 print_r($e);

Output:

stdClass Object
(
 [41] => Array
 (
 )
 [42] => Array
 (
 )
 [43] => Array
 (
 )
 [44] => Array
 (
 )
 [46] => Array
 (
 )
 [47] => Array
 (
 )
 [48] => Array
 (
 )
 [49] => Array
 (
 )
 [50] => Array
 (
 )
[51] => Array
 (
 )
Rizwan Khan
1,9692 gold badges20 silver badges43 bronze badges
asked Jul 10, 2017 at 9:27
0

2 Answers 2

0

You need to set ACL Attribute Rules from System -> Web Services -> Rest Attributes

answered May 23, 2018 at 7:29
0

Use Soap 1.1 instead of 1.2 if it fails to give you correct output like:

$opts = array(
 'http'=>array(
 'user_agent' => 'CustomSoapClient'
 )
);
$params = [
 'encoding' => 'UTF-8', 
 'soap_version' => SOAP_1_1, 
 'trace' => 1, 
 'exceptions' => 1, 
 "connection_timeout" => 180, 
 'stream_context' => stream_context_create($opts),
 'cache_wsdl' => WSDL_CACHE_NONE
];
$host = "magentostore.com"; 
$client = new SoapClient("https://".$host."/api/v2_soap/index/?wsdl=1",$params); 
answered Apr 20, 2022 at 15:28

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.