1

Is there is a built in rest API to get ALL products with a specific attribute_code

ex. this API https://domain.com/index.php/rest/V1/products/:productID returns

..
 <item>
 <attribute_code>featured</attribute_code>
 <value>0</value>
 </item>
..
Khoa Truong
32.5k11 gold badges91 silver badges159 bronze badges
asked Apr 2, 2017 at 16:19

1 Answer 1

1

Should try with Search using REST APIs: http://devdocs.magento.com/guides/v2.1/howdoi/webapi/search-criteria.html

You should try with GET:

http://{magento_host}/rest/V1/products? searchCriteria[filter_groups][0][filters][0][field]=featured& searchCriteria[filter_groups][0][filters][0][value]=0 searchCriteria[filter_groups][0][filters][0][condition_type]=eq

<?php
$userData = ["username" => "admin", "password" => "admin123"];
$ch = curl_init("http://mage215.loc/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("http://mage215.loc/rest/V1/products?
searchCriteria[filter_groups][0][filters][0][field]=featured&
searchCriteria[filter_groups][0][filters][0][value]=0
searchCriteria[filter_groups][0][filters][0][condition_type]=eq");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // 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);
$result = json_decode($result, 1);
echo '<pre>';print_r($result);
answered Apr 3, 2017 at 6:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.