I'm trying to create a product using magento REST api.

I created a OAuth Consumer in magento admin and got key and secret key, I also assigned a OAuth consumer to the user. (Followed http://help.sweettoothrewards.com/article/363-rest-api-setup )

But, I'm getting "An error occurred. Your authorization request is invalid." error.

enter image description here I think, there is something wrong with callback url because of that token is not generating but not sure.

I googled, but did not got any working solution.

I followed http://devdocs.magento.com/guides/m1x/api/rest/introduction.html but it did not worked.


$callbackUrl = "http://magentohost.com/oauth_admin.php";
$temporaryCredentialsRequestUrl = "http://magentohost.com/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://magentohost.com/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://magentohost.com/oauth/token';
$apiUrl = 'http://magentohost/api/rest';
$consumerKey = 'myconsumerkey';
$consumerSecret = 'myconsumersecret';

if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
$_SESSION['state'] = 0;
try {
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);

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']);
} 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);
} else {
    $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
    $resourceUrl = "$apiUrl/products";
    $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => '*/*'));
    $productsList = json_decode($oauthClient->getLastResponse());
} catch (OAuthException $e) {

Please let me know what I'm doing wrong in this? Any suggestions always welcome.



After struggling many hours on this issue, I comes to know the exact problem.

The issue was with https, my domain was forced to use https and after disabling this, its working fine.


  • Hi Parveen, I have the same problem. Do you mean you had to make the request with HTTPS or did you edit your server so HTTPS was not required. – Ankur Mar 31 '17 at 22:19
  • yes, i edited server so that not require https. – Parveen Kumar Apr 3 '17 at 11:55

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.