Kontakt PHP API (Pt. 1)

I've been fiddling with these iBeacon compatible transmitters at work and noticed they didn't have a PHP library at the time of writing this. The logical next step was for me to build my own but it's still fairly rough at this stage. To get details of a particular beacon, you would simply do the following:

< ?php*

$url = 'https://api.kontakt.io/beacon?proximity=';
$prox = 'f7826da6-4fa2-4e98-8024-bc5b71e0893e'; // Kontakt UUID
$major = 35896;
$minor = 2222;
$key = 'YVMS1AZhgAEjC1Krg5X5tiI9AhhmpgbP' // Public API Key (use your own if you want to update beacon settings)

$rest = curl_init();
curl_setopt($rest, CURLOPT_URL, $url.$prox."&major=".$major."&minor=".$minor);
        array("Api-Key: ".$key,
                "Accept: application/vnd.com.kontakt+json;version=5",
				"Content-Type: application/x-www-form-urlencoded"));
$reply = curl_exec($rest);

echo $reply;


*An extra space was needed at the start of the PHP code block after the first angle breaker otherwise the source code wouldn't show with markdown, oddly.

So the above returns UUID, major/minor IDs, broadcast interval, TX power, any browser actions, etc. (more info here http://docs.kontakt.io/rest-api/quickstart/#using-the-api-key) as a JSON object.

UPDATE: I realized that if you're managing several beacons which may share the same UUID it may be better to get the beacon by unique ID (aka device ID, separate 4 character alphanumeric string Kontakt assigns to your beacons). In this case you would just pass the unique ID in your GET URL like so: https://api.kontakt.io/beacon/5QQ4

Vincent Seow

Vincent Seow