The Lead Commerce Products API allows you to view, create, and update:
Views allow you to display data about your Products.
With the Product API, you can filter your result set to get a particular result set you are looking for. You can use any of the filters in any particular combination.
Filters
Key | Data Type | Required | Example | Notes |
---|---|---|---|---|
status | Integer | No | 1 |
|
id | Integer | No | 5 | The ID of the Product |
product_type | Integer | No | 1 | The ID of the Product Type |
timestamp_start | Integer | No | 1406239561 | UNIX timestamp of the latest time of the product. This means updated or created. |
timestamp_end | Integer | No | 1412200562 | UNIX timestamp of the latest time of the product. This means updated or created. |
price_above | Integer | No | 8 | Price of the product above this watermark. |
price_below | Integer | No | 100 | Price of the product below this watermark. |
The sample code below demonstrates how to request a view in XML:
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/Products.xml'); curl_exec($curl); curl_close($curl); ?>
Example Output:
<?xml version="1.0" encoding="UTF-8"?> <message client="192.168.100.208" time="1398210504"> <response> <code>200</code> <data> <item> <id>1</id> <name>Basic T-Shirt</name> <display_name>Basic T-Shirt</display_name> <cost>8.95</cost> <price>22.99</price> <seo_title>Basic T-Shirt</seo_title> <seo_keyword>Basic, Product, T-Shirt</seo_keyword> <seo_description>This is a sample t-shirt product.</seo_description> <available_on>0</available_on> <url>http://western.goleadcommerce.com/products/basic-t-shirt/</url> <description>This is a sample t-shirt product.</description> <unavailable_after>0</unavailable_after> <tax_code>00000</tax_code> <product_type>1</product_type> <created>4/22/2014 3:16PM</created> <last_updated>4/22/2014 3:16PM</last_updated> <status>Active</status> <categories> <categorie> <id>1</id> <name>Products</name> <display_name>Products</display_name> <slug>products</slug> <values> <value> <id>1</id> <name>Men Shirts</name> <display_name>Shirts</display_name> <directory_structure>/products/</directory_structure> <slug>shirts_men</slug> </value> <value> <id>6</id> <name>Men</name> <display_name>Men</display_name> <directory_structure>/products/</directory_structure> <slug>men</slug> </value> </values> </categorie> <categorie> <id>2</id> <name>Sale Items</name> <display_name>Sale Items</display_name> <slug>sale_items</slug> </categorie> </categories> <vendors> <vendor> <id>1</id> <name>My Vendor</name> </vendor> </vendors> <images> <image> <url>http://western.goleadcommerce.com/flex/assets/images/products/6c/61/1/1/1/tshirt.png</url> <alt_text /> <title /> </image> </images> <product_variations> <product_variation> <id>1</id> <name>Color</name> <display_name>Color</display_name> <values> <value> <id>2</id> <name>Blue</name> </value> <value> <id>1</id> <name>Red</name> </value> <value> <id>5</id> <name>White</name> </value> </values> </product_variation> <product_variation> <id>2</id> <name>Size</name> <display_name>Size</display_name> <values> <value> <id>7</id> <name>S</name> </value> <value> <id>8</id> <name>M</name> </value> <value> <id>9</id> <name>L</name> </value> <value> <id>10</id> <name>XL</name> </value> </values> </product_variation> </product_variations> <inventory_skus> <inventory_sku> <sku>1-0001</sku> </inventory_sku> <inventory_sku> <sku>1-0002</sku> </inventory_sku> <inventory_sku> <sku>1-0003</sku> </inventory_sku> <inventory_sku> <sku>1-0004</sku> </inventory_sku> <inventory_sku> <sku>1-0005</sku> </inventory_sku> <inventory_sku> <sku>1-0006</sku> </inventory_sku> <inventory_sku> <sku>1-0007</sku> </inventory_sku> <inventory_sku> <sku>1-0008</sku> </inventory_sku> <inventory_sku> <sku>1-0009</sku> </inventory_sku> <inventory_sku> <sku>1-0010</sku> </inventory_sku> <inventory_sku> <sku>1-0011</sku> </inventory_sku> <inventory_sku> <sku>1-0012</sku> </inventory_sku> </inventory_skus> </item> </data> </response> </message>
Create allows you to create products and their values as if you went through the Lead Commerce Back Office.
Below is a sample if you wanted to create a new product with 2 subcategories.
Example:
$insert = array("name" => "Basic T-Shirt", "display_name" => "Amazing Basic T-Shirt", "cost" => "19.95", "price" => "34.95", "details" => "This T-Shirt is the softest, most durable you'll ever find.", "length" => "12", "width" => "36", "height" => "8", "weight" => "2.2", "weight_only" => "Y", "ship_alone" => "N", "metatitle" => "New Amazing Basic T-Shirts For Sale", "metatag" => "t-shirt, t-shirts, new t-shirts, amazing t-shirts for sale", "metadesc" => "Shop our Amazing Basic T-Shirts", "terms" => 16, "product_type" => 2, "tax_code" => 00000, "available_on" => "8/26/2013", "unavailable_after" => "9/30/2013", "status" => "active", "vendors" => array(1, 3), "images" => array("image_url"=>array('http://[[yourdomainpath.com]]/uploads/jumbo1.jpg','http://[[yourdomainpath.com]]/uploads/A-Retail.jpg'), array("image_title"=>array('Title for jumbo1.jpg','Title for A-Retail.jpg'), array("image_alt"=>array('Alt Text for jumbo1.jpg','Alt Text for A-Retail.jpg'), ), "variations" => array(array(4, array(16, 17)), array(5, array(8, 9, 11)))); $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://www.leadcommercestore.com/api/v1/Products/create.xml'); curl_exec($curl); curl_close($curl); ?>
Key | Data Type | Required | Example | Notes |
---|---|---|---|---|
name |
string |
Yes |
Basic T-Shirt |
|
display_name |
string |
No |
Amazing Basic T-Shirt |
|
display_id |
string |
No |
X4545RL0-998 |
Only available if Custom SKU is enabled. This must be a unique string. |
status |
string |
No |
Active |
Active by default |
cost |
decimal |
Yes |
19.95 |
Enter amount in US Dollars |
price |
decimal |
Yes |
34.95 |
Enter amount in US Dollars |
product_type |
int |
Yes |
2 |
ID from Product Types |
terms |
int |
No |
16 |
ID from Terms & Conditions |
details |
text |
No |
This T-Shirt is the softest, most durable you'll ever find. |
|
attributes |
|
|
|
Please review Attributes API documentation |
weight_only |
boolean |
No |
Y |
|
ship_alone |
boolean |
No |
N |
|
length |
int |
No |
12 |
Enter in Inches (in) |
width |
int |
No |
36 |
Enter in Inches (in) |
height |
int |
No |
8 |
Enter in Inches (in) |
weight |
decimal |
Yes |
2.2 |
Enter in Pounds (lbs) |
vendors |
array |
No |
1081, 605, 984 |
ID from Vendors |
seo_title |
string |
No |
New Amazing Basic T-Shirts For Sale |
|
seo_keyword |
string |
No |
t-shirt, t-shirts, new t-shirts, amazing t-shirts for sale |
|
seo_description |
string |
No |
Shop our Amazing Basic T-Shirts |
|
url |
string |
No |
products/wires/11254/x56t.html |
|
available_on |
date |
No |
8/26/2013 |
|
unavailable_after |
date |
No |
9/30/2013 |
|
tax_code |
int |
No |
00000 |
The default value is '00000 (Generic Product/Service)' - please refer to Downloads for additional Tax Codes |
bulk_pricing |
int |
No |
1 |
The ID from Bulk Pricing |
variations |
array |
No |
4, array(16,17), 5, array(8,10,11) |
Variation IDs followed by Variation values in an array (e.g. 4 could be 'Size' and 16 could be 'Medium') |
cat |
array |
No |
array(16,17) |
This is the category id. This field is required for subcategories |
subcat |
array |
No |
array(18,85,47,65,12) |
This is the subcategory id |
images |
array |
No |
See sample code in create |
This is the images for the product. Only image_url is required. (image_url,image_title,image_alt. If you wish to delete all the images tied to a product, specify the word "delete" for the url. |
Update allows you to update Products as if you went through the Lead Commerce Back Office. When updating a Product, you are NOT required to pass all fields; passing a blank will update the field as blank.
This API DOES NOT allow you to update Inventory Levels or SKUs. To update your Inventory, refer to our Stock Levels API. To update your SKUs, refer to our SKUs API.
The sample code below demonstrates how you would update the Name, Tax Code, Unavailable After date, and Product Description of the Product assigned to ID 1001.
Example:
<?php $update = array('id' => '1001', 'name' => 'Updated Graphic T-Shirt', 'tax_code' => '20060', 'unavailable_after' => '10/30/2013', 'details' => 'This is the updated description of the product.'); $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://www.leadcommercestore.com/api/v1/Products/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 |
related | array | No | array(1554,2214,4474) | ID of the related product |