Magento 1.9 REST API Callback Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar ManaraMagento 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
How to keep bees out of canned beverages?
Does Feeblemind produce an ongoing magical effect that can be dispelled?
Would reducing the reference voltage of an ADC have any effect on accuracy?
Why did Israel vote against lifting the American embargo on Cuba?
A Paper Record is What I Hamper
Expansion//Explosion and Siren Stormtamer
"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?
What *exactly* is electrical current, voltage, and resistance?
Is a 5 watt UHF/VHF handheld considered QRP?
"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"
Protagonist's race is hidden - should I reveal it?
The art of proof summarizing. Are there known rules, or is it a purely common sense matter?
As an international instructor, should I openly talk about my accent?
Is Electric Central Heating worth it if using Solar Panels?
Suing a Police Officer Instead of the Police Department
Second order approximation of the loss function (Deep learning book, 7.33)
How to get even lighting when using flash for group photos near wall?
Could moose/elk survive in the Amazon forest?
How would this chord from "Rocket Man" be analyzed?
Co-worker works way more than he should
Seek and ye shall find
My admission is revoked after accepting the admission offer
What is this word supposed to be?
What is /etc/mtab in Linux?
Magento 1.9 REST API Callback
Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraMagento 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;
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
bumped to the homepage by Community♦ 5 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
|
show 2 more comments
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
bumped to the homepage by Community♦ 5 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
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
|
show 2 more comments
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
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
magento-1.9 php rest oauth phpstorm
asked Jul 13 '16 at 11:17
TanguyBTanguyB
18311
18311
bumped to the homepage by Community♦ 5 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 5 hours ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
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
|
show 2 more comments
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
|
show 2 more comments
1 Answer
1
active
oldest
votes
This $callbackURL should work in the sample above.
$callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
This $callbackURL should work in the sample above.
$callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";
add a comment |
This $callbackURL should work in the sample above.
$callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";
add a comment |
This $callbackURL should work in the sample above.
$callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";
This $callbackURL should work in the sample above.
$callbackUrl = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . "$_SERVER['HTTP_HOST']/$_SERVER['REQUEST_URI']";
answered Nov 1 '17 at 15:33
David St.AmourDavid St.Amour
1
1
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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