Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Using the web services API
 
hmpierson
Sr. Member
 
Total Posts:  101
Joined:  2008-11-15
 

In the hope of saving someone else a lot of wasted hours, I’ll make two observations about using the web API.

I was having a lot of trouble getting the web services API to work. I started with the code from the Wiki

http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_category

#
$proxy = new SoapClient(’http://magentohost/api/soap/?wsdl’);
#
$sessionId = $proxy->login(’apiUser’, ‘apiKey’);
#
$allCategories = $proxy->call($sessionId, ‘category.tree’); // Get all categories.
#

First of all, my script kept failing with an error about failing to load the wsdl. Reading through the forum, I found some people had luck with:

$proxy = new SoapClient(’http://magentohost/index.php/api/soap/index/wsdl/1’);

in place of the first line. This worked for me as well. However, then I got “Access denied” errors for the login line.

I finally tried going to System | Web Services | Roles in the Admin, and created a role “forweb”.  “I then clicked on “Role Resources,” and changed the drop down from “Custom” to “All.”

I tried to assign the user to the role, but no matter how many times I tried, I couldn’t get it to work. So I finally tried going back to System | Web Services | Users , selected the user I had created earlier (which had been failing on log in), and THEN clicked on “User Role.” This time, “forweb” showed up as a choice. I clicked the radio button, then clicked “Save User.”

When I tried my script again, I was able to login successfully, and var_dump($allCategories); displayed the category structure correctly.

HTH,

Harry

 
Magento Community Magento Community
Magento Community
Magento Community
 
ds1122
Jr. Member
 
Total Posts:  11
Joined:  2008-08-21
 

That works! Thanks a lot! I’ve been trying to make this work for hours.

 
Magento Community Magento Community
Magento Community
Magento Community
 
BlueKai
Member
 
Avatar
Total Posts:  42
Joined:  2008-09-04
Madrid Spain
 

Thank you for this.. I’d also like to add that if you have your directories protected with an .htaccess file, you need to add a login array.

In other words, if when you go to your site you have an ‘authentication required’ dialog box pop up to even see the site, you need to add that username and password to the below array. Then do the apikey as above.

$proxy = new SoapClient("http://magentohost/api/soap/?wsdl", array(’login’ => “ login name “,’password’ => “ your password “));

 
Magento Community Magento Community
Magento Community
Magento Community
 
i92segoa
Jr. Member
 
Total Posts:  1
Joined:  2008-04-01
 

that was really helpfull. You saved me a couple of hours!

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrspeaker
Member
 
Total Posts:  44
Joined:  2009-01-19
 

Is there any trick to getting the API interface to “be available”?

All of the urls I’ve seen relating to api end points are 404ing (i tried the soap ones too):
/api/xmlrpc/
/api/soap/
/api/soap/?wsdl
/api/?wsdl
/index.php/api/soap/index/wsdl/1
/index.php/api/xmlrpc/
/index.php/api/?wsdl

all result in 404s, and return the whole html 404 page to my xmlrpc client.
I’ve added a role (all) and user to the web services config section… is there something I need to do to “turn it on”?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
mrspeaker
Member
 
Total Posts:  44
Joined:  2009-01-19
 

Ahhh, cancel that!  I was getting the 404 because there are multiple websites setup, and i needed to add the store name to the url
eg /magento/store_name/api/xmlrpc

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael Laursen
Member
 
Total Posts:  39
Joined:  2009-08-30
 

Hi there

I still get the error in line 1. Do I need to place the XML in the special folder? I placed it in website/shop/etc

My code looks like this

$proxy = new SoapClient(’http://www.schmeltz.net/shop/index.php/api/soap/index/wsdl/1’);
$sessionId = $proxy->login(’apiUser’, ‘apiKey’);
$allCategories = $proxy->call($sessionId, ‘category.tree’); // Get all categories.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Damodaran P
Jr. Member
 
Total Posts:  27
Joined:  2010-11-09
Kerala
 

This is my code
<?php
$proxy = new SoapClient('http://localhost/magento/index.php/api/soap/?wsdl');
$sessionId = $proxy->login('testapi', 'testapi');
echo "Login ID : $sessionId";
?>

But i am getting the error
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘http://localhost/magento/index.php/api/soap/?wsdl’ : Extra content at the end of the document in C:\Program Files\wamp\www\magento\testAPI.php:11 Stack trace: #0 C:\Program Files\wamp\www\magento\testAPI.php(11): SoapClient->SoapClient(’http://localhos...’) #1 {main} thrown in C:\Program Files\wamp\www\magento\testAPI.php on line 11

Please Help..

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top