1

I would like to create mobile app for my magento site for that I have created REST consumer and I got consumer key and consumer secrete.. Then I create rest.php file inside rootdirectory/api/rest. When I call http://localhost/magento/api/rest/ on my postman getting an error like

{"messages": {
"error": [
  {
    "code": 401,
    "message": "oauth_problem=nonce_used"
  }
] }}

What I will do? I am new to magento webservices..

-1

You can use this PHP file and access in your browser.

<?php
$nonce = substr(md5(uniqid('nonce_', true)),0,16);
$temprealm="http://youmagentostore.com/api/rest/products";
$realm=urlencode($temprealm);
$oauth_version="1.0";
$oauth_signature_method="HMAC-SHA1";
$oauth_consumer_key="ffe7ef1d24dfecdc0e5e31a438b41464R";
$oauth_access_token="gh77390c4322c9fbe58f27e409811cop";
$oauth_method="GET";
$oauth_timestamp=time();
$algo="sha1";
$key="c8e7ef1d24ffecdc0e5e31a438b4146d&8d5e6be3ee69ce8b969594aea61b7cf3"; //consumer secret & token secret //Both are used in generate signature
$data="oauth_consumer_key=".$oauth_consumer_key."&oauth_nonce=".$nonce."&oauth_signature_method=".$oauth_signature_method."&oauth_timestamp=".$oauth_timestamp."&oauth_token=".$oauth_access_token."&oauth_version=".$oauth_version;

$send_data=$oauth_method."&".$realm."&".urlencode($data);
$sign=hash_hmac($algo,$send_data,$key,1); // consumer key and token secrat used here
$fin_sign=base64_encode($sign);
$curl = curl_init();



curl_setopt($curl,CURLOPT_HTTPHEADER,array('Authorization : OAuth realm='.$realm.', oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_nonce="'.$nonce.'", oauth_timestamp="'.$oauth_timestamp.'", oauth_consumer_key='.$oauth_consumer_key.', oauth_token='.$oauth_access_token.', oauth_signature="'.$fin_sign.'"'));

curl_setopt ($curl, CURLOPT_URL,$temprealm);
$xml=curl_exec($curl);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.