开发者

Magento API call for getting products information

开发者 https://www.devze.com 2023-03-12 05:18 出处:网络
I used the below code to get products details from a magento store from my localhost $proxy = new SoapClient(\'http://domain.com/magento/index.php/api/soap/?wsdl\');

I used the below code to get products details from a magento store from my localhost

$proxy = new SoapClient('http://domain.com/magento/index.php/api/soap/?wsdl');

$sessionId = $proxy->login('username', 'apikey');
$filters = array(
    'sku' => array('like'=>'test%')
);

$products = $proxy->call($sessionId, 'product.list', array($filters));

var_dump($products);

It works on my localhost machine but not on server. But soap configuration is enabled in server. Below is the error message

" SOAP-ERROR: Parsing WSDL: Couldn't find <definitions> in "

I got corresponding xml file when I used the below URL http://domainname/shoponline/index.php/api/soap/?wsdl

I removed index.php but didn't get any result.

$proxy = new SoapClient('http://domain.c开发者_如何学Pythonom/magento/index.php/api/soap/?wsdl');

The above statement display the below error

Parsing WSDL: Couldn't find definitions in


Looks like the WSDL XML file was not loaded at all. To debug, try to open this file in your browser. I guess it will not be loaded at all and you'll get an error (which will help you to find out what's wrong) or you will be asked to input username and password (basic HTTP auth). In the second case try change your URL from http://domain.com/magento/index.php/api/soap/?wsdl to http://user:pass@domain.com/magento/index.php/api/soap/?wsdl


Make sure you disable developer mode and error reporting in index.php.


Open the "hosts" file from C:\windows\system32\drivers\etc and comment out the line ::1 (like this: # ::1) or remove the line altogether, then save the file.

I've also used this service - http://localhost:81/magento/index.php/api/soap/?wsdl and it works for me.


The SoapClient unable to retrive wsdl definition file which means that routing is not configured correctly or there some external error occurs. But most likely it's a routing problem. The api/[type] rewrite rule is commented in .htaccess, so you need to remove # sign or use api.php directly. To make api.php work directly you need to pass type parameter to api.php to specify which API protocol you would like to use.

For example, for SOAP it will be - http://domain.com/magento/api.php?type=soap&wsdl. You can also use 'soap_v2'.

0

精彩评论

暂无评论...
验证码 换一张
取 消