--- layout: m1x_soap title: Assign Product ---
The Mage_Catalog module allows you to manage categories and products.
Aliases:
Assign a product to the required category.
Aliases:
Arguments:
| Type | Name | Description |
|---|---|---|
| string | sessionId | Session ID |
| int | categoryId | ID of the category |
| string | product/productId | ID or SKU of the product to be assigned to the category |
| string | position | Position of the assigned product in the category (optional) |
| string | identifierType | Defines whether the product ID or SKU is passed in the 'product' argument |
Returns:
| Type | Description |
|---|---|
| boolean | True if the product is assigned to the specified category |
$client = new SoapClient('http://magentohost/api/soap/?wsdl');
// If somestuff requires api authentification,
// then get a session token
$session = $client->login('apiUser', 'apiKey');
$result = $client->call($session, 'catalog_category.assignProduct', array('categoryId' => '4', 'product' => '1'));
var_dump($result);
// If you don't need the session anymore
//$client->endSession($session);
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl'); // TODO : change url
$sessionId = $proxy->login('apiUser', 'apiKey'); // TODO : change login and pwd if necessary
$result = $proxy->catalogCategoryAssignProduct($sessionId, '4', '3');
var_dump($result);
$proxy = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$sessionId = $proxy->login((object)array('username' => 'apiUser', 'apiKey' => 'apiKey'));
$result = $proxy->catalogCategoryAssignProduct((object)array('sessionId' => $sessionId->result, 'categoryId' => '5', 'productId' => '1', 'position' => '5'));
var_dump($result->result);