Reputation: 150
I am using REST to call the Magento product list, but it is only showing 10 products instead of all of them.
Could anyone guide because of what this problem may occur?
This is the code I am using to call the rest api :-
$url = 'magentohost url';
$callbackUrl = $url . "oauth_admin.php";
$temporaryCredentialsRequestUrl = $url . "oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = $url . 'admin/oauth_authorize';
$accessTokenRequestUrl = $url . 'oauth/token';
$apiUrl = $url . 'api/rest';
$consumerKey = 'consumer_key';
$consumerSecret = 'consumer_secret';
$token = 'token';
$secret = 'token_secret';
try {
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, OAUTH_AUTH_TYPE_AUTHORIZATION);
$oauthClient->setToken($token, $secret);
$resourceUrl = "$apiUrl/products";
$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json', 'Accept' => 'application/json'));
$productsList = json_decode($oauthClient->getLastResponse());
echo '<pre>';
print_r($productsList);
}
catch(Exception $e) {
echo '<pre>';
print_r($e);
}
It is giving me proper output, but never more than 10 products, when I want to output all of them.
Upvotes: 1
Views: 5093
Reputation: 3
We can set the default number of product response and maximum number of products.
Go to app/code/core/mage/Api2/Model/Resource.php
Change as per our need.
/**#@+
* Collection page sizes
*/
const PAGE_SIZE_DEFAULT = 10;
const PAGE_SIZE_MAX = 200;
/**#@-*/
Upvotes: 0
Reputation: 1724
I would like to add from the comment above. You should copy app/code/core/mage/Api2/Model/Resource.php to app/code/local/mage/Api2/Model/Resource.php and make your changes in he local file. You should NEVER edit the core Magento files, otherwise, if you upgrade your Magento system, you lose your changes.
Upvotes: 1
Reputation: 66
By Default the limit is 10. You can pass the limit as follows:
You can define the limit of items returned in the response by passing the limit parameter. By default, 10 items are returned and the maximum number is 100 items. You can also define the page number by passing the page parameter. Example:
http://magentohost/api/rest/products?page=2&limit=20
Upvotes: 5