Table of Contents

FoxyCart's E-Commerce API

Like any API, FoxyCart's API is for advanced users only. If you're not comfortable with programming, you should probably get familiar with your language of choice first, and never test on a live store. FoxyCart cannot be held responsible for any misuse of the API.

Need to Know

REST Request Format

REST is the simplest request format to use - it's a simple HTTP POST action. GET requests are NOT supported, which cuts down on potential security risks (particularly with regard to how GET requests tend to get logged, cached, stored, and etc.).

Endpoint

The REST Endpoint URL is https:/ /example.foxycart.com/api or https:/ /custom.subdomain.tld/api (spaces added to prevent indexing), depending on what your FoxyCart store URL is set to. All requests need the api_token passed in along with any request. Your API Token is the same as your datafeed encryption key, and can be set in the Advanced tab in your FoxyCart admin.

It is your responsibility to keep this key secure. If a malicious person finds your API key they will have access that they definitely should not have.

REST Response

By default, REST requests will send a response that looks something like this:

<?xml version='1.0' encoding='UTF-8'?>
<foxydata>
	<result>SUCCESS</result>
	<messages>
		<message>Customer Found</message>
	</messages>
	<customer_id>51</customer_id>
	<last_modified_date>2009-02-10 13:16:11</last_modified_date>
	<customer_first_name>brett</customer_first_name>
	<customer_last_name>florio</customer_last_name>
	<customer_company/>
	<customer_address1>555 Mulberry Dr.</customer_address1>
	<customer_address2/>
	<customer_city>Happyville</customer_city>
	<customer_state>CA</customer_state>
	<customer_postal_code>55555</customer_postal_code>
	<customer_country>US</customer_country>
	<customer_phone> </customer_phone>
	<customer_email>example@example.tld</customer_email>
	<shipping_first_name/>
	<shipping_last_name/>
	<shipping_company/>
	<shipping_address1/>
	<shipping_address2/>
	<shipping_city/>
	<shipping_state/>
	<shipping_postal_code/>
	<shipping_country>US</shipping_country>
	<shipping_phone/>
	<customer_password>97fad3230c7bca8cc37515c3de12e509</customer_password>
	<cc_number>xxxxxxxxxxxx1111</cc_number>
	<cc_exp_month>12</cc_exp_month>
	<cc_exp_year>2009</cc_exp_year>
	<shipto_addresses/>
</foxydata>

Request Methods

Customer Records

Methods
Required Fields
Data Retrieval
Notes:

Customer Addresses

Methods
Required Fields

Transactions

Methods
Required Fields
Data Retrieval

Subscriptions

Methods
Required Fields
Data Retrieval

Example

Here's a very rough example of how to use the API using PHP:

$foxy_domain = "myfoxydomain.foxycart.com";
$foxyData = array();
$foxyData["api_token"] = "XXXXX your api / datafeed key here XXXXXX";
$foxyData["api_action"] = "customer_save";
$foxyData["customer_id"] = "12345";
// OR use the email:
//$foxyData["customer_email"] = "customer@example.com";
$foxyData["customer_password"] = "my new password";
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://" . $foxy_domain . "/api");
curl_setopt($ch, CURLOPT_POSTFIELDS, $foxyData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
// If you get SSL errors, you can uncomment the following, or ask your host to add the appropriate CA bundle
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = trim(curl_exec($ch));
 
// The following if block will print any CURL errors you might have
if ($response == false) {
	print "CURL Error: \n" . curl_error($ch);
} else {
	print "Response to customer save of " . $foxyData['customer_email'] . "\n";
	print $response;
}
curl_close($ch);
 
$foxyResponse = simplexml_load_string($response, NULL, LIBXML_NOCDATA);
print "<pre>";
var_dump($foxyResponse);
print "</pre>";

Language Specific Considerations

Ruby on Rails (RoR)

If you have difficulty with httparty or ActiveResource, try putting the POST request in the :body and not the :query.

Using CURL to Test the API

You can always use CURL to test the API. Here is an example command line CURL request:

curl -d "api_token=PUT_YOUR_API_KEY_HERE&api_action=customer_get&customer_email=john.doe@example.com" https://example.foxycart.com/api

You'd obviously need to insert your own values in that call, but it's provided here for reference. Using CURL can be handy if you just want to get a customer ID quickly, or test to ensure data is being returned as expected.