I have created Integration in System->Integration. And Set access to catelog ->products to the integration. I can get Single Product by Sku using
But i need to display all the products. How to get the result.
Thanks in advance.
My Code to get product details
function sign($method, $url, $data, $consumerSecret, $tokenSecret)
{
$url = urlEncodeAsZend($url);
$data = urlEncodeAsZend(http_build_query($data, '', '&'));
$data = implode('&', [$method, $url, $data]);
$secret = implode('&', [$consumerSecret, $tokenSecret]);
return base64_encode(hash_hmac('sha1', $data, $secret, true));
}
function urlEncodeAsZend($value)
{
$encoded = rawurlencode($value);
$encoded = str_replace('%7E', '~', $encoded);
return $encoded;
}
// REPLACE WITH YOUR ACTUAL DATA OBTAINED WHILE CREATING NEW INTEGRATION
$consumerKey = 'key';
$consumerSecret = 'key';
$accessToken = 'key';
$accessTokenSecret = 'key';
$method = 'GET';
$url = 'http://localhost.com/index.php/rest/V1/products';
//
$data = [
'oauth_consumer_key' => $consumerKey,
'oauth_nonce' => md5(uniqid(rand(), true)),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => time(),
'oauth_token' => $accessToken,
'oauth_version' => '1.0',
];
$data['oauth_signature'] = sign($method, $url, $data, $consumerSecret, $accessTokenSecret);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => [
'Authorization: OAuth ' . http_build_query($data, '', ',')
]
]);
$result = curl_exec($curl);
curl_close($curl);
echo '<pre>';print_r(json_decode($result));
But it returns error
[message] => %fieldName is a required field.
[parameters] => stdClass Object
(
[fieldName] => searchCriteria
)
Best Answer
First get admin token,
You can make use of below code, If you have many products increase the page_size.