Create Data Storage
For storing data, the following attributes are to be mentioned in your request:
Attributes | Description |
---|---|
key | Unique key to identify the stored value. The value of this attribute can have a maximum length of 50 characters and it cannot be NULL. The special characters allowed are comma (,), underscore (_), and colon (:). |
value | Represents the value of the stored information. The data passed by this attribute must be a JSON object whose size cannot exceed 5.1 KB. Even empty JSON objects can be passed. |
queriableValue | Helps to fetch the value by reverse lookup. Used to group the multiple storage data. Specifies a common lookup group of the given key-value pair which will be useful for lookup from the database. The value of this attribute can have a maximum length of 50 characters and it cannot be NULL. The special characters allowed are comma (,), underscore (_), and colon (:). |
Note:You can store multiple values by passing them as an array of objects, as shown in the sample request. Only 10 values can be stored at a time.
You can create data in two ways:
To store extension-related data in a database, follow the steps given below:
- In your local drive, go to your Project folder which you created initially while building your first widget.
- Open widget.html file in app folder, with the help of editor.
- In widget.html file, provide the Request as given here to store the data.
This request asynchronously sets the data in the extension's connected database. - Save the file.
You can also store large amounts of data.
- Pack and publish the extension.
Now, your data will be successfully stored in the database. This data can be retrieved and used to develop the functionalities of your extension.
Note: Once the corresponding extension is uninstalled, all the data stored in the database will be deleted automatically and cannot be recovered. You can store the personal details also in an encrypted format.
Sample Request
Copied//Set single Data in Storage
ZOHODESK.set('database', { key: "001", value: { name: "zylker" }, queriableValue: "Production_Department" }).then(function (response) {
// response returns the value saved
//response = {"database.set":{"queriableValue":"Production_Department","value:{"name":"zylker"},"key":"001"}}"
}).catch(function (err) {
// Error handling
})
//Set Bulk Data in Storage
ZOHODESK.set('database', [
{
"queriableValue": "bugid:94208395746",
"value": {
"name": "portal"
},
"key": "id:674883524897539"
},
{
"queriableValue": "bugid:94208395746",
"value": {
"name": "support"
},
"key": "id:674883524897537"
},
{
"queriableValue": "bugid:94208395746",
"value": {
"name": "helpdesk"
},
"key": "id:674883524897540"
}
]).then(function (response) {
//Print response
console.log(response);
}).catch(function (err) {
// Error handling
console.log(err);
})
via Functions
To create data storage via functions, follow the steps given below:
- Go to Sigma > Functions > Add Function > Create your function.
In the function editor, provide the given sample request.
In this request, a connection will be used to store the data. For that connection, scopes should hold the value 'Desk.extensions.ALL'.
- Save and Publish the function.
- Associate function with the extension.
- Publish the extension.
Your data will be successfully stored in the database while calling this function.
Sample Request
Copiedrequest = map();
request.put("key", "001");
request.put("queriableValue", "Production_Department");
val = Map();
val.put("name", "zylker");
request.put("value", val);
head = Map();
head.put("orgId", data.get('integ_scope_id'));
installationId = data.get('service_app_id');
//Set a single value using data storage
storage = invokeurl
[
url: "https://desk.zoho.com/api/v1/installedExtensions/"+installationId+"/storage"
type: POST
parameters: request.toString()
headers: head
content-type: "application/json"
connection: "testing"
];
//Set bulk data using storage API
bulkRequestParams={"storage":[
{
"queriableValue": "bugid:94208395746",
"value": {
"name": "portal"
},
"key": "id:674883524897539"
},
{
"queriableValue": "bugid:94208395746",
"value": {
"name": "support"
},
"key": "id:674883524897537"
},
{
"queriableValue": "bugid:94208395746",
"value": {
"name": "helpdesk"
},
"key": "id:674883524897540"
}
]};
storage = invokeurl
[
url: "https://desk.zoho.com/api/v1/installedExtensions/"+installationId+"/storage/bulk"
type: POST
parameters: bulkRequestParams.toString()
headers: head
content-type: "application/json"
connection: "testing"
];
Show full
Show less