I want to create API route which can list/return products data in JSON or XML format.
By creating this endpoint I will be able to fetch the all the products from Magento. Then I will access it on my website. What I tried is below:
public function getMagentoProducts()
{
$productArr = array('' => 'Select Product');
try {
$proxy = new SoapClient('https://shop.mysite.com/soap?wsdl');
$sessionId = $proxy->login(sfConfig::get('app_mgt_api_user'), sfConfig::get('app_mgt_api_key'));
try {
$mgtProducts = $proxy->call($sessionId, 'product.list');
if (count($mgtProducts) > 0) {
foreach ($mgtProducts as $product) {
$productArr[$product['product_id']] = $product['name'];
}
}
return $productArr;
} catch (Exception $e) {
$this->forward404($e->getMessage());
}
} catch (Exception $e) {
$this->forward404($e->getMessage());
}
}
But by running the above code it throws the below error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://shop.mysite.com/soap?wsdl' : failed to load external entity "https://shop.mysite.com/soap?wsdl"
Am I doing something wrong here?
Is there any easy way to fetch products list from Magento2 on my website?