как показать продукты JSON в API

Я застрял в проблеме, я не могу получить продукты JSON в magento2? Может ли кто-нибудь решить мою проблему, я получаю токен успешно, но не могу получить продукты json в php

Вот мой следующий код PHP

<?php
$userData = ["username" => "admin", "password" => "admin_password"];

$ch = curl_init("https://www.experian-ccmp.com/rest/V1/integration/admin/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

$token = curl_exec($ch);

$ch = curl_init("https://www.experian-ccmp.com/rest/V1/products");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); //  method
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($emailcontent));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
$result = curl_exec($ch);
echo $result;
die;
$result = json_decode($result, 1);
echo '<pre>';print_r($result);
?>

вот что я получаю ответ в json, имя поля обязательно

{"message":"%fieldName is a required field.","parameters":{"fieldName":"product"},"trace":"#0 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/framework\/Webapi\/ServiceInputProcessor.php(131): Magento\\Framework\\Webapi\\ServiceInputProcessor->processInputError(Array)\n#1 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/module-webapi\/Controller\/Rest\/InputParamsResolver.php(101): Magento\\Framework\\Webapi\\ServiceInputProcessor->process('Magento\\\\Catalog...', 'save', Array)\n#2 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/module-webapi\/Controller\/Rest.php(299): Magento\\Webapi\\Controller\\Rest\\InputParamsResolver->resolve()\n#3 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/module-webapi\/Controller\/Rest.php(216): Magento\\Webapi\\Controller\\Rest->processApiRequest()\n#4 \/home2\/bhagnani\/public_html\/experian-ccmp\/var\/generation\/Magento\/Webapi\/Controller\/Rest\/Interceptor.php(37): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#5 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/framework\/App\/Http.php(135): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#6 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/framework\/App\/Bootstrap.php(258): Magento\\Framework\\App\\Http->launch()\n#7 \/home2\/bhagnani\/public_html\/experian-ccmp\/index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http))\n#8 {main}"}

Спасибо за комментарии заранее

1

Решение

Вместо
$ ch = curl_init («https://www.experian-ccmp.com/rest/V1/products«);

Попробуйте это, чтобы получить весь список продуктов

$ ch = curl_init («https://www.experian-ccmp.com/rest/V1/products?searchCriteria=«);

Надеюсь это поможет!

0

Другие решения

Ваш URL в порядке.

Только изменить:

$ch = curl_init("https://www.experian-ccmp.com/rest/V1/products");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); //  method

чтобы:
curl_setopt ($ ch, CURLOPT_CUSTOMREQUEST, «ПОЛУЧИТЬ«); // метод

Проверьте: http://devdocs.magento.com/swagger/

0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector