Magento 1.9 REST API CallbackMagento REST API: What populates the api2_acl_attribute Table?OAuth for REST API using PHPAccess Pre-Authorized Rest APINot able to get OAuth token for Magento Rest API ClientMagento's REST API responses claiming oauth_callback param is emptyHaving issue with magento 1.9 with API handlinghow to use magento REST api for creating productsIntegrate Magento REST API (OAUTH1.0) with SAP PIMagento ver. 1.9.3.6 - oauthUnable to get access_token for Magento2.0

Electric guitar: why such heavy pots?

Is it possible to measure lightning discharges as Nikola Tesla?

Transfer over $10k

What is a Recurrent Neural Network?

What's the metal clinking sound at the end of credits in Avengers: Endgame?

Do I have to worry about players making “bad” choices on level up?

What's the polite way to say "I need to urinate"?

Pressure to defend the relevance of one's area of mathematics

What does "rf" mean in "rfkill"?

Stark VS Thanos

Are Boeing 737-800’s grounded?

Please, smoke with good manners

Python "triplet" dictionary?

Why do TACANs not have a symbol for compulsory reporting?

Is it possible to Ready a spell to be cast just before the start of your next turn by having the trigger be an ally's attack?

What does YCWCYODFTRFDTY mean?

Unexpected email from Yorkshire Bank

Toggle Overlays shortcut?

Multiple options for Pseudonyms

gnu parallel how to use with ffmpeg

Phrase for the opposite of "foolproof"

Why is the origin of “threshold” uncertain?

Is thermodynamics only applicable to systems in equilibrium?

In gnome-terminal only 2 out of 3 zoom keys work



Magento 1.9 REST API Callback


Magento REST API: What populates the api2_acl_attribute Table?OAuth for REST API using PHPAccess Pre-Authorized Rest APINot able to get OAuth token for Magento Rest API ClientMagento's REST API responses claiming oauth_callback param is emptyHaving issue with magento 1.9 with API handlinghow to use magento REST api for creating productsIntegrate Magento REST API (OAUTH1.0) with SAP PIMagento ver. 1.9.3.6 - oauthUnable to get access_token for Magento2.0






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















so I just set up my M1.9 store, and want to set up a REST API. I wanted to test it out by retrieving a list of products. I only don't know what to put in the callbackurl field, online they say the location of the .php file I'm using but I'm running it locally and the magento server is on a dedicated server, so that doesn't work out.



Here's the code i use



<?php
$callbackUrl = "";
$temporaryCredentialsRequestUrl = "http://52.59.36.230/magento/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://52.59.36.230/magento/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://52.59.36.230/magento/oauth/token';
$apiUrl = 'http://52.59.36.230/magento/api/rest';
$consumerKey = '***';
$consumerSecret = '***';

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";
$oauthClient->fetch($resourceUrl);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);

catch (OAuthException $ex )
print_r($e);

?>


Anyone who could help me further ?



EDIT:



I'm running my code trough PHPStorm, so it uses my localhost. The magento server is running on an AWS instance.










share|improve this question






















  • After authorization the call back url will be redirected to the place we want e.g.magento.loc/api/rest/products or function we want to call e.g. magento.loc/restconnect/test/callback. I used this link for my ref. inchoo.net/magento/consuming-magento-rest-zend_oauth_consumer.

    – Arjun
    Jul 13 '16 at 11:26











  • @Arjun ok so when I put in the magentoloc/api/rest/products it gives me an access denied ?

    – TanguyB
    Jul 13 '16 at 11:29











  • Yes for guest customer the api/rest/products are denied. You need to pass authorization key along with it in header for allowing it access as a customer.

    – Arjun
    Jul 13 '16 at 11:36











  • @Arjun I'm confused, the WEB API roles are set up and I use the 2 given keys in my script, what else is missing ?

    – TanguyB
    Jul 13 '16 at 11:38











  • I would suggest you to check these page devdocs.magento.com/guides/m1x/api/rest/….

    – Arjun
    Jul 13 '16 at 11:50

















0















so I just set up my M1.9 store, and want to set up a REST API. I wanted to test it out by retrieving a list of products. I only don't know what to put in the callbackurl field, online they say the location of the .php file I'm using but I'm running it locally and the magento server is on a dedicated server, so that doesn't work out.



Here's the code i use



<?php
$callbackUrl = "";
$temporaryCredentialsRequestUrl = "http://52.59.36.230/magento/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://52.59.36.230/magento/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://52.59.36.230/magento/oauth/token';
$apiUrl = 'http://52.59.36.230/magento/api/rest';
$consumerKey = '***';
$consumerSecret = '***';

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";
$oauthClient->fetch($resourceUrl);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);

catch (OAuthException $ex )
print_r($e);

?>


Anyone who could help me further ?



EDIT:



I'm running my code trough PHPStorm, so it uses my localhost. The magento server is running on an AWS instance.










share|improve this question






















  • After authorization the call back url will be redirected to the place we want e.g.magento.loc/api/rest/products or function we want to call e.g. magento.loc/restconnect/test/callback. I used this link for my ref. inchoo.net/magento/consuming-magento-rest-zend_oauth_consumer.

    – Arjun
    Jul 13 '16 at 11:26











  • @Arjun ok so when I put in the magentoloc/api/rest/products it gives me an access denied ?

    – TanguyB
    Jul 13 '16 at 11:29











  • Yes for guest customer the api/rest/products are denied. You need to pass authorization key along with it in header for allowing it access as a customer.

    – Arjun
    Jul 13 '16 at 11:36











  • @Arjun I'm confused, the WEB API roles are set up and I use the 2 given keys in my script, what else is missing ?

    – TanguyB
    Jul 13 '16 at 11:38











  • I would suggest you to check these page devdocs.magento.com/guides/m1x/api/rest/….

    – Arjun
    Jul 13 '16 at 11:50













0












0








0








so I just set up my M1.9 store, and want to set up a REST API. I wanted to test it out by retrieving a list of products. I only don't know what to put in the callbackurl field, online they say the location of the .php file I'm using but I'm running it locally and the magento server is on a dedicated server, so that doesn't work out.



Here's the code i use



<?php
$callbackUrl = "";
$temporaryCredentialsRequestUrl = "http://52.59.36.230/magento/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://52.59.36.230/magento/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://52.59.36.230/magento/oauth/token';
$apiUrl = 'http://52.59.36.230/magento/api/rest';
$consumerKey = '***';
$consumerSecret = '***';

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";
$oauthClient->fetch($resourceUrl);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);

catch (OAuthException $ex )
print_r($e);

?>


Anyone who could help me further ?



EDIT:



I'm running my code trough PHPStorm, so it uses my localhost. The magento server is running on an AWS instance.










share|improve this question














so I just set up my M1.9 store, and want to set up a REST API. I wanted to test it out by retrieving a list of products. I only don't know what to put in the callbackurl field, online they say the location of the .php file I'm using but I'm running it locally and the magento server is on a dedicated server, so that doesn't work out.



Here's the code i use



<?php
$callbackUrl = "";
$temporaryCredentialsRequestUrl = "http://52.59.36.230/magento/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://52.59.36.230/magento/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://52.59.36.230/magento/oauth/token';
$apiUrl = 'http://52.59.36.230/magento/api/rest';
$consumerKey = '***';
$consumerSecret = '***';

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";
$oauthClient->fetch($resourceUrl);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);

catch (OAuthException $ex )
print_r($e);

?>


Anyone who could help me further ?



EDIT:



I'm running my code trough PHPStorm, so it uses my localhost. The magento server is running on an AWS instance.







magento-1.9 php rest oauth phpstorm






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 13 '16 at 11:17









TanguyBTanguyB

18311




18311












  • After authorization the call back url will be redirected to the place we want e.g.magento.loc/api/rest/products or function we want to call e.g. magento.loc/restconnect/test/callback. I used this link for my ref. inchoo.net/magento/consuming-magento-rest-zend_oauth_consumer.

    – Arjun
    Jul 13 '16 at 11:26











  • @Arjun ok so when I put in the magentoloc/api/rest/products it gives me an access denied ?

    – TanguyB
    Jul 13 '16 at 11:29











  • Yes for guest customer the api/rest/products are denied. You need to pass authorization key along with it in header for allowing it access as a customer.

    – Arjun
    Jul 13 '16 at 11:36











  • @Arjun I'm confused, the WEB API roles are set up and I use the 2 given keys in my script, what else is missing ?

    – TanguyB
    Jul 13 '16 at 11:38











  • I would suggest you to check these page devdocs.magento.com/guides/m1x/api/rest/….

    – Arjun
    Jul 13 '16 at 11:50

















  • After authorization the call back url will be redirected to the place we want e.g.magento.loc/api/rest/products or function we want to call e.g. magento.loc/restconnect/test/callback. I used this link for my ref. inchoo.net/magento/consuming-magento-rest-zend_oauth_consumer.

    – Arjun
    Jul 13 '16 at 11:26











  • @Arjun ok so when I put in the magentoloc/api/rest/products it gives me an access denied ?

    – TanguyB
    Jul 13 '16 at 11:29











  • Yes for guest customer the api/rest/products are denied. You need to pass authorization key along with it in header for allowing it access as a customer.

    – Arjun
    Jul 13 '16 at 11:36











  • @Arjun I'm confused, the WEB API roles are set up and I use the 2 given keys in my script, what else is missing ?

    – TanguyB
    Jul 13 '16 at 11:38











  • I would suggest you to check these page devdocs.magento.com/guides/m1x/api/rest/….

    – Arjun
    Jul 13 '16 at 11:50
















After authorization the call back url will be redirected to the place we want e.g.magento.loc/api/rest/products or function we want to call e.g. magento.loc/restconnect/test/callback. I used this link for my ref. inchoo.net/magento/consuming-magento-rest-zend_oauth_consumer.

– Arjun
Jul 13 '16 at 11:26





After authorization the call back url will be redirected to the place we want e.g.magento.loc/api/rest/products or function we want to call e.g. magento.loc/restconnect/test/callback. I used this link for my ref. inchoo.net/magento/consuming-magento-rest-zend_oauth_consumer.

– Arjun
Jul 13 '16 at 11:26













@Arjun ok so when I put in the magentoloc/api/rest/products it gives me an access denied ?

– TanguyB
Jul 13 '16 at 11:29





@Arjun ok so when I put in the magentoloc/api/rest/products it gives me an access denied ?

– TanguyB
Jul 13 '16 at 11:29













Yes for guest customer the api/rest/products are denied. You need to pass authorization key along with it in header for allowing it access as a customer.

– Arjun
Jul 13 '16 at 11:36





Yes for guest customer the api/rest/products are denied. You need to pass authorization key along with it in header for allowing it access as a customer.

– Arjun
Jul 13 '16 at 11:36













@Arjun I'm confused, the WEB API roles are set up and I use the 2 given keys in my script, what else is missing ?

– TanguyB
Jul 13 '16 at 11:38





@Arjun I'm confused, the WEB API roles are set up and I use the 2 given keys in my script, what else is missing ?

– TanguyB
Jul 13 '16 at 11:38













I would suggest you to check these page devdocs.magento.com/guides/m1x/api/rest/….

– Arjun
Jul 13 '16 at 11:50





I would suggest you to check these page devdocs.magento.com/guides/m1x/api/rest/….

– Arjun
Jul 13 '16 at 11:50










1 Answer
1






active

oldest

votes


















0














This $callbackURL should work in the sample above.



$callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";





share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f125545%2fmagento-1-9-rest-api-callback%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    This $callbackURL should work in the sample above.



    $callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";





    share|improve this answer



























      0














      This $callbackURL should work in the sample above.



      $callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";





      share|improve this answer

























        0












        0








        0







        This $callbackURL should work in the sample above.



        $callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";





        share|improve this answer













        This $callbackURL should work in the sample above.



        $callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 1 '17 at 15:33









        David St.AmourDavid St.Amour

        1




        1



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f125545%2fmagento-1-9-rest-api-callback%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Sum ergo cogito? 1 nng

            三茅街道4182Guuntc Dn precexpngmageondP