Hi,
I'm trying to get all products by using catalogProductRepositoryV1 (https://devdocs.magento.com/swagger/#/catalogProductRepositoryV1/catalogProductRepositoryV1GetListGe...
And I don't know how can I get all my products, I used a lot of different 'searchCriteria' combinaison but no one really working. And also, I've more then 50 000 products.
Maybe I should try to get them 1 000 by 1 000 using the pageSize ?
If someone has an idea feel free to post it here !
Thanks!
First get admin token from magento,
$adminUrl='http:www.yurdomain.com/rest/V1/integration/admin/token';
$ch = curl_init();
$data = array("username" => "admin_username", "password" => "admin_password");
$dataString = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($dataString))
);
$token = curl_exec($ch);
$token = json_decode($token);
print_r($token);
curl_close($ch);
You can make use of below code, If you have many products increase the page size.
<?php
$productUrl='http:wwwyourdomain.com/rest/V1/products?searchCriteria[page_size]=20';
$ch = curl_init($productUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Bearer $token"
)
);
$productList = curl_exec($ch);
$err = curl_error($ch);
$products = json_decode($productList);
echo '<pre>';print_r($products );
curl_close($ch);
Try this hope it work!