API

Example use

curl "http://demo.keitarotds.com/api.php?action=get_link\
&api_key=89185200811a6ebb7c16be09616f2f18\
&group=newcoms\
&ip=217.212.230.137\
&keyword=free+popcorn\
&langs=es\
&referer=http%3A%2F%2Fwww.google.com.my%2Fsearch%3Fq%3D%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Aen-US%3Aofficial%26client%3Dfirefox-a&charset=utf-8\
&ua=Mozilla%2F4.0+(compatible%3B+Mozilla%2F5.0+(Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.7.13)+Gecko%2F20060414%3B+Windows+NT+5.1)"

Answer:

{
  "stream":{
    "id":"1098",
    "group_id":"11"
    "url": "http://google.com",
  },
  redirect: {
    "content": null, 
    "headers": [
        "LOCATION: http://google.com"
    ], 
    "type": "location"
  }
}

Answer format: json.

PHP example

If you use Keitaro 7 or newer, you can get this code on page «Campaign > Additional > Integration Assistant > Other > API».

<?php
$domain = 'domain.com';
$apiKey = '2614374967c4ecce1cc1a406e3d78848';
$id = 'id';
$keyword = urlencode('KEYWORD');
$lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$ua = urlencode($_SERVER['HTTP_USER_AGENT']);
$ip = null;
$headers = array('HTTP_X_FORWARDED_FOR', 'HTTP_CF_CONNECTING_IP', 'HTTP_X_REAL_IP', 'REMOTE_ADDR');
foreach ($headers as $header) {
    if (!empty($_SERVER[$header])) {
        $ip = $_SERVER[$header];
        break;
    }
}
if (strstr($ip, ',')) {
    $tmp = explode(',', $ip);
    if (stristr($_SERVER['HTTP_USER_AGENT'], 'mini')) {
        $ip = trim($tmp[count($tmp) - 2]);
    } else {
        $ip = trim($tmp[0]);
    }
}     
$referrer = urlencode(@$_SERVER['HTTP_REFERER']);
$url = "http://$domain/api.php?charset=utf-8&action=get&api_key=$apiKey&group=$id&ua=$ua&ip=$ip&keyword=$keyword&referrer=$referrer&lang=$lang";
$result = json_decode(@file_get_contents($url));
if ($result->redirect) {
  foreach($result->redirect->headers as $header) {
    header($header);
  }
  if ($result->redirect->content) {
     echo $result->redirect->content;
  }
}
?>

Query parameters

  • api_key — key;
  • dummy_mode — the visitor is not added into statistics if this parameter is active;
  • group — group identifier;
  • ip — user IP;
  • ua — UserAgent;
  • keyword — keyword;
  • referer — referrer;
  • lang — browser language;
  • se_referer — search engine visitor referrer;
  • source — traffic source;
  • charset — keyword encoding;
  • debug — debugging info display

Response

  • stream — stream information. Values inside: id, group_id;
  • stream.id — stream id;
  • stream.group_id — group id;
  • stream.url — stream URL;
  • redirect — information about redirect;
  • redirect.type — redirect type;
  • redirect.headers — redirect headers;
  • redirect.content — page contents if generated by redirect;
  • debug — debugging info;
  • execution_time — script execution time

Why uniqueness by cookies filter is not working?

Cookies are not transmitted through API, that is why it is necessary to use “Uniqueness by IP” filter.

How to call API from command prompt?

Use php-cgi

php-cgi -f /path/api.php action="get" api_key="api_key" campaign="campaign_id" ua="..." ip="..." keyword="..." referrer="..."

Example

php-cgi -f /path/api.php action="get" api_key="f1uh20efuh102euhf01uhef" campaign="123" ua="Mozilla%2F5.0+%28Macintosh%3B+Intel+Mac+OS+X+10_11_2%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F49.0.2618.0+Safari%2F537.36" ip="6.6.6.6" keyword="keyword" referrer="http://referrer"