Realtime Cloud Storage

putItem

Stores an item in a table or replaces an existing item with a new item.

Sample

curl 'https://storage-backend-prd-useast1.realtime.co/putItem' -H 'Content-Type: application/json; charset=UTF-8' -d '{ "applicationKey": "[YOUR_APP_KEY]", "authenticationToken":"[YOUR_TOKEN]", "table":"SampleUser","item":{ "id":1, "category": "developer", "name": "Mr. Smith" } }'

Parameters

String applicationKey

Public key of the application's license.

String privateKey optional

Private key of the application's license. For administration use only.

String authenticationToken

Identification of the user using the application.

String table

The name of the table.

Object item

The properties that compose the item to be stored.

PutItemResponse callback

Function called when the operation completes.

Response

PutItemResponse(data, error)

Response of the putItem operation.

Object data

The upserted item

Error error

The attribute that holds the results of the operation if an error occurred.

Notifications

A notification is a Realtime Cloud Messaging message sent each time an item is inserted, updated or deleted. To receive these messages, you must connect using cluster URL http://ortc-storage.realtime.co/server/2.1 and subscribe a channel with the following syntax:

rtcs_[TABLE]

Receive notifications of all changes made to the items of a TABLE.

rtcs_[TABLE]:[PRIMARY_KEY]

Receive notifications of changes made only for the specific item(s) with the PRIMARY_KEY stored in TABLE.

rtcs_[TABLE]:[PRIMARY_KEY]_[SECONDARY_KEY]

Receive notifications of changes made only for the specific item with the PRIMARY_KEY and SECONDARY_KEY stored in TABLE.

where [TABLE] should be replaced with the name of the table; [PRIMARY_KEY] with the value of a primary key and [SECONDARY_KEY] with the value of a secondary key.

At least two, and at most three, notifications are sent each time an operation is done over an item, depending whether the table has a secondary key. All of them include the item and are sent to the above mentioned channels. The message includes the type of operation (put, update, delete) and data with the changed item.


// subscribe to a channel at table level. All changes made to items in table 'SampleUser' will be received.
connection.subscribe("rtcs_SampleUser", function(message) {
    var item = message.data;
    console.log(message.type, "of user", item.id);
});

// subscribe to a channel at primary key level. All changes made to items with primary key 'developers' will be received.
connection.subscribe("rtcs_SampleUser:developer", function(message) {
    var item = message.data;
    console.log(message.type, "of user", item.id);
});

// subscribe to a channel at secondary key level (the most restrict). All changes made to the item with primary key 'developers' and secondary key 1 will be received.
connection.subscribe("rtcs_SampleUser:developer:1", function(message) {
    var item = message.data;
    console.log(message.type, "of user", item.id);
});