<img height="1" width="1" alt="" style="display:none" src="https://www.facebook.com/tr?id=799187456795375&amp;ev=PixelInitialized">

Copy ‘n’ Paste Code Snippets

The Personalization API is easy to implement in a variety of languages. The code snippets below use the libraries on our GitHub Page to query our API and output the results. For more details, please consult each library's accompanying README docs.

Ruby | Python | PHP | Java | Perl | C#


This snippit requires the towerdata_api gem (gem install towerdata_api).


require 'towerdata_api'
  api = TowerDataApi::Api.new("API_KEY") # Set API key here
  hash = api.query_by_email("personalize@rapleaf.com")
  puts hash.inspect
rescue Exception => e
  puts e.message

back to top


This snippit requires the towerdata_Api python module, which depends on the urllib3 module. (pip install towerDataApi).


from towerDataApi import TowerDataApi
api = TowerDataApi.TowerDataApi('API_KEY')
  response = api.query_by_email('personalize@rapleaf.com')
  for k, v in response.iteritems():
    print '%s = %s' % (k, v)
except Exception as e:
  print e

back to top


This snippit requires the TowerData API library for PHP5. Make sure to set your API key at the top of TowerDataApi.php. (Not on PHP5? Check out our devkit for older versions of PHP.)


namespace TowerData;
include "TowerDataApi.php";

$person = $argv[1];
$response = query_by_email($person, false);

back to top


This snippit relies on the towerdata-api-complete jar, which you can find in TowerData's Java devkit on GitHub.


import org.json.JSONObject;
import com.towerdata.api.personalization.TowerDataApi;

public class TowerDataApiExample {
  public static void main(String[] args) {
    TowerDataApi api = (args[0] != null) ? new TowerDataApi(args[0]):new TowerDataApi("YOUR_KEY"); // Set API key here
final String email = (args[1] != null) ? args[1]:"personalize@rapleaf.com";

// Query by email try { JSONObject response = api.queryByEmail(email, true); System.out.println("Query by email: \n" + response); } catch (Exception e) { e.printStackTrace(); } } }

back to top


This snippit requires the TowerData API library for Perl, which depends on the JSON module (perl -MCPAN -e 'install JSON'). Make sure to set your API key at the top of TowerDataAPI.pm.


use 'TowerDataAPI.pm';
eval {
  my $response = query_by_email('pete@rapleafdemo.com');
  while(my ($k, $v) = each %$response) {
      print "$k = $v.\n";
if ($@) {
  print $@

back to top


This snippit relies on the TowerDataApi dll, which you can find in TowerData's C♯ devkit on GitHub.


using System.Collections.Generic;
using System;
using System.Net;
using Personalization;

namespace example
    class TowerDataExample
        // outlined below are three separate ways of querying the API using the TowerDataApi library
        public static void Main(string[] args)
            TowerDataApi api = (args.Length >= 1 && args[0] != null) ? new TowerDataApi(args[0]) : new TowerDataApi("YOUR_API_KEY");
            String email = (args.Length >= 2 && args[1] != null) ? args[1] : "pete@rapleafdemo.com";

            // Query by email
            Console.WriteLine("\nQuery by email: "+email+"\n");
                Dictionary<string, object=""> response = api.queryByEmail(email);
                foreach (KeyValuePair<string, object=""> kvp in response)
            catch (WebException e)

        private static void printKeyValuePair(KeyValuePair<string, object=""> kvp)
            if (kvp.Value is Dictionary<string, object="">)
                Console.WriteLine("--" + kvp.Key + "--");
                foreach (KeyValuePair<string, object=""> sub_kvp in (Dictionary<string, object="">)kvp.Value)
                Console.WriteLine("--" + kvp.Key + "--");
                Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value);

back to top

1,000 free age and gender queries. Get API Key