Error : Rest API for customer return 403 access denied error.
Format : website/rest/api/customer -> 403 access denied error
Magento\Framework\Webapi\Exception::HTTP_FORBIDDEN
-
Are you using POSTMAN ? and which method you're using ?Aditya Shah– Aditya Shah2018年10月16日 07:00:10 +00:00Commented Oct 16, 2018 at 7:00
-
Share your url, url method and please check your token is valid or not.Aditya Shah– Aditya Shah2018年10月16日 07:00:43 +00:00Commented Oct 16, 2018 at 7:00
-
@AdityaShah I just simply enter in url like websitename/api/rest/products not working, in localhost localhost/magento/api/rest/products returns my products in json format.zus– zus2018年10月16日 07:03:32 +00:00Commented Oct 16, 2018 at 7:03
-
@AdityaShah How can i check my token?zus– zus2018年10月16日 07:03:56 +00:00Commented Oct 16, 2018 at 7:03
-
Yeah zus i understand your concern but when url is redirected at 404 it means your url method or url might be wrong, so i need more details :)Aditya Shah– Aditya Shah2018年10月16日 07:04:45 +00:00Commented Oct 16, 2018 at 7:04
2 Answers 2
Error : Rest API for products return 404 page error in Live Site.
Retrieve the list of products for Admin user with OAuth authentication
<?php
/**
* Example of retrieving the products list using Admin account via Magento REST API. OAuth authorization is used
* Preconditions:
* 1. Install php oauth extension
* 2. If you were authorized as a Customer before this step, clear browser cookies for 'yourhost'
* 3. Create at least one product in Magento
* 4. Configure resource permissions for Admin REST user for retrieving all product data for Admin
* 5. Create a Consumer
*/
// $callbackUrl is a path to your file with OAuth authentication example for the Admin user
$callbackUrl = "http://yourhost/oauth_admin.php";
$temporaryCredentialsRequestUrl = "http://yourhost/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://yourhost/admin/oAuth_authorize';
$accessTokenRequestUrl = 'http://yourhost/oauth/token';
$apiUrl = 'http://yourhost/api/rest';
$consumerKey = 'yourconsumerkey';
$consumerSecret = 'yourconsumersecret';
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, array(), 'GET', array('Content-Type' => 'application/json'));
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);
}
} catch (OAuthException $e) {
print_r($e->getMessage());
echo "<br/>";
print_r($e->lastResponse);
}
-
what is the error mean : snag.gy/0i9SUF.jpg?zus– zus2018年10月20日 12:29:45 +00:00Commented Oct 20, 2018 at 12:29
-
1finally get the oauth_token,oauth_token_secret,oauth_callback_confirmed, then what i need to do?zus– zus2018年10月23日 09:51:02 +00:00Commented Oct 23, 2018 at 9:51
Let's clarify a few things.
Accessing
https://www.example.com/api/rest/productsfrom your browser shouldn't return a list of products like your screenshot shows. It should return a 403 with access denied, unless you passed in credentials - it doesn't sound like you did?According to your question, on your live website, you tried
https://www.example.com/api/rest/customerand you're getting a 404, that's because that endpoint doesn't exist. You need to add an s to customers like sohttps://www.example.com/api/rest/customersWhat you're seeing in your browser is not
jsonit'sxml
-
Updated snag.gy/LcnQVP.jpg like customer to customers getting error, can you guide me solve the issue? FYI - localhost/anusthana/api/rest/products return products values.zus– zus2018年10月19日 12:24:16 +00:00Commented Oct 19, 2018 at 12:24
-
There is no issue, unless you are authorized you should not be able to access that URL from a browser. You need to be passing along API credentialsHaim– Haim2018年10月19日 12:25:32 +00:00Commented Oct 19, 2018 at 12:25
-
Also you realize that on your local you are looking for products and on your live you are looking for customersHaim– Haim2018年10月19日 12:26:02 +00:00Commented Oct 19, 2018 at 12:26
-
Yes, you are right. example.com/api/rest/products not return products, how can i pass my credentials? @haimzus– zus2018年10月25日 07:54:30 +00:00Commented Oct 25, 2018 at 7:54