如何在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

drasv0904
drasv0904 我不知道API,但我想你应该尝试发送一个fieldName参数作为发布数据。您应该有一个API文档,检测到哪些paremerts。
大约 3 年之前 回复

2个回答



而不是
$ ch = curl_init(“ https://www.experian-ccmp.com/rest/V1/products ”); </ p>

试试这个 获取所有产品列表</ p>

$ ch = curl_init(“ https://www.experian-ccmp.com/rest/V1/products?searchCriteria= ”); </ p>

希望这会有所帮助!</ p>

</ div>

展开原文

原文

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!



您的网址正常。</ p>

仅更改:</ p>

< pre> $ ch = curl_init(“https://www.experian-ccmp.com/rest/V1/products”);
curl_setopt($ ch,CURLOPT_CUSTOMREQUEST,“POST”); // method
</ code> </ pre>

to:
curl_setopt($ ch,CURLOPT_CUSTOMREQUEST,“ GET </ strong>”); //方法</ p>

检查: http://devdocs.magento.com / swagger / </ p>
</ div>

展开原文

原文

Your URL are ok.

Only change:

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

to: curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // method

Check: http://devdocs.magento.com/swagger/

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐