Writing Data

Writing, reading and managing data is among the primary functionalities of Beebotte.

Beebotte API makes it extremely easy for an object (physical or virtual channel) to write data to Beebotte cloud platform. Beebotte associates data to resources; it is possible to write one record at a time or to perform a bulk write for multiple records belonging to the same channel.

Beebotte provides server (backend) and client libraries for writing data to already created resources. These libraries use either the REST API or the Websockets API.

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. Both data message types will be routed by Beebotte and delivered to subscribers in real time. The following example show how to submit persisted data to Beebotte. Remember that persisted data MUST be associated to an existing resource.

When writing to a channel resource, the message will have the access level (public or private) of the channel.
That is: the message will be private when writing to a private channel and public when writing to a public channel.


Server side Write (REST API)

You can send a persisted 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');
## cURL requires Channel Token authentication

curl -i -H "Content-Type: application/json" \
  -H "X-Auth-Token: YOUR_CHANNEL_TOKEN" \
  -X POST -d '{"data":"Hello World"}' \
  http://api.beebotte.com/v1/data/write/dev/res1

Server side Bulk write (REST API)

You can send an array of 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);
## cURL requires Channel Token authentication

curl -i -H "Content-Type: application/json" \
  -H "X-Auth-Token: YOUR_CHANNEL_TOKEN" \
  -X POST -d '{"records":[{"resource":"res1","data":"Hello"},{"resource":"res2","data":"World"}]}' \
  http://api.beebotte.com/v1/data/write/dev

Client side Write (client applications)

You can use the client side libraries to write resources.

/* You are responsible for granting write access access */
var bbt = new BBT('API_KEY', {auth_endpoint: 'authentication_URL'});

/* Subscrite to the resource with write access. Permissions are granted at the resource level */
bbt.subscribe({channel: 'dev', resource: 'res1', write: true}, function(err, msg) {console.log(msg)} );

bbt.write({channel: 'dev', resource: 'res1', data: 'Hello World'});


/* If the channel is private, you need to add 'private-' prefix to the channel name */
bbt.subscribe({channel: 'private-dev', resource: 'res1', write: true}, function(err, msg) {console.log(msg)} );

bbt.write({channel: 'private-dev', resource: 'res1', data: 'Hello World'});

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

  • You are responsible for granting permissions to your users (users of your website, web application or service)
  • You can limit your permission in time by setting the ttl parameter (defined in seconds)
  • Permissions should be granted before any write operation
  • Write permission is mandatory for public and private resources (public or private channels)
  • Permissions are associated to user sessions. If the user reloads the page, a new permission needs to be requested.