API V1 is no longer in active development. If you are starting a new integration, it is recommended you use API V2

Product Variations

Use the Lead Commerce Product Variation API to view, create, and update product variations.

Views

Display information about your Product Variations including ID, Name, Status, and their values.

Example:

<?php  
header("Content-type: text/xml;");  
$credentials = array('identifier' => 'LC350000000',  
                     'key' => 'dynKSr4I7y2K3RrPRsFYFJr03IXUbv');  
$curl = curl_init();  
curl_setopt($curl,CURLOPT_POSTFIELDS, http_build_query($credentials));  
curl_setopt($curl,CURLOPT_POST, 1);  
curl_setopt($curl, CURLOPT_URL, 'http://leadcommercestore.web/api/v1/ProductOptions.xml');  
curl_exec($curl);  
curl_close($curl);  
?>

Example Output:

<message client="192.168.0.1" time="1377535712">  
    <response>  
        <code>200</code>
        <data>
            <item>
                <id>3</id>
                <name>Available Colors</name>
                <display_name>Available Colors</display_name>
                <required>0</required>
                <created>6/21/2013 7:15PM</created>
                <last_updated>8/24/2013 4:02PM</last_updated>
                <status>Active</status>
                <variations>
                    <variation>
                        <name>Green</name>
                        <cost_type>$</cost_type>
                        <cost>4.50</cost>
                        <price_type>$</price_type>
                        <price>7.99</price>
                        <weight>2.50</weight>
                        <sort>0</sort>
                        <status>Active</status>
                    </variation>
                    <variation>
                        <name>Orange</name>
                        <cost_type>$</cost_type>
                        <cost>0.00</cost>
                        <price_type>$</price_type>
                        <price>0.00</price>
                        <weight>1.68</weight>
                        <sort>0</sort>
                        <status>Active</status>
                    </variation>
                </variations>
            </item>
        </data>
    </response>
</message>

Create

Create allows you to create Product Variations and their values as if you went through the Lead Commerce Back Office. Refer to the Data Points table below to learn which data points can be passed when creating variations.

The sample Create Product Variation code below shows how you would insert a Variation called 'Colors' into the database, add two values to it, and set it to 'Active' Status.

Example:

<?php  
$insert = array('name' => 'Colors',
                'required' => 'yes',
                'variations' => array(array('name' => 'Green',
                                            'weight' => '1.2',
                                            'cost' => '1.29',
                                            'cost_type' => '$',
                                            'price' => '4.99',
                                            'price_type' => '$'),
                                      array('name' => 'Orange',
					    'weight' => '1.2',
                                            'cost' => '1.29',
                                            'cost_type' => '%',
                                            'price' => '4.99',
                                            'price_type' => '$')));

$fields = array('identifier' => 'LC350000000',  
                'key' => 'dynKSr4I7y2K3RrPRsFYFJr03IXUbv',  
                'inserts' => array($insert));  
$curl = curl_init();  
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($fields));  
curl_setopt($curl, CURLOPT_POST, 1);  
curl_setopt($curl, CURLOPT_URL, 'http://leadcommercestore.web/api/v1/ProductOptions/create.xml');  
curl_exec($curl);  
curl_close($curl);
?>

Data Points

Key Data Type Required Example Notes
name string Yes Color
display_name string No Color Name displayed on the website
required string or int No 1 or 'yes'
status string No Active Active by default

Variant Values

These are the values that are assigned to the parent Variation. Along with their name and status, you can specify an additional cost, price, and weight for each option.

Key Data Type Required Example Notes
name string Yes Green
status string or int No 1 or 'active'
weight int No 1.25 Additional weight accrued for this value
cost int No 1.25 Additional cost for this value
cost_type string No $ or % Cost type ($ - flat / % - percentage)
price int No 1.25 Additional price for this value
price_type string No $ or % Price type ($ - flat / % - percentage)

Update

Update allows you to update Product Variations as if you went through the Lead Commerce Back Office. When updating a Variation, you are NOT required to pass all fields; passing a blank will update the field as blank.

Running the sample Update code below for a Product Variation with an ID of 3 would update the Product Variations display name from Colors to Available Colors, update the added weight for the value 'Orange', and add an additional color option of Gray.

Example:

<?php  
$update = array('id' => '3',
                'display_name' => 'Available Colors',
                'variations' => array(array('id' => '13',
                                            'name' => 'Orange',
                                            'weight' => '1.68'),
                                      array('name' => 'Gray',
                                            'weight' => '1.4',
                                            'price' => '7.95',
                                            'price_type' => '$',
                                            'cost' => '2.99',
                                            'cost_type' => '$')));

$fields = array('identifier' => 'LC350000000',  
                'key' => 'dynKSr4I7y2K3RrPRsFYFJr03IXUbv',  
                'updates' => array($update));  
$curl = curl_init();  
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($fields));  
curl_setopt($curl, CURLOPT_POST, 1);  
curl_setopt($curl, CURLOPT_URL, 'http://leadcommercestore.web/api/v1/ProductOptions/update.xml');  
curl_exec($curl);  
curl_close($curl);  
?>

Refer to the Data Points table above to update your Product Variations. The only difference is described below:

Key Data Type Required Example Notes
id int Yes 3 ID of the Product Variation

Start your free, no-risk trial today.