曾经试图弄清楚这里发生了什么,但是被卡住了。任何人都知道发生了什么事。
使用Magento 2.2.4
( ! ) Fatal error: Uncaught TypeError: Argument 1 passed to Magento\Catalog\Model\ProductRepository\Interceptor::getList() must be an instance of Magento\Framework\Api\SearchCriteriaInterface, string given in C:\wamp64\www\magento2\generated\code\Magento\Catalog\Model\ProductRepository\Interceptor.php on line 85
( ! ) TypeError: Argument 1 passed to Magento\Catalog\Model\ProductRepository\Interceptor::getList() must be an instance of Magento\Framework\Api\SearchCriteriaInterface, string given in C:\wamp64\www\magento2\generated\code\Magento\Catalog\Model\ProductRepository\Interceptor.php on line 85
我尝试执行的代码:
set_time_limit(0);
define('TOKEN', 'token code');
define('URL', 'http://localhost:8080/magento2/index.php');
$headers = array("Authorization: Bearer ". TOKEN);
//API URL to get all Magento 2 modules
$requestUrl = (URL . "/rest/V1/products?searchCriteria=");
$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
print_r($result);
答案 0 :(得分:1)
您需要在请求API时通过搜索条件。尝试下面的代码。
set_time_limit(0);
define('TOKEN', 'token code');
define('URL', 'http://localhost:8080/magento2/index.php');
$headers = array("Authorization: Bearer ". TOKEN);
//API URL to get all Magento 2 modules
$requestUrl = (URL . "/rest/V1/products/?searchCriteria[filter_groups][0][filters][0][field]=category_gear&searchCriteria[filter_groups][0][filters][0][value]=86&searchCriteria[filter_groups][0][filters][0][condition_type]=finset");
$ch = curl_init($requestUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
print_r($result);