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

SOAP API: category.create creates two duplicate categories
 
kevin123
Jr. Member
 
Total Posts:  27
Joined:  2008-11-04
 

I wrote a script to use the SOAP API to create 1 category, but for some reason I end up with 2 duplicate categories.

Here is my code.

<?php
$proxy 
= new SoapClient('http://domain/api/?wsdl');
$sessionId $proxy->login('username''password');

$newCategoryId $proxy->call(
    
$sessionId,
    
'category.create',
    array(
        
35,
        array(
'name'=>'New Sub-Category Through Soap''is_active' => 1)
    )
);

echo 
$newCategoryId;

This code results in TWO categories being created.

echo $newCategoryId prints out the first created category.

But when I goto the store or admin, there is a duplicate category. (The second duplicate category url key is suffix’d with a “-1").

Anyone ever have this problem? What am I doing wrong?

BTW I am running Magento 1.1.6

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandlive_br
Guru
 
Avatar
Total Posts:  653
Joined:  2008-05-19
Buenos Aires, Argentina
 

Hi keven 123.

I made a test, with a magento implementation that I use like a lab.
I got some categories, one created over the API (called Test con WS) and the other one, using the category administration (called Carteras).

If a made a query to the categories tree, I get this:

Array
(
    
[category_id] => 1
    [parent_id] 
=> 0
    [name] 
=> Root Catalog
    [position] 
=> 1
    [level] 
=> 0
    [children] 
=> Array
        (
            
[0] => Array
                (
                    
[category_id] => 2
                    [parent_id] 
=> 0
                    [name] 
=> Default Category
                    [is_active] 
=> 1
                    [position] 
=> 1
                    [level] 
=> 1
                    [children] 
=> Array
                        (
                            
[0] => Array
                                (
                                    
[category_id] => 3
                                    [parent_id] 
=> 2
                                    [name] 
=> Test con WS
                                    [position] 
=> 1
                                    [level] 
=> 2
                                    [children] 
=> Array
                                        (
                                        )
                                )
                            
[1] => Array
                                (
                                    
[category_id] => 4
                                    [parent_id] 
=> 2
                                    [name] 
=> Carteras
                                    [is_active] 
=> 1
                                    [position] 
=> 2
                                    [level] 
=> 2
                                    [children] 
=> Array
                                        (
                                        )
                                )
                        )
                )
        )
)

Then, I run this code to add a new one (using the API).

<?php
//Url de la conexión
$client = new SoapClient("http://host/index.php/api/?wsdl");
//Login
$session $client->login("user""password");
//Call
$client->call($session"catalog_category.create", array(3,array("name" => "New Sub-Category Through Soap""is_active" => 1)));
//Logout
$client->endSession($session);

And it works.
Mu new query to the category tree shows:

Array
(
    
[category_id] => 1
    [parent_id] 
=> 0
    [name] 
=> Root Catalog
    [position] 
=> 1
    [level] 
=> 0
    [children] 
=> Array
        (
            
[0] => Array
                (
                    
[category_id] => 2
                    [parent_id] 
=> 0
                    [name] 
=> Default Category
                    [is_active] 
=> 1
                    [position] 
=> 1
                    [level] 
=> 1
                    [children] 
=> Array
                        (
                            
[0] => Array
                                (
                                    
[category_id] => 3
                                    [parent_id] 
=> 2
                                    [name] 
=> Test con WS
                                    [position] 
=> 1
                                    [level] 
=> 2
                                    [children] 
=> Array
                                        (
                                            
[0] => Array
                                                (
                                                    
[category_id] => 5
                                                    [parent_id] 
=> 3
                                                    [name] 
=> New Sub-Category Through Soap
                                                    [is_active] 
=> 1
                                                    [position] 
=> 1
                                                    [level] 
=> 3
                                                    [children] 
=> Array
                                                        (
                                                        )
                                                )
                                        )
                                )
                            
[1] => Array
                                (
                                    
[category_id] => 4
                                    [parent_id] 
=> 2
                                    [name] 
=> Carteras
                                    [is_active] 
=> 1
                                    [position] 
=> 2
                                    [level] 
=> 2
                                    [children] 
=> Array
                                        (
                                        )
                                )
                        )
                )
        )
)

This test is working with Magento 1.1.6.

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