Use the Lead Commerce Customer API to view, create, and update customers.
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, '<a href="http://leadcommercestore.web/api/v1/Customers.xml')">http://leadcommercestore.web/api/v1/Customers.xml'...</a>; curl_exec($curl); curl_close($curl); ?>
Example Output:
<message client="192.168.100.208" time="1395344348"> <response> <code>200</code> <data> <item> <id>1061</id> <name>Tom Jones</name> <first>Tom</first> <last>Jones</last> <email>[email protected]</email> <phone>310-555-1212</phone> <fax/> <customer_type>1</customer_type> <username>[email protected]</username> <company_id>17</company_id> <company_name>Jones Co, Inc.</company_name> <created>2/19/2013 7:17PM</created> <last_updated>2/19/2013 7:17PM</last_updated> <status>Active</status> <attributes> <attribute> <id>14</id> <name>How did you hear about us?</name> <display_name>How did you hear about us?</display_name> <slug>attr_how_did_you_hear_about_us</slug> <value>Google search</value> </attribute> </attributes> <addresses> <address> <id>126</id> <full_name>Tom Jones</full_name> <address_1>5000 Parkway Avenue</address_1> <address_2/> <city>Los Angeles</city> <subregion>3684</subregion> <postal_code>90210</postal_code> <region>840</region> <phone>310-555-1212</phone> <biz_name/> <default_billing>Y</default_billing> <default_shipping>Y</default_shipping> <status>Active</status> </address> </addresses> </item> </data> </response> </message>
Create allows you to create Customers as if you went through the Lead Commerce Back Office and includes automatic ID creation. Refer to the Data Points table below to learn which data points can be passed when creating Customers.
This sample Create Customer code shows how you would insert a Customer along with their billing and shipping addresses into the database.
Example:
$insert = array('first' => 'Leonardo', 'last' => 'DeCappuccino', 'email' => '[email protected]', 'phone' => '619-555-1212', 'fax' => '619-555-1123', 'company' => 'Coffee Shop Company', 'addresses' => array('address1' => array('full_name' => 'Leo DeCappuccino', 'address_1' => '5000 Parkway Avenue', 'city' => 'Los Angeles', 'subregion' => 'California', 'postal_code' => '90210', 'phone' => '310-555-6789', 'default_billing' => 1), 'address2' => array('full_name' => 'Leo DeCappuccino', 'address_1' => '7000 Parkway Avenue', 'address_2' => '#414', 'city' => 'Los Angeles', 'subregion' => 'California', 'postal_code' => '90210', 'phone' => '310-555-4015', 'default_shipping' => 1) ) ); $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, '<a href="http://leadcommercestore.web/api/v1/Customers/create.xml')">http://leadcommercestore.web/api/v1/Customers/crea...</a>; curl_exec($curl); curl_close($curl);
Key | Data Type | Required | Example | Notes |
---|---|---|---|---|
first | string | Yes | Tom | Customer first name |
last | string | Yes | Smith | Customer last name |
string | Yes | [email protected] | ||
phone | string | No | 310-555-1212 | Customer primary phone number |
fax | string | No | 310-555-1234 | Customer primary fax number |
company | string | No | Coffee Shop, Co. | Tie customer to company (Note: if the company doesn't exist, it'll be created) |
customer_type | int | No | Customer Type. Defaults to 1 if not set. | |
lead | Boolean | No | Is this a lead or customer. Pass true, false, yes or no. Defaults to false. | |
addresses | array | No | Array containing an additional array of each address. See below for data points |
Key | Data Type | Required | Example | Notes |
---|---|---|---|---|
full_name | string | Yes | Tom Smith | Customer full name for shipping |
status | int/string | No | 1 ( or 'Active') | Set address status, default to active if not set |
address_1 | string | Yes | 5000 Parkway Ave. | Customer street address |
address_2 | string | No | #423 | Unit/Apartment Number |
city | string | Yes | Los Angeles | |
subregion | string | Yes | CA | Customer state (abbr) |
postal_code | string | Yes | 90210 | |
region | string | Yes | United States | Customer country |
phone | string | No | 310-555-9876 | |
default_billing | int | No | 1 | Set address as default billing address |
default_shiping | int | No | 1 | Set address as default shipping address |
Update allows you to update Customers as if you went through the Lead Commerce Back Office. When updating a customer, you are NOT required to pass all fields; passing a blank or empty field will update the field value as blank.
Running the sample update code below for Customer ID 55 would update this customers first name as well as their phone number. This example will also set the default billing address to also be the default shipping address and then set the old address to inactive.
Example:
<!--?php $update = array('id' =--> 55, 'first' => 'Leo', 'phone' => '310-555-3322', 'address' => array(array('id' => 1, 'default_shipping' => 1), array('id' => 2, 'status' => 'inactive'))); $fields = array('identifier' => "LC350000000", 'key' => "dynKSr4I7y2K3RrPRsFYFJr03IXUbv", 'inserts' => 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, '<a href="http://leadcommercestore.web/api/v1/Customers/update.xml')">http://leadcommercestore.web/api/v1/Customers/upda...</a>; curl_exec($curl); curl_close($curl); ?>
Refer to the Data Points table above to update your Customers. The only difference is described below:
Key | Data Type | Required | Example | Notes |
---|---|---|---|---|
id | int | Yes | 55 | ID of the Customer |