<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 'rapleaf_api'
  api = RapleafApi::Api.new("API_KEY") # Set API key here
  hash = api.query_by_email("test@example.com")
  puts hash.inspect
rescue Exception => e
  puts e.message

back to top


This snippit requires the rapleafApi python module, which depends on the urllib3 module. (easy_install urllib3 rapleafApi).


from rapleafApi import RapleafApi
api = RapleafApi.RapleafApi('API_KEY')
  response = api.query_by_email('test@example.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 RapleafApi library for PHP5. Make sure to set your API key at the top of RapleafApi.php. (Not on PHP5? Check out our devkit for older versions of PHP.)


  namespace Rapleaf;
  include "RapleafApi.php";
  $api = new RapleafApi(YOUR_RAPLEAF_API_KEY);
  try {
    $response = $api -> query_by_email('test@example.com', 
                                       $hash_email = true);
    foreach ($response as $key => $value) {
     echo $key . " = " . $value . "n";
  } catch (Exception $e) {
    echo 'Caught exception: ' .  $e->getMessage() . "n";

back to top


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


import org.json.JSONObject;
import com.rapleaf.api.personalization.RapleafApi;

public class Test {
  public static void main(String[] args) {
    RapleafApi api = new RapleafApi("API_KEY"); // Set API key here
    try {
      JSONObject response = api.queryByEmail("test@example.com", 
    } catch (Exception e) {

back to top


This snippit requires the RapleafApi 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 RapleafApi.pl.


do 'RapleafApi.pl';
eval {
  my $response = query_by_email('test@example.com');
  while(my ($k, $v) = each %$response) {
      print "$k = $v.n";
if ($@) {
  print $@

back to top


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


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using personalization;

namespace MyApplication {
  class RapleafExample {
    public static void Main(string[] args) {
      RapleafApi api = new RapleafApi("SET_ME"); // Set API key here
      try {
        Dictionary<string, string=""> response = api.queryByEmail("test@example.com",
        foreach (KeyValuePair<string, object=""> kvp in response) {
          Console.WriteLine("{0}: {1}", kvp.Key, kvp.Value);
      catch (System.Net.WebException e) {

back to top

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