douba3943 2017-08-14 12:39
浏览 65

如何在api中展示产品json

I am stuck to a problem, I am unable to get the products json in magento2? Can any one solve my problem, I get the token successfully but unable to get the products json in php

Here is my following php code

<?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);
?>

here is what I get the response in json, field name is required

{"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)
#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)
#2 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/module-webapi\/Controller\/Rest.php(299): Magento\\Webapi\\Controller\\Rest\\InputParamsResolver->resolve()
#3 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/module-webapi\/Controller\/Rest.php(216): Magento\\Webapi\\Controller\\Rest->processApiRequest()
#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))
#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))
#6 \/home2\/bhagnani\/public_html\/experian-ccmp\/vendor\/magento\/framework\/App\/Bootstrap.php(258): Magento\\Framework\\App\\Http->launch()
#7 \/home2\/bhagnani\/public_html\/experian-ccmp\/index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http))
#8 {main}"}

Thanks for the comments in advance

  • 写回答

2条回答 默认 最新

  • doulongsha5478 2017-08-15 15:29
    关注

    Instead of $ch = curl_init("https://www.experian-ccmp.com/rest/V1/products");

    Try this to get all product list

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

    Hope this helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)