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

Magento Forum

Problem of running my first program using magento api
Mohammad Akram Ali
Jr. Member
Total Posts:  3
Joined:  2008-12-03


I am new in magento and try to import categories using magento api but could not run my first program. Can some one help me to run my first program. I am very thankful to him. The problem in line one, I think i could not add the soap client correctly. Please Help me!

my site address is:

here is the code:


$client = new SoapClient('');

// If soap isn't default use this link instead

// http://youmagentohost/api/soap/?wsdl

// If somestuff requires api authentification,

// we should get session token

$session = $client->login('apiUser', 'apiKey');

$result = $client->call($session, 'somestuff.method');

$result = $client->call($session, 'somestuff.method', 'arg1');

$result = $client->call($session, 'somestuff.method', array('arg1', 'arg2', 'arg3'));

$result = $client->multiCall($session, array(


array('somestuff.method', 'arg1'),

array('somestuff.method', array('arg1', 'arg2'))


function getSomeRandomCategory(&$categories, $targetLevel, $currentLevel = 0) {

if (count($categories)==0) {

return false;


if ($targetLevel == $currentLevel) {

return $categories[rand(0, count($categories)-1)];

} else {

return getSomeRandomCategory($categories[rand(0, count($categories)-1)]['children'], $targetLevel + 1);



$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');

$sessionId = $proxy->login('apiUser', 'apiKey');

$allCategories = $proxy->call($sessionId, 'category.tree'); // Get all categories.

// select random category from tree

while (($selectedCategory = getSomeRandomCategory($allCategories, 3)) === false) {}

// create new category

$newCategoryId = $proxy->call(





array('name'=>'New Category Through Soap')



$newData = array('is_active'=>1);

// update created category on German store view

$proxy->call($sessionId, 'category.update', array($newCategoryId, $newData, 'german'));

$firstLevel = $proxy->call($sessionId, 'category.level', array(null, 'german', $selectedCategory['category_id']));


// If you wish remove category, uncomment next line

//$proxy->call($sessionId, 'category.remove', $newCategoryId);


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