One of the lesser-known features of the Canopy Labs platform is a RESTful API that enables you to query customer data aggregated from MailChimp, ExactTarget, Magento, Omniture, and whichever platforms we pull data from for your business.

This API enables you to run queries on any of the customer profiles we’ve built, or data sources that we’ve queried. Today, we’ll show you how to get a customer list using the Canopy Labs API and query a specific profile to get a customer’s activities.

Why would you want to query the Canopy Labs API directly? If you’re planning to customize content on your site, e-mail triggers, or other run other custom marketing campaigns, then this API will let you build to your heart’s content! Here are some examples:

  • Making dynamic offers based on a customer’s past purchases, after they’ve browsed over 10 pages. Query the API to see when a customer last purchased, and provide them with a special discount code as they browse your site.
  • Sending a “welcome back” message when a person visits a second or third time. Use the API to determine whether this is a visitor’s second visit, and provide them with a welcome back message.
  • Sending an e-mail reminder if a customer has not visited your site for 28 days. Remind customers with your latest updates, but only do so if they’re not actively engaging with you.

The examples above represent complex activities that can be managed easily once your business has 360-degree customer profiles. We’ll use the API with Python to query a customer profile and obtain the customer’s activities.

To begin, the code below queries the API for the first 50 customers. The data in response2 will query the customer list for the customers that appear after a certain customer in our customer database. Each response has an after variable that enables you to paginate past the list you’ve seen so far.

import requests
import urllib

api_root = ‘’ # Root URL for the API.
api_key = ‘tbd’; # API key; e-mail your account rep to receive your API key.

response = requests.get(api_root + “/customers”, headers={‘x-api-key’: api_key})
response2 = requests.get(api_root + “/customers”, headers={‘x-api-key’: api_key},
params = {“after”:”customer-id”})

To get a customer’s specific actions, query the /customers/cust-id/actions/ URL where cust-id is the e-mail address or other identifier for a customer:

response_actions = requests.get(api_root + “/customers/cust-id/actions”,
headers={‘x-api-key’: api_key})

You can dynamically query the Canopy Labs API for specific customers as they browse your site, or when you want to send special offers. The response_actions variable above will provide you with all the activity that has been linked to the customer — this is the data Canopy Labs uses for internal product recommendations and other models, but is also available for you to use in any way!

Interested in trying our API? We’re always looking for feedback — please contact us and we’ll get you started!