2

I am using the magento rest api client(postman & restclient) to get the products details but always returning the 404 error. Please see the attached screen shot.I have set all the values in the header.

OAuth oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_nonce="HqwgoI2wH24FsaU", oauth_timestamp="1464929692", oauth_consumer_key="35781cd8ea16ab9edc4aeb7c132299bd", oauth_token="23b8bfd8c51c4d3efdae6bdf451792b9", oauth_signature="2SrYBSzOflXyGYk%2FmYIWy8XtzOM%3D"

enter image description here

I have created a rest role named as 'pawan' and assign Role Api Resources of catalog product for create,retrieve and update.

enter image description here

And I have assign all the resources to the rest attribute 'admin' user. I have created a rest api cosumer and used the given cosumer key and consumer secret in my controller where I am just doing the authentication for the magento consumer and requestiing for the request token and then callback function is called.

class Custom_Restapi_TestController extends Mage_Core_Controller_Front_Action {

public function indexAction()
{
    //Basic parameters that need to be provided for oAuth authentication
    //on Magento
     $params = array(
            'siteUrl' => 'http://172.16.10.16/~pmahajan/magento/index.php/oauth',
            'accessTokenUrl' => 'http://172.16.10.16/~pmahajan/magento/index.php/oauth/token',
            'requestTokenUrl' => 'http://172.16.10.16/~pmahajan/magento/index.php/oauth/initiate',
            'authorizeUrl' => 'http://172.16.10.16/~pmahajan/magento/index.php/admin/oauth_authorize',//This URL is used only if we authenticate as Admin user type
            'consumerKey' => '35781cd8ea16ab9edc4aeb7c132299bd',//Consumer key registered in server administration
            'consumerSecret' => 'df759660479433bb61f60d559b7b2192',//Consumer secret registered in server administration
            'callbackUrl' => 'http://172.16.10.16/~pmahajan/magento/index.php/restapi/test/callback',//Url of callback action below
        );
    // Initiate oAuth consumer with above parameters
    $consumer = new Zend_Oauth_Consumer($params);
    // Get request token
    $requestToken = $consumer->getRequestToken();
    // Get session
    $session = Mage::getSingleton('core/session');
    // Save serialized request token object in session for later use
    $session->setRequestToken(serialize($requestToken));
    // Redirect to authorize URL
    //Zend_Debug::dump( serialize($requestToken) );
    //Zend_Debug::dump( $requestToken );
    $consumer->redirect();
    return;
}

public function callbackAction()
{
//oAuth parameters
   $params = array(
         'siteUrl' => 'http://172.16.10.16/~pmahajan/magento/index.php/oauth',
            'requestTokenUrl' => 'http://172.16.10.16/~pmahajan/magento/index.php/oauth/initiate',
            'accessTokenUrl' => 'http://172.16.10.16/~pmahajan/magento/index.php/oauth/token',
            'consumerKey' => '35781cd8ea16ab9edc4aeb7c132299bd',
            'consumerSecret' => 'df759660479433bb61f60d559b7b2192'
    );


    // Get session
    $session = Mage::getSingleton('core/session');
    // Read and unserialize request token from session
    $requestToken = unserialize($session->getRequestToken());
  // echo 'request token';print_r($requestToken);
   //echo '<br/>';
    $consumer = new Zend_Oauth_Consumer($params);
    // Using oAuth parameters and request Token we got, get access token
    Mage::log('Get Array:' . print_r($_GET, true) );
    $acessToken = $consumer->getAccessToken($_GET, $requestToken);

    $restClient = $acessToken->getHttpClient($params);
    // Set REST resource URL
   $restClient->setUri('http://172.16.10.16/~pmahajan/magento/index.php/api/rest/products');
    // In Magento it is neccesary to set json or xml headers in order to work
    $restClient->setHeaders('Accept', 'application/json');
    // Get method
    $restClient->setMethod(Zend_Http_Client::GET);
    //Make REST request
    $response = $restClient->request();
    // Here we can see that response body contains json list of products
    print_r($acessToken);
    //Zend_Debug::dump($response);
    return;
}

}

In the callback function I am getting the accessToken and accessSecret and these are used in the postman header.

Now I am hitting the URL in rest client postman : http://172.16.10.16/~pmahajan/magento/index.php/api/rest/products?limit=2

but it is returning the 404 error. If anyone has any idea please suggest me. Thank You.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.