header

Magento 1.x Software Support Notice

For Magento Commerce 1, Magento is providing software support through June 2020. Depending on your Magento Commerce 1 version, software support may include both quality fixes and security patches. Please review our Magento Software Lifecycle Policy to see how your version of Magento Commerce 1 is supported.

For Magento Open Source 1.5 to 1.9, Magento is providing software security patches through June 2020 to ensure those sites remain secure and compliant. Visit our information page for more details about our software maintenance policy and other considerations for your business.

Add Option

Edit this page on GitHub

Module: Product Attributes API

Resource: product_attribute

Method:

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

Arguments:

Type Name Description
string sessionId Session ID
string attribute
Attribute code or ID
array data Array of catalogProductAttributeOptionEntityToAdd

Return:

Type Name Description
boolean result True on success

The catalogProductAttributeOptionEntityToAdd content is as follows:

Type Name Description
array label Array of catalogProductAttributeOptionLabel
int order Option order
int is_default Defines whether the option is a default one

The catalogProductAttributeOptionLabel content is as follows:

Type Name Description
ArrayOfString store_id
Array of store view IDs
string value
Text label

Faults:

Fault Code Fault Message
101 Requested attribute not found.
104 Incorrect attribute type.
108 Unable 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