shylaja
shylaja

Reputation: 115

Magento API call for getting products information

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.com/magento/index.php/api/soap/?wsdl');

The above statement display the below error

Parsing WSDL: Couldn't find definitions in

Upvotes: 3

Views: 4477

Answers (4)

Daniel van der Garde
Daniel van der Garde

Reputation: 234

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

Upvotes: 2

Sergey Kolodyazhnyy
Sergey Kolodyazhnyy

Reputation: 691

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'.

Upvotes: 0

Sangamesh Arali
Sangamesh Arali

Reputation: 123

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.

Upvotes: 0

vsushkov
vsushkov

Reputation: 2435

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:[email protected]/magento/index.php/api/soap/?wsdl

Upvotes: 2

Related Questions