Read Data

Reading, writing and managing data is among the basic functionalities of Beebotte.

Beebotte API makes it easy for an object (physical or virtual channel) to read data from Beebotte cloud platform. Beebotte associates data to resources and automatically performs multi time scale statistical analysis to calculate hourly, daily, and monthly metrics. Using the API, it is possible to request data from the resource live database (persistent messages) or from the resource statistics data.

Data can be read using the REST (server side) API. Remember that only persistent messages are stored into Beebotte and thus can be read. You can read up to 50,000 records in one read call.


Server Side Read (REST API)

You can read from a resource as follows (last inserted records will be returned):

bclient.read({
  channel: 'dev',
  resource: 'res1',
  limit: 5/* Retrieves last 5 records . default is 750 */
}, 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
## cURL requires Channel Token authentication

curl -H "Content-Type: application/json" \
  -H "X-Auth-Token: YOUR_CHANNEL_TOKEN" \
  -X GET \
  http://api.beebotte.com/v1/data/read/dev/res1?limit=5

The API for reading from a resource statistics is very similar with just few additional parameters. It is done as follows:

bclient.read({
  channel: 'dev',
  resource: 'res1',
  limit: 24 /* Retrieves last 24 records . default is 750 */,
  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

// Create a private message to read from
PrivateMessage msg = new PrivateMessage('dev', 'res1', limit: 24, source: 'hour-stats');

// Read from the resource
List records = bclient.PrivateRead(msg);
// Do something with records
## cURL requires Channel Token authentication

curl -H "Content-Type: application/json" \
  -H "X-Auth-Token: YOUR_CHANNEL_TOKEN" \
  -X GET \
  http://api.beebotte.com/v1/data/read/dev/res1?limit=24&source=hour-stats

Statistics calculation are done for a number of numeric based resource types. If the requested resource is does not maintain statistical data, an empty array will be returned. Please refer to the data types and the details of the Read API for more information.


Client side Read (client applications)

You can use the client side API to read data from a public resource.

/* You are responsible for granting read access */
var bbt = new BBT('API_KEY');

bbt.read({owner: 'username', channel: 'dev', resource: 'res1', limit: 5}, function(err, msg) {console.log(msg)});

Take into account the following points when using the client side read API:

  • Reading from a resource history is limited for public resources
  • Reading from public resources does not require any authentication