Traffic Truffle API

Connecting to Traffic Truffle is simple with our REST API

Traffic Truffle API

The API provides you access to your business visitors, tags and email notification settings. The REST API is simple to connect to and is available to all account holders with a starter or pro package.

Basic Information

You should send your API requests to https://api.traffictruffle.com and include a “Authorization: Basic” header that is made up of your siteID and token. For example 1:4a903f2acc6c6056d449a2d54a6080d4

To access your token and siteID you should look within the “My Account” menu in your Traffic Truffle account. Your token is shown on the “API Access” page and the siteID can be found on “Manage Sites”. The API response is in JSON format.

API Calls

Visitors

Make a GET request to https://api.traffictruffle.com/visitors and you will get back a list of visitors to your site for today.

If you would like to query for different days or a date range then you can use the optional parameters search_from and search_to. The format of these dates should be YYYY-MM-DD.

e.g. https://api.traffictruffle.com/visitors?search_from=2017-01-01&search_to=2017-01-07

Visitor Details

To get the specific information about a particular visitor then you need to make a GET request to https://api.traffictruffle.com/visitor/:userID: where :userID: is the ID of the user you are interested in. This is returned as part of the visitors call.

Within both the /visitors and /visitor/:userID: calls you will see a tag_id associated with the user.

To update the tag associated with a user you should make a PATCH request to https://api.traffictruffle.com/visitor/:userID: and specify a parameter called tag. This should be the ID number of the tag that you want to set the user to have.

Tags

To get a list of all tags you can assign to your visitors then make a GET request to https://api.traffictruffle.com/tags

Sites

Make a GET request to https://api.traffictruffle.com/sites and you will get back a list of the sites you have access to within your Traffic Truffle account. The response contains a name and an ID per site. You can then use the siteID when making an API call along side your token.

Sample PHP Code

<?php

	// search visitors over a date range
	$out = api('visitors?search_from=2017-02-01&search_to=2017-02-14', 'GET', array() );
	
	// search all visitors from today
	$out = api('visitors', 'GET', array() );
	
	// give me a list of all my sites
	$out = api('sites', 'GET', array() );
	
	// give me a list of all my tags
	$out = api('tags', 'GET', array() );
	
	// give me details about a specific user
	$out = api('visitor/792317', 'GET', array() );
	
	// update the tag for a specific user
	$out = api('visitor/785082', 'PATCH', array('tag' => 1) );
	
	function api($call, $method, $data) {
	
	    $siteID = '1';
	    $token = '4b10a863489c7161a079cb965317de14';
	
	    $url = 'https://api.traffictruffle.com/' . $call;
	    
	    $ch = curl_init(); 
	    curl_setopt($ch, CURLOPT_URL, $url);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    
	    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
	    curl_setopt($ch, CURLOPT_USERPWD, $siteID . ':' . $token);  
	    
	    if($method == 'POST' or $method == 'PATCH') {
	        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data) );         
	    }       
	    
	    $result = curl_exec($ch);
	    curl_close($ch);    
	    
	    return json_decode($result);
	
	}
	
	
	

If you have any questions or comments then get in touch. We are happy to help.