Cartloom does a lot of things to help you manage your online shopping cart, but sometimes you need it to do something special and unique to your business. For this reason we have put together a powerful and elegant RESTful API for our users to use. Our API is very flexible and can return data in a number of formats. The Cartloom API provides an interface allowing you to access and perform actions in Cartloom from external applications and scripts.
What you will need
- General programming knowledge in preferred script language ( i.e. PHP, Ruby, Objective-C, etc…) of choice.
- You will need to include your API key with each request. The best way is to use it as a HTTP HEADER, but it can be sent as an Argument as well. The name of the header ( or argument ) needs to be X-API-KEY. Your API Key found under Tools -> RESTful API Settings in Seller Admin.
That's it, that is all you need to start using our API.
API URL Structure
All API requests will formated as seen below, replacing CARTNAME with your unique Cartloom cart name.
https://CARTNAME.cartloom.com/api/orders/list
Optional Parameters
To narrow down your search you will want to use the following parameters…
- start_date ( YYY-MM-DD )
- end_date ( YYY-MM-DD )
- search_type ( email or last_name )
- keyword ( value needed for search_type )
Response Formats
By default the output is returned as JSON. You can change the format by adding the following to the end of the URL…
format/htmlThe available formats are…
- xml
- json
- serialize
- php ( raw output that can be used in eval )
- html
- csv
So , for example, if you wanted the output as XML, then you would use the following URL…
https://CARTNAME.cartloom.com/api/orders/list/format/xml
Commands
Example
<?php $api_key = 'your-api-key-goes-here'; // cartloom api key (required) $cart_name = 'yourcartname'; // cartloom cart name $params = array('start_date' => '2012-11-1', 'end_date' =>'2012-11-7', 'search_type' => 'email', 'keyword' => 'johnqcustomer@example.com'); $action = 'orders/list'; $result = request($action, $params, 'POST', 'xml'); echo "All My Orders (xml):<br><pre>"; print_r($result); echo "</pre>"; private function request($action, $args = null , $method = 'GET', $format = 'json') { global $api_key, $cart_name; $url = 'https://'.$cart_name.'.cartloom.com/api/'.$action.'/format/'.$format; $headers = array('X-API-KEY:'.$api_key); // set the API Key as header $query_string = ''; if($args) foreach ($args as $k=>$v) $query_string .= "$k=".urlencode($v)."&"; if (function_exists('curl_init')) { $ch = curl_init(); //curl_setopt($ch, CURLOPT_USERPWD, $this->_username . ':' . $this->_password); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, false); // do not return header curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $rs = curl_exec($ch); if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch)); curl_close($ch); unset($ch); } else { $query_string = $args['data']; $rs = `/usr/bin/curl -d "$query_string" $url`; } return $rs; }
Comments
0 comments
Article is closed for comments.