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

Module: Product Attributes API

Resource: product_attribute

Method:
  • product_attribute.create (SOAP V1)
  • catalogProductAttributeCreate (SOAP V2)

Allows you to create a new product attribute.

Arguments:

TypeNameDescription
stringsessionIdSession ID
arraydataArray of catalogProductAttributeEntityToCreate

Returns:

TypeNameDescription
intresultID of the created attribute

The catalogProductAttributeEntityToCreate content is as follows:

TypeNameDescription
stringattribute_codeAttribute code
stringfrontend_inputAttribute type
stringscopeAttribute scope. Possible values are as follows: ‘store’, ‘website’, or ‘global’
stringdefault_valueAttribute default value
intis_uniqueDefines whether the attribute is unique
intis_requiredDefines whether the attribute is required
ArrayOfStringapply_toApply to. Empty for “Apply to all” or array of the following possible values: ‘simple’, ‘grouped’, ‘configurable’, ‘virtual’, ‘bundle’, ‘downloadable’, ‘giftcard’
intis_configurableDefines whether the attribute can be used for configurable products
intis_searchableDefines whether the attribute can be used in Quick Search
intis_visible_in_advanced_searchDefines whether the attribute can be used in Advanced Search
intis_comparableDefines whether the attribute can be compared on the frontend
intis_used_for_promo_rulesDefines whether the attribute can be used for promo rules
intis_visible_on_frontDefines whether the attribute is visible on the frontend
intused_in_product_listingDefines whether the attribute can be used in product listing
associativeArrayadditional_fieldsArray of additional fields
arrayfrontend_labelArray of catalogProductAttributeFrontendLabel

The catalogProductAttributeFrontendLabelEntity content is as follows:

TypeNameDescription
stringstore_idStore ID
stringlabelText label

Notes: The “label” value for the “store_id” value set to 0 must be specified. An attribute cannot be created without specifying the label for store_id=0.

The AdditionaFieldsEntity array of additional fields for the text type is as follows:

TypeNameDescription
stringfrontend_classInput Validation for Store Owner. Possible values are as follows: ‘validate-number’ (Decimal Number), ‘validate-digits’ (Integer Number), ‘validate-email’, ‘validate-url’, ‘validate-alpha’ (Letters), ‘validate-alphanum’ (Letters (a-z, A-Z), or Numbers (0-9))
booleanis_html_allowed_on_frontDefines whether the HTML tags are allowed on the frontend
booleanused_for_sort_byDefines whether it is used for sorting in product listing

The AdditionaFieldsEntity array of additional fields for the text area type is as follows:

TypeNameDescription
booleanis_wysiwyg_enabledEnable WYSIWYG flag
booleanis_html_allowed_on_frontDefines whether the HTML tags are allowed on the frontend

The AdditionaFieldsEntity array of additional fields for the date and boolean types is as follows:

TypeNameDescription
booleanused_for_sort_byDefines whether it is used for sorting in product listing

The AdditionaFieldsEntity array of additional fields for the multiselect type is as follows:

TypeNameDescription
booleanis_filterableDefines whether it is used in layered navigation
booleanis_filterable_in_searchDefines whether it is used in search results layered navigation
intpositionPosition

The AdditionaFieldsEntity array of additional fields for the select and price types is as follows:

TypeNameDescription
booleanis_filterableDefines whether it is used in layered navigation
booleanis_filterable_in_searchDefines whether it is used in search results layered navigation
intpositionPosition
booleanused_for_sort_byDefines whether it is used for sorting in product listing

Faults:

Fault CodeFault Message
102Invalid request parameters.
103Attribute code is invalid. Please use only letters (a-z), numbers (0-9) or underscore (_) in this field, first character should be a letter.
104Incorrect attribute type.
105Unable to save attribute.

Examples

Request Example SOAP V1
<?php

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

// If some stuff requires API authentication,
// then get a session token
$session = $client->login('apiUser', 'apiKey');

$attributeToUpdate = array(
    "scope" => "global",
 "default_value" => "100",
    "frontend_input" => "text",
    "is_unique" => 0,
    "is_required" => 0,
    "is_configurable" => 0,
    "is_searchable" => 0,
    "is_visible_in_advanced_search" => 0,
    "used_in_product_listing" => 0,
    "additional_fields" => array(
        "is_filterable" => 1,
        "is_filterable_in_search" => 1,
        "position" => 1,
        "used_for_sort_by" => 1
    ),
    "frontend_label" => array(
        array(
            "store_id" => 0,
            "label" => "Updated attribute"
        )
    )
);


$attributeCode = 'code1';

$result = $client->call($session, 'product_attribute.update', array($attributeCode, $attributeToUpdate));
var_dump ($result);
 
// If you don't need the session anymore
//$client->endSession($session);

?>
Request Example SOAP V2
<?php
//ini_set("soap.wsdl_cache_enabled", 0);

$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;


//v2

$data = array(
   "attribute_code" => "test_attribute",
   "frontend_input" => "text",
   "scope" => "1",
   "default_value" => "1",
   "is_unique" => 0,
   "is_required" => 0,
   "apply_to" => array("simple"),
   "is_configurable" => 0,
   "is_searchable" => 0,
   "is_visible_in_advanced_search" => 0,
   "is_comparable" => 0,
   "is_used_for_promo_rules" => 0,
   "is_visible_on_front" => 0,
   "used_in_product_listing" => 0,
   "additional_fields" => array(),
   "frontend_label" => array(array("store_id" => "0", "label" => "some label"))
  );

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



//V2 WSI
//WSDL WSI Sample is not complete
//$result = $client->catalogProductAttributeCreate(array("sessionId" => $session, "data" => $data));
//$orders = $result->result->complexObjectArray;

echo 'Number of results: ' . count($orders) . '<br/>';
var_dump ($orders);
?>

Create the Magento file system owner