Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Module: Product Attributes API

Resource: product_attribute

Method:
  • product_attribute.addOption (SOAP V1)
  • catalogProductAttributeAddOption (SOAP V2)

Allows you to add a new option for attributes with selectable fields.

Arguments:

TypeNameDescription
stringsessionIdSession ID
stringattributeAttribute code or ID
arraydataArray of catalogProductAttributeOptionEntityToAdd

Return:

TypeNameDescription
booleanresultTrue on success

The catalogProductAttributeOptionEntityToAdd content is as follows:

TypeNameDescription
arraylabelArray of catalogProductAttributeOptionLabel
intorderOption order
intis_defaultDefines whether the option is a default one

The catalogProductAttributeOptionLabel content is as follows:

TypeNameDescription
ArrayOfStringstore_idArray of store view IDs
stringvalueText label

Faults:

Fault CodeFault Message
101Requested attribute not found.
104Incorrect attribute type.
108Unable to add option.

Examples

Request Example SOAP V1
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl');
$sessionId = $proxy->login('apiUser', 'apiKey');

$attributeCode = "new_attribute";
$optionToAdd = array(
    "label" => array(
        array(
            "store_id" => 0,
            "value" => "New Option"
        )
    ),
    "order" => 0,
    "is_default" => 0
);

$result = $proxy->call(
    $sessionId,
    "product_attribute.addOption",
    array(
         $attributeCode,
         $optionToAdd
    )
);
Request Example SOAP V2
<?php
$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

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

// V2 WS-I Mode
//$response = $client->login(array('username' => 'apiUser', 'apiKey' => 'apiKey'));
//$session = $response->result;

$attributeCode = "new_attribute";

//v2

$label = array (
   array(
    "store_id" => array("0"),
    "value" => "some random data"
   )
  );

$data = array(
   "label" => $label,
   "order" => "10",
   "is_default" => "1"
  );

$orders = $client->catalogProductAttributeAddOption($session, $attributeCode, $data); 



//V2 WSI
//WSDL WSI does not describe this method
//$result = $client->catalogProductAttributeAddOption(...);
//$orders = $result->result->complexObjectArray;

var_dump ($orders);
?>

Create the Magento file system owner