how to make request to get all products using REST API. I'm integrating salesforce - magento through apex controller. please tell me how construct the request.

  • I am using below way to get all products of the website. Upvote the answer if this is useful to you.
    – Mahendra
    Aug 28, 2018 at 18:23

1 Answer 1

use Magento\Framework\App\Bootstrap;
$rootDirectory = $_SERVER['DOCUMENT_ROOT']; 
require $rootDirectory . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $_SERVER); 
$objectManager = $bootstrap->getObjectManager(); 
$storeManager = $objectManager->get('Magento\Store\Model\StoreManagerInterface'); 
$baseUrl= (string)$storeManager->getStore()->getBaseUrl();
$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');

$collection = $productCollection->create()
            ->addAttributeToFilter('status', '1')

 $appState = $objectManager->get('\Magento\Framework\App\State');

foreach ($collection as $product){
    $result[] = array(
        "id" => $product->getId(),
        "name" => $product->getName(),
        "sku" => $product->getSku(),
         "description"=> strip_tags($product->getShortDescription()),
          "small_image" => $mediaurl.'catalog/product'.$product->getImage()


Here you get all product in result array

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.