Data Storage: Storing data against entities and extensions

While you build an extension for Zoho BugTracker, you might have to store the extension's data somewhere. We use key-value pairs to store such data against entities and extensions. Hence, the need for a traditional database like RDBMS, where the data will be stored in rows and columns, is eliminated. 

Entity Properties

What is a key-value pair?

'Key-value' is a format in which data can be stored. You can store the property or an attribute of an entity or an extension in a key-value pair.  The key will be a unique string and the value will be a JSON object. Data like session information, user profiles, and preferences can be stored as key-value pairs. You can store data against the entities we support and the extensions you develop for Zoho BugTracker.

Storing data against an entity

Zoho BugTracker supports the 'issue' entity. You will be able to store issue-specific data against their respective entities. The key will be a unique string and the data will be a JSON object that has to be identified with the key in the future. You can store, retrieve, update, and delete the data that you store against an entity using the following methods respectively.

If the current user has only READ access, they will be able to only retrieve the data i.e.retrieve() can only be invoked. If they have EDIT access, the other functions like 'store()', 'update()', and 'remove()' can also be invoked.

entity.store

Stores data against an entity.


var value = [
{"id" : "1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu","name" : "Sample.png"}
];
zohobugtracker.entity.store("6573492", value).then(function(response)
/* Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"sample.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

Arguments

Argument nameData typeDescription
keystring

Unique string used to identify the entity property. Only this key should be used to retrieve the data later.

Note: Max length: <255> TBD

valueJSONObjectProperty / Data that has to be stored against the entity.

If the entity is deleted, the data stored against the entity is deleted automatically.

entity.retrieve

Retrieves the data stored against an entity. The argument of this method should be the key that was used when the same data was stored.


zohobugtracker.entity.retrieve("6573492").then(function(response)
/*Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"update.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

entity.update

Updates the data that's stored against an entity. The argument of this method is a JSON object with the following three predefined keys:

Argument nameData typeDescription
idstringThe ID that was generated as the output while storing the current key against the entity using the entity.store() method.
keystringThe new key that has to be mapped against the entity. You can also choose to retain the old/current key.
valueJSON ObjectThe data or property that has to be updated against the entity.

var valueObj = [
{"id" : "1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu","name" : "Sample_New.png"}
];
zohobugtracker.entity.update({id:"1587134426",key:"6573492",value:valueObj}).then(function(response)
/*Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"Sample_New.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

entity.remove

Deletes the data that's stored against a specific entity. The argument of this method is the ID that was generated as the output when the same data was stored using the 'entity.store()' method.


zohobugtracker.entity.remove(1587134426).then(function(response)
/* Output
{
  "status": "success"
}
*/
);

Limitations of entity properties

  • The value stored against a key should not exceed 50KB at once.
  • This method cannot be invoked for the 'app_settings', 'attachment_picker' and 'top_band' locations.
  • The value stored in an entity property should be in a valid JSON format.
  • Concurrent edits on an entity property don't ensure consistency. i.e, when two different users make changes to the same entity property at the same time, only the latest change will be saved and the former will be lost/overridden.

Extension property

What is an extension property?

It is a key-value pair that's stored against the extension itself. However, the data stored against an extension will be lost if the extension is uninstalled from the product. Whereas, the data stored against an entity will be retained even if the extension is uninstalled because only the extension-specific information gets deleted and the entity-specific data will still be available for the other extensions to access.

app.store

Stores data against an extension. 


var value = [
{"id" : "1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu","name" : "Sample.png"}
];
zohobugtracker.app.store("6573492", value).then(function(response)
/* Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"sample.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

Arguments

Argument nameData typeDescription
keystringUnique string used to identify the extension property.
valueJSONObjectProperty/Data that has to be stored against the extension.

app.retrieve

Retrieves the data stored against the extension. The argument of this method should be the key that was used when the same was stored. Data could be retrieved only when this method is invoked from the extension against which it is stored. When the extension is uninstalled, the data will be deleted.


zohobugtracker.app.retrieve("6573492").then(function(response)
/*Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"update.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

app.update

Updates the data that's stored against an extension. The argument of this method is a JSON object with the following predefined keys:

Argument nameData typeDescription
idstringThe ID that was generated as the output while storing the current key against the extension using the app.store() method.
keystringThe new key that has to be mapped against the extension. You can also choose to retain the old/current key.
valueJSON ObjectThe data or property that has to be updated against the extension.

var valueObj = [
{"id" : "1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu","name" : "Sample_New.png"}
];
zohobugtracker.app.update({id:"1587134426",key:"6573492",value:valueObj}).then(function(response)
/*Output
{
  "properties": [
    {
      "key": "6573492",
      "value": "[{\"id\":\"1-QabBt69U8myXYRDVU-1YiCo2k-JWRfu\",\"name\":\"Sample_New.png\"}]",
      "id": 1587134426
    }
  ]
}
*/
);

app.remove

Deletes the data that's stored against a specific extension. The argument of this method is the ID that was generated as the output when the same data was stored using the app.store() method.


zohobugtracker.app.remove(1587134426).then(function(response)
/* Output
{
  "status": "success"
}
*/
);

Limitations of extension properties

  • The value stored against a key should not exceed 50KB at once.
  • A maximum of 100 key-value pairs only can be stored against an extension.
  • The value stored in an extension property should be in a valid JSON format.
  • Concurrent edits on an extension property don't ensure consistency. i.e, when two different users make changes to the same extension property at the same time, only the latest change will be saved and the former will be lost/overridden.

You can store, retrieve, update, and delete the data that you store against an extension using the following methods respectively.