Quick Start Guide

Sign-up and note yoursecret key andAPI key in youraccountsettings page.
YourSecret Key is a secret shared between you and Beebotte. It is used to authenticate and sign your communications with Beebotte.Learn more.

Tutorial contents:

Step 0: Install and initialize the SDK

The first step to use Beebotte's API is to install the SDK for your programming language. In this tutorial we will be using nodejs and javascript. Refer to the libraries for more instructions.

Beebotte Nodejs SDK can simply be installed using npm:

npm install beebotte
Beebotte Python SDK can simply be installed using pip:

pip install beebotte //On Linux
python -m pip install beebotte //On MS Windows
Beebotte PHP SDK is available as a composer package named bbt_php:
https://packagist.org/packages/beebotte/bbt_php

Check installation instructions at:
https://getcomposer.org/doc/01-basic-usage.md
Beebotte .Net SDK source code and binaries can be obtained from github

https://github.com/beebotte/bbt_dotnet

Install or download Beebotte SDK if you haven't already. Create a new file (or project depending on the programming language you are using) and open it with the editor or IDE of your choice. Include beebotte library as follows:

//Include the Beebotte SDK for nodejs
var bbt = require('beebotte');

var bclient = new bbt.Connector({apiKey: 'API_KEY', secretKey: 'SECRET_KEY'});
//Include the Beebotte SDK for Python
from beebotte import *

bclient = BBT("API_KEY", "SECRET_KEY")
//Include Beebotte SDK for PHP
require 'vendor/autoload.php'; //If installed using Composer

$bclient = new Beebotte("API_KEY", "SECRET_KEY");
//Include Beebotte SDK for .Net
using Beebotte.API.Server.Net;

Connector bclient = new Connector("API_KEY", "SECRET_KEY");

Step 1: Write Data (Send persistent message)

Beebotte provides two types of resource data:persistent andTransient . persistent data will be stored into a database and will be available for future read requests. Transient data, will not be persisted. It will be delivered to listeners in real time. The following example show you how to write persistent data to Beebotte. Remember that persistent data MUST be associated to an existing resource.

You can send a persistent message as follows:

bclient.write(
  {channel: 'dev', resource: 'res1', data: 'Hello World'},
  function(err, res) {
    // Do something here
});
## Create a Resource object
res1 = Resource(bclient, 'dev', 'res1')
## Write to the resource
res1.write('Hello World')

## Or simply
bclient.write('dev', 'res1', 'Hello World')
// Create a Resource object
$res1 = new Resource($bclient, 'dev', 'res1');
// Write to the resource
$res1->write('Hello World');

// Or simply
$bclient->write('dev', 'res1', 'Hello World');
// Write to the resource: Simply
bclient.Write("dev", "res1", 'Hello World');

You can send an array of persistent messages (bulk write) as follows:

bclient.writeBulk({channel: 'dev', records: [
    {resource: 'res1', data: 'Hello'},
    {resource: 'res2', data: 'World'}
]}, function(err, res) {
    // Do something here
});
bclient.writeBulk('dev', [
  {resource: 'res1', data: 'Hello'},
  {resource: 'res2', data: 'World'}
])
$bclient->writeBulk('dev', [
  {resource: 'res1', data: 'Hello'},
  {resource: 'res2', data: 'World'}
]);
// Create the a list of resource messages to write
List msgs = new List();
msgs.Add(new ResourceMessage("res1", "Hello"));
msgs.Add(new ResourceMessage("res2", "World"));
// Write (persist) the messages
bclient.WriteBulk("dev", msgs);

Step 2: Publish Data (Send transient message)

You can publish a transient message as follows:

bclient.publish(
  {channel: 'dev', resource: 'res1', data: 'Hello World'},
  function(err, res) {
    // Do something here
});
## Create a Resource object
res1 = Resource(bclient, 'dev', 'res1')
## Publish to the resource
res1.publish('Hello World')

## Or simply
bclient.publish('dev', 'res1', 'Hello World')
// Create a Resource object
$res1 = new Resource($bclient, 'dev', 'res1');
// Publish to the resource
$res1->publish('Hello World');

// Or simply
$bclient->publish('dev', 'res1', 'Hello World');
// Publish the message
bclient.Publish("dev", "res1", "Hello World");

You can send an array of transient messages (bulk publish) as follows:

bclient.publishBulk({channel: 'dev', records: [
    {resource: 'res1', data: 'Hello'},
    {resource: 'res2', data: 'World'}
]}, function(err, res) {
    // Do something here
});
bclient.publishBulk('dev', [
  {resource: 'res1', data: 'Hello'},
  {resource: 'res2', data: 'World'}
])
$bclient->publishBulk('dev', [
  {resource: 'res1', data: 'Hello'},
  {resource: 'res2', data: 'World'}
]);
// Create the message with bulk records to publish
List msgs = new List();
msgs.Add(new ResourceMessage("res1", "Hello"));
msgs.Add(new ResourceMessage("res2", "World"));

// Publsih the message (multiple records)
bclient.PublishBulk("dev", msgs);

Step 3: Read message

You can use the server SDK to read persistent resource from Beebotte like this:

bclient.read({
  channel: 'dev',
  resource: 'res1',
  limit: 5/* Retrieves last 5 records . default is 1 */
}, function(err, res) {
  // Do something here
});
## Create a Resource object
res1 = Resource(bclient, 'dev', 'res1')
## Read from the resource
records = res1.read(limit = 5)
## Do something with records (JSON format)

## Or simply
records = bclient.read('dev', 'res1', limit = 5)
// Create a Resource object
$res1 = new Resource($bclient, 'dev', 'res1');
// Read from the resource
$records = $res1->read(5); //limit is the first parameter
// Do something with records

// Or simply
$records = $bclient->read('dev', 'res1', 5);
// Read from the resource
List records = bclient.Read("dev", "res1", limit: 5);
// Do something with records

You can also read from resource statistics like this:

bclient.read({
  channel: 'dev',
  resource: 'res1',
  limit: 24 /* Retrieves last 24 records . default is 1 */,
  source: 'hour-stats' /* read from the hour based statistics */,
}, function(err, res) {
  // Do something here
});
## Create a Resource object
res1 = Resource(bclient, 'dev', 'res1')
## Read from the resource
records = res1.read(limit = 24, source = 'hour-stats')
## Do something with records (JSON format)

## Or simply
records = bclient.read('dev', 'res1', limit = 24, source = 'hour-stats')
// Create a Resource object
$res1 = new Resource($bclient, 'dev', 'res1');
// Read from the resource
$records = $res1->read(24, 'hour-stats'); //limit and source are the first and second parameters
// Do something with records

// Or simply
$records = $bclient->read('dev', 'res1', 24, 'hour-stats');
// Read from the resource
List records = bclient.Read("dev", "res1", limit: 24, source: "hour-stats");
// Do something with records

Step 4: Receive messages in real time

Beebotte provides a javascript library to add real-time communication between a browser (webpage) and Beebotte platform. In this section we will see how a webpage can receive data from Beebotte in real time.

You need first to include the javascript client library in your HTML page.

<script src='socket.io.min.js'></script>
<script src='//beebotte.com/bbt.js' ></script>

Set up the credentials to access the API. As the created channel is public, you only need to the API key to read data.

var bbt = new BBT('API_KEY');

In order to receive messages relative to a specific resource, we need to subscribe to that resource first:

You can subscribe to a private resource as follows (resource belonging to a private channel):

var bbt = new BBT('API_Key', {auth_endpoint: 'authentication_URL'});

/* Subscribing to private resource will automatically request read access permission */
bbt.subscribe({
  channel: 'private-dev', //Note the 'private-' prefix
  resource: 'res',
}, function(msg){
  /* Do something here */
  /* Will get here every time a new resource data is written or published */
});

You can subscribe to a public resource as follows:

var bbt = new BBT('API_KEY');

//Public resources do not require special permissions, they are open for everybody
bbt.subscribe({
  channel: 'dev',
  resource: 'res',
}, function(msg){
  /* Do something here */
  /* Will get here every time a new resource data is written or published */
});

Find out more about the cool things you can do in thetutorials. Check thedemos and startplaying with the APIfor further details.