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!

    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题