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