### Get User Profile Implementation
Source: https://sdk.dronahq.com/en/stable/developer/api-device-user.html
Example implementation showing success and error callback functions to handle the retrieved user profile data.
```javascript
var fnSuccess = function(uData){
console.log('User ID: ' + uData.uid);
console.log('User Name: ' + uData.name);
console.log('User Email: ' + uData.email);
console.log('User Designation: ' + uData.designation);
console.log('User Profile Image: ' + uData.profile_image);
console.log('User Nonce: ' + uData.nonce);
};
var fnError = function(err){
console.error('Failed to load user info. Error: ' + err);
};
DronaHQ.user.getProfile(fnSuccess, fnError);
```
--------------------------------
### Get all users endpoint
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Retrieves a list of users within the scope of the provided tokenkey.
```http
GET /users
```
--------------------------------
### Get User Profile Method Signature
Source: https://sdk.dronahq.com/en/stable/developer/api-device-user.html
The basic method signature for retrieving the user profile object.
```javascript
DronaHQ.user.getProfile(fnSuccess, fnError);
```
--------------------------------
### GET /users
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Retrieves a list of users within the scope of the provided tokenkey, ordered chronologically.
```APIDOC
## GET /users
### Description
This API returns a list of users within the scope of the tokenkey, ordered chronologically.
### Method
GET
### Endpoint
/users
### Parameters
#### Query Parameters
- **tokenkey** (string) - Required - Your API key.
- **ulimit** (integer) - Optional - The number of users to return. Default is 25.
- **maxuid** (integer) - Optional - If given, users with user id greater than the maxuid are returned.
- **gid** (integer) - Optional - If given, users who belong to the group with id gid are returned.
- **search** (string) - Optional - Keyword to search for in user’s name.
- **showstats** (boolean) - Optional - If true, a summary of user’s stats will be returned.
- **listtype** (string) - Optional - A enum with 3 possible values: active, inactive, moderate.
### Response
#### Success Response (200)
- **user_id** (integer) - Unique id of the user
- **user_name** (string) - Full name of the user
- **user_email** (string) - Email-id of the user
- **user_desg** (string) - Designation of the user
- **user_image_url** (string) - Profile image url of the user
- **channel_name** (string) - Unique name of account where user is registered in
- **app_name** (string) - Display name of the account where user is registered in
- **user_reg_date** (string) - Registration date of the user in ‘yyyy-MM-dd hh:mm:ss’ format in UTC time-zone
- **external_idp** (boolean) - true if user account is connected to a third-party identity provider
- **external_idp_response** (string) - Response recieved from the third-party identity provider
- **is_admin** (boolean) - true if the user is an admin
- **user_group** (array) - Array of groups which are assigned to the user
```
--------------------------------
### Demonstrate invalid transaction usage
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Example of incorrect usage where SQL statements are executed on a transaction after it has finished.
```javascript
// BROKEN SAMPLE:
var db = window.sqlitePlugin.openDatabase({name: "test.db"});
db.executeSql("DROP TABLE IF EXISTS tt");
db.executeSql("CREATE TABLE tt (data)");
db.transaction(function(tx) {
$.ajax({
url: 'https://api.github.com/users/litehelpers/repos',
dataType: 'json',
success: function(res) {
console.log('Got AJAX response: ' + JSON.stringify(res));
$.each(res, function(i, item) {
console.log('REPO NAME: ' + item.name);
tx.executeSql("INSERT INTO tt values (?)", JSON.stringify(item.name));
});
}
});
}, function(e) {
console.log('Transaction error: ' + e.message);
}, function() {
// Check results:
db.executeSql('SELECT COUNT(*) FROM tt', [], function(res) {
console.log('Check SELECT result: ' + JSON.stringify(res.rows.item(0)));
});
});
```
--------------------------------
### GET /users/{userIdORuserEmail}
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Retrieves a user object for the specified user ID or email address.
```APIDOC
## GET /users/{userIdORuserEmail}
### Description
This API returns a user object for the provided userId or Email within the scope of the tokenkey.
### Method
GET
### Endpoint
/users/{userIdORuserEmail}
### Parameters
#### Path Parameters
- **userIdORuserEmail** (string) - Required - The “user id” or “email id” of the user whose profile information you which to retrieve
#### Query Parameters
- **tokenkey** (string) - Required - Your API key.
- **nonce** (string) - Optional - Recieved as SSO parameter from the container app via the dronahq.js
- **stats** (boolean) - Optional - If true, a summary of user’s CMS activity will be returned in the response object.
### Response
#### Success Response (200)
- **user_id** (integer) - Unique id of the user
- **user_name** (string) - Full name of the user
- **user_email** (string) - Email-id of the user
- **user_desg** (string) - Designation of the user
- **user_image_url** (string) - Profile image url of the user
- **channel_name** (string) - Unique name of account where user is registered in
- **app_name** (string) - Display name of the account where user is registered in
- **user_reg_date** (string) - Registration date of the user in ‘yyyy-MM-dd hh:mm:ss’ format in UTC time-zone
- **external_idp** (boolean) - true if user account is connected to a third-party identity provider
- **external_idp_response** (string) - Response recieved from the third-party identity provider
- **is_admin** (boolean) - true if the user is an admin
- **user_group** (array) - Array of groups which are assigned to the user
```
--------------------------------
### Get pending upload count
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sync.html
Retrieves the total number of upload requests currently waiting in the queue.
```javascript
DronaHQ.sync.getPendingUploadCount(function(count){}, function(e){});
```
--------------------------------
### Open a database with callbacks
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Use optional success and error callbacks when opening a database to handle initialization results.
```javascript
window.sqlitePlugin.openDatabase({name: 'my.db'}, function(db) {
db.transaction(function(tx) {
// ...
}, function(err) {
console.log('Open database ERROR: ' + JSON.stringify(err));
});
});
```
--------------------------------
### Open a database after deviceready
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Wait for the 'deviceready' event before attempting to open a database connection to ensure the environment is initialized.
```javascript
// Wait for dronahq to load
document.addEventListener('deviceready', onDeviceReady, false);
// DronaHQ is ready
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name: 'my.db'});
// ...
}
```
--------------------------------
### Create Application index.html
Source: https://sdk.dronahq.com/en/stable/developer/quick-start.html
A basic HTML structure for a DronaHQ micro-app, including necessary CSS and JS dependencies.
```html
User profile - DronaHQ
Name: {{user_name}}
Email: {{user_email}}
Nonce: {{nonce}}
Designation: {{user_desig}}
```
--------------------------------
### Initialize DronaHQ Application
Source: https://sdk.dronahq.com/en/stable/developer/quick-start.html
This script initializes the application, fetches user profile data, and handles default profile image generation using Identicon.
```javascript
/* global $, DronaHQ, Identicon */
var App = function () {
var _getDefaultImage = function (inputHash) {
// set up options
var hash = 'myUnicodeUsername!' // Any unicode string
var options = {
background: [255, 255, 255, 255], // rgba white
margin: 0.2, // 20% margin
size: 290 // 420px square
}
// create a base64 encoded PNG
var data = new Identicon(hash, options).toString()
return 'data:image/png;base64, ' + data;
}
var _initUser = function () {
DronaHQ.user.getProfile(function (uData) {
console.log('User ID: ' + uData.uid)
$('#spUserName').text(uData.name)
$('#spUserEmail').text(uData.email)
if (uData.designation) {
$('#userDesg').removeClass('hide')
$('#spUserDesg').text(uData.designation)
}
if (uData.profile_image) {
$('#imgUserProfile').attr('src', uData.profile_image)
} else {
$('#imgUserProfile').attr('src', _getDefaultImage(uData.uid))
}
$('#spUserNonce').text(uData.nonce)
})
}
return {
init: function () {
_initUser()
}
}
}
$(document).on('deviceready', function () {
var objApp = new App()
objApp.init()
})
```
--------------------------------
### POST /users
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Creates a user account with pre-registered password and group(s) based on the scope of the tokenkey.
```APIDOC
## POST /users
### Description
Creates a user account with pre-registered password and group(s) based on the scope of the tokenkey. A maximum of 50 users can be sent in one request.
### Method
POST
### Endpoint
/users
### Parameters
#### Request Body
- **token_key** (string) - Required - Your API key.
- **pre_register** (bool) - Required - Set value to true.
- **invitee_user** (array) - Required - An array of the invitee object.
#### Invitee object data
- **user_name** (string) - Required - Full name of the invitee.
- **user_email** (string) - Required - Email-id of the invitee.
- **user_group_name** (array) - Required - A string array of the group-names.
- **user_password** (string) - Required - Password for the invitee.
### Response
#### Success Response (200)
- **response** (array) - Returns an empty array on success, or an array of error objects for individual invitees if registration fails.
#### Error object of an invitee
- **user_email** (string) - Email-id of the invitee.
- **error_code** (string) - Error code.
- **error_detail** (string) - Detailed description of the error.
```
--------------------------------
### Initialize DronaHQ Client
Source: https://sdk.dronahq.com/en/stable/developer/quick-start.html
Wait for the deviceready event before executing any Device API calls to ensure the container is fully initialized.
```javascript
document.addEventListener('deviceready', function(){
//Intialize your app
}, false);
```
--------------------------------
### Execute PRAGMA statements with SQLite
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Demonstrates creating a table, inserting data, and executing a PRAGMA statement. PRAGMA statements must be called on the database object directly, not within a transaction.
```javascript
// Wait for DronaHQ to load
document.addEventListener('deviceready', onDeviceReady, false);
// DronaHQ is ready
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name: 'my.db'});
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
// demonstrate PRAGMA:
db.executeSql("pragma table_info (test_table);", [], function(res) {
console.log("PRAGMA res: " + JSON.stringify(res));
});
tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
console.log("insertId: " + res.insertId + " -- probably 1");
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
db.transaction(function(tx) {
tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) {
console.log("res.rows.length: " + res.rows.length + " -- should be 1");
console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
});
});
}, function(e) {
console.log("ERROR: " + e.message);
});
});
}
```
--------------------------------
### window.sqlitePlugin.openDatabase
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Opens a database access handle object. It is recommended to wait for the 'deviceready' event before calling this method.
```APIDOC
## window.sqlitePlugin.openDatabase
### Description
Opens a database access handle object for the specified database name.
### Parameters
- **args** (object) - Required - An object containing the database name, e.g., {name: 'my.db'}.
- **successcb** (function) - Optional - Callback function executed upon successful database opening.
- **errorcb** (function) - Optional - Callback function executed if an error occurs during opening.
```
--------------------------------
### PUT /users
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Activates registered users based on the provided token key and list of email addresses.
```APIDOC
## PUT /users
### Description
Activates registered users based on the scope of the tokenkey.
### Method
PUT
### Endpoint
/users
### Parameters
#### Request Body
- **token_key** (string) - Required - Your API key.
- **list_user_email** (array) - Required - A string array of the users email. A maximum of 50 IDs can be sent in one request.
### Response
#### Success Response (200)
- **users_success** (integer) - A string array of user email whose account has been successfully activated.
- **users_invalid** (array) - A string array of invalid user email.
- **user_not_exist** (array) - A string array of user not found in the API key scope.
- **users_failed** (array) - A string array of user email on which the operation of activation failed.
```
--------------------------------
### Create Users Endpoint
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
The endpoint used to initiate the user creation process via a POST request.
```http
POST /users
```
--------------------------------
### Perform transaction-level nesting
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Shows how to reuse the same transaction object to perform sequential SQL operations.
```javascript
// Wait for DronaHQ to load
document.addEventListener('deviceready', onDeviceReady, false);
// DronaHQ is ready
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase({name: 'my.db'});
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
console.log("insertId: " + res.insertId + " -- probably 1");
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");
tx.executeSql("select count(id) as cnt from test_table;", [], function(tx, res) {
console.log("res.rows.length: " + res.rows.length + " -- should be 1");
console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
});
}, function(tx, e) {
console.log("ERROR: " + e.message);
});
});
}
```
--------------------------------
### Execute standard asynchronous transactions
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Uses BEGIN, COMMIT, or ROLLBACK to ensure failure-safe database operations.
```javascript
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS MyTable');
tx.executeSql('CREATE TABLE MyTable (SampleColumn)');
tx.executeSql('INSERT INTO MyTable VALUES (?)', ['test-value'], function(tx, resultSet) {
console.log('resultSet.insertId: ' + resultSet.insertId);
console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected);
}, function(tx, error) {
console.log('INSERT error: ' + error.message);
});
}, function(error) {
console.log('transaction error: ' + error.message);
}, function() {
console.log('transaction ok');
});
```
--------------------------------
### Include DronaHQ SDK
Source: https://sdk.dronahq.com/en/stable/developer/quick-start.html
Add the dronahq.js script to the header of your HTML page to enable Device API functionality.
```html
```
--------------------------------
### DronaHQ.app.exitApp()
Source: https://sdk.dronahq.com/en/stable/developer/api-device-app.html
This method allows the user to exit the current instance of the micro-app.
```APIDOC
## DronaHQ.app.exitApp()
### Description
Exits the current instance of the micro-app.
### Method
JavaScript SDK Method
### Usage
```javascript
DronaHQ.app.exitApp();
```
```
--------------------------------
### window.sqlitePlugin.deleteDatabase(options, successcb, errorcb)
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Deletes a specified database file.
```APIDOC
## window.sqlitePlugin.deleteDatabase(options, successcb, errorcb)
### Description
Deletes the database specified by the provided options.
### Parameters
- **options** (object) - Required - An object containing the database name, e.g., {name: 'my.db'}.
- **successcb** (function) - Optional - Callback function executed upon successful deletion.
- **errorcb** (function) - Optional - Callback function executed if an error occurs during deletion.
```
--------------------------------
### Retrieve a value by key
Source: https://sdk.dronahq.com/en/stable/developer/api-device-kvs.html
Fetches the string value associated with the provided key name.
```javascript
DronaHQ.KVStore.getItem(keyName, function(data) {
//success callback
var value = data.value;
}, function() {
//fail callback
});
```
--------------------------------
### db.sqlBatch
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Executes a batch of SQL queries as a single transaction.
```APIDOC
## db.sqlBatch
### Description
Executes multiple SQL statements as a batch transaction.
### Parameters
- **queries** (array) - Required - An array of SQL strings or arrays containing [sql, params].
- **successcb** (function) - Optional - Callback executed upon successful completion of the batch.
- **errorcb** (function) - Optional - Callback executed if any part of the batch fails.
```
--------------------------------
### Overwrite window.openDatabase
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Replace the standard window.openDatabase factory with the sqlitePlugin implementation to maintain compatibility with existing Web SQL code.
```javascript
window.openDatabase = function(dbname, ignored1, ignored2, ignored3) {
return window.sqlitePlugin.openDatabase({name: dbname});
};
```
--------------------------------
### Activate Users Endpoint
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Use this endpoint to activate registered users. A maximum of 50 email addresses can be processed per request.
```http
PUT /users
```
--------------------------------
### Listen for uploadcomplete event
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sync.html
Registers an event listener to execute logic once the sync service has finished processing all pending requests.
```javascript
document.addEventListener('dronahq.sync.uploadcomplete', function(){
//Refresh task is complete.
});
```
--------------------------------
### Set a key-value pair
Source: https://sdk.dronahq.com/en/stable/developer/api-device-kvs.html
Stores a string value associated with a specific key name.
```javascript
DronaHQ.KVStore.setItem(keyName, keyValue, function() {
//success callback
}, function() {
//fail callback
});
```
--------------------------------
### Trigger the sync service
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sync.html
Wakes up the sync service to process any pending upload requests immediately.
```javascript
//refreshType = 'upload' for submitting any pending uploads
DronaHQ.sync.refresh(refreshType);
```
--------------------------------
### Exit the current micro-app
Source: https://sdk.dronahq.com/en/stable/developer/api-device-app.html
Terminates the current instance of the micro-app.
```javascript
DronaHQ.app.exitApp();
```
--------------------------------
### DronaHQ.sync.refresh()
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sync.html
Wakes up the sync service to trigger any pending uploads immediately.
```APIDOC
## DronaHQ.sync.refresh(refreshType)
### Description
Forces the sync service to wake up and process pending upload requests.
### Parameters
- **refreshType** (string) - The type of refresh to perform (e.g., 'upload').
### Example
```javascript
DronaHQ.sync.refresh('upload');
```
```
--------------------------------
### Execute SQL batch query transactions
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Run multiple SQL statements as a single batch transaction to optimize performance.
```javascript
db.sqlBatch([
'DROP TABLE IF EXISTS MyTable',
'CREATE TABLE MyTable (SampleColumn)',
[ 'INSERT INTO MyTable VALUES (?)', ['test-value'] ],
], function() {
db.executeSql('SELECT * FROM MyTable', [], function (resultSet) {
console.log('Sample column value: ' + resultSet.rows.item(0).SampleColumn);
});
}, function(error) {
console.log('Populate table error: ' + error.message);
});
```
--------------------------------
### Delete a database
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Deletes the specified database file.
```javascript
window.sqlitePlugin.deleteDatabase({name: 'my.db'}, successcb, errorcb);
```
--------------------------------
### DronaHQ.KVStore.clear
Source: https://sdk.dronahq.com/en/stable/developer/api-device-kvs.html
Removes all keys and values from storage.
```APIDOC
## DronaHQ.KVStore.clear(successCallback, failCallback)
### Description
Allows micro-apps to remove all keys with their associated string values.
### Parameters
- **successCallback** (function) - Required - Callback executed on success.
- **failCallback** (function) - Required - Callback executed on failure.
```
--------------------------------
### DronaHQ.KVStore.getItem
Source: https://sdk.dronahq.com/en/stable/developer/api-device-kvs.html
Retrieves the string value associated with a key.
```APIDOC
## DronaHQ.KVStore.getItem(keyName, successCallback, failCallback)
### Description
Allows micro-apps to get the string value of a key.
### Parameters
- **keyName** (string) - Required - The key to retrieve.
- **successCallback** (function) - Required - Callback executed on success, receiving an object with a 'value' property.
- **failCallback** (function) - Required - Callback executed on failure.
```
--------------------------------
### Upload data to a remote URL
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sync.html
Submits a request to the Container App to upload JSON data and an optional image. The sync service handles the actual transmission until a 2XX response is received.
```javascript
var remUrl = 'https://yourserver.com/api/users/134/action/updatedesignation';
var dronaHQReqMethod = 'POST';
var dronaHQReqData = {designation_code : 'X601'};
var reqImgURI = '';
var headers = [{ Authorization: 'Auth a2FuY2hhbkBkcm9uYW1vYmlsZS5jb206bWFpbEAxMjM0' }];
var options = {};
options.header = headers;
DronaHQ.sync.upload(remURL, dronaHQReqMethod, dronaHQReqData, reqImgURI, options);
```
--------------------------------
### Clear all storage
Source: https://sdk.dronahq.com/en/stable/developer/api-device-kvs.html
Removes all keys and their associated values from the local storage.
```javascript
DronaHQ.KVStore.clear(function() {
//success callback
}, function() {
//fail callback
});
```
--------------------------------
### Retrieve user profile
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Endpoint for fetching user details using a userId or email address.
```http
GET /users/{userIdORuserEmail}
```
--------------------------------
### PUT /v2/notifications
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-notification.html
Sends a notification to one or more users.
```APIDOC
## PUT /v2/notifications
### Description
Sends a notification to one or more users within the scope of the provided token key.
### Method
PUT
### Endpoint
/v2/notifications
### Parameters
#### Request Body
- **token_key** (string) - Optional - Your API key.
- **user_id** (array) - Required - A string array of the DronaHQ user ID or user Email ID. Maximum of 50 IDs.
- **message** (string) - Required - Text message to be sent as notification. Maximum 160 characters.
- **data** (string) - Optional - A custom JSON string to be sent along with the notification.
### Response
#### Success Response (200)
- **noti_id** (integer) - Unique ID of the sent notification.
- **user_success** (array) - A string array of user IDs to whom the notification has been sent successfully.
- **user_failed** (array) - A string array of invalid user IDs to whom notifications could not be delivered.
```
--------------------------------
### Execute single-statement SQL
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Perform individual SQL operations using executeSql with success and error callbacks.
```javascript
db.executeSql('INSERT INTO MyTable VALUES (?)', ['test-value'], function (resultSet) {
console.log('resultSet.insertId: ' + resultSet.insertId);
console.log('resultSet.rowsAffected: ' + resultSet.rowsAffected);
}, function(error) {
console.log('SELECT error: ' + error.message);
});
```
```javascript
db.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (resultSet) {
console.log('got stringlength: ' + resultSet.rows.item(0).stringlength);
}, function(error) {
console.log('SELECT error: ' + error.message);
});
```
--------------------------------
### DronaHQ.KVStore.setItem
Source: https://sdk.dronahq.com/en/stable/developer/api-device-kvs.html
Sets a string value for a specified key.
```APIDOC
## DronaHQ.KVStore.setItem(keyName, keyValue, successCallback, failCallback)
### Description
Allows micro-apps to set a string value to a key.
### Parameters
- **keyName** (string) - Required - The key to set.
- **keyValue** (string) - Required - The string value to associate with the key.
- **successCallback** (function) - Required - Callback executed on success.
- **failCallback** (function) - Required - Callback executed on failure.
```
--------------------------------
### DronaHQ.sync.upload()
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sync.html
Uploads JSON data to a remote URL. The request is queued and retried automatically until a 2XX response is received.
```APIDOC
## DronaHQ.sync.upload(remoteurl, requestmethod, requestdata, imagefilepath, options)
### Description
Uploads JSON data to a remote URL. Optionally includes an image file. The request is queued and retried every hour if it fails.
### Parameters
- **remoteurl** (string) - Required - http(s) URL of your API.
- **requestmethod** (string) - Required - HTTP method type ('POST' or 'PUT').
- **requestdata** (object) - Required - JSON object for the request body.
- **imagefilepath** (string) - Optional - File Path URI for an image.
- **options** (object) - Optional - Object containing headers and timeout settings.
- **fnsuccess** (function) - Optional - Callback after request is queued.
- **fnerror** (function) - Optional - Callback if request fails to queue.
### Example
```javascript
var remUrl = 'https://yourserver.com/api/users/134/action/updatedesignation';
var dronaHQReqMethod = 'POST';
var dronaHQReqData = {designation_code : 'X601'};
var reqImgURI = '';
var headers = [{ Authorization: 'Auth a2FuY2hhbkBkcm9uYW1vYmlsZS5jb206bWFpbEAxMjM0' }];
var options = { header: headers };
DronaHQ.sync.upload(remUrl, dronaHQReqMethod, dronaHQReqData, reqImgURI, options);
```
```
--------------------------------
### Execute read-only transactions
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Uses readTransaction to perform queries without BEGIN, COMMIT, or ROLLBACK operations.
```javascript
db.readTransaction(function(tx) {
tx.executeSql("SELECT UPPER('Some US-ASCII text') AS uppertext", [], function(tx, resultSet) {
console.log("resultSet.rows.item(0).uppertext: " + resultSet.rows.item(0).uppertext);
}, function(tx, error) {
console.log('SELECT error: ' + error.message);
});
}, function(error) {
console.log('transaction error: ' + error.message);
}, function() {
console.log('transaction ok');
});
```
--------------------------------
### Send Notification Endpoint
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-notification.html
Use this PUT request to send a notification to a list of user IDs or email addresses.
```http
PUT /v2/notifications
```
--------------------------------
### Close database within transaction callbacks
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Demonstrates valid usage of closing a database within transaction error or success callbacks.
```javascript
db.transaction(function(tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function(tx, res) {
console.log('got stringlength: ' + res.rows.item(0).stringlength);
});
}, function(error) {
// OK to close here:
console.log('transaction error: ' + error.message);
db.close();
}, function() {
// OK to close here:
console.log('transaction ok');
db.close(function() {
console.log('database is closed ok');
});
});
```
--------------------------------
### POST /groups/{groupId}/actions/assign_user
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-groups.html
Assigns or removes a list of users from a specified group.
```APIDOC
## POST /groups/{groupId}/actions/assign_user
### Description
This API is used to assign a list of users to a group or remove a list of users from a group.
### Method
POST
### Endpoint
/groups/{groupId}/actions/assign_user
### Parameters
#### Path Parameters
- **groupId** (integer) - Required - The unique id of the group in concern
#### Request Body
- **token_key** (string) - Required - Your API key.
- **assign** (array) - Optional - An integer array of unique ids of users to be assigned to the group.
- **remove** (array) - Optional - An integer array of unique ids of users to be removed from the group.
### Response
#### Success Response (200)
- **group_id** (integer) - The unique id of the group in concern.
- **assigned_users** (array) - An integer array of unique user ids successfully assigned to the group.
- **removed_users** (array) - An integer array of unique user ids successfully removed from the group.
- **invalid_users** (array) - An integer array of unique user ids that are not valid.
- **failed_users** (array) - An integer array of unique id of users on which the operation of assigning/removing failed.
```
--------------------------------
### DronaHQ.user.getProfile(fnSuccess, fnError)
Source: https://sdk.dronahq.com/en/stable/developer/api-device-user.html
Retrieves the profile object of the user currently logged into the application.
```APIDOC
## DronaHQ.user.getProfile(fnSuccess, fnError)
### Description
This method retrieves the profile object of the user currently logged into the app.
### Parameters
- **fnSuccess** (function) - Required - Callback function executed on success, receiving the user profile object.
- **fnError** (function) - Required - Callback function executed on failure, receiving the error object.
### User Profile Object
- **uid** (integer) - User ID of the user currently signed-in.
- **name** (string) - Full name of the user currently signed-in.
- **email** (object) - Email ID of the user currently signed-in.
- **designation** (string) - Designation of the user currently signed-in.
- **profile_image** (object) - URL of the profile image.
- **nonce** (function) - A random string.
### Example
```javascript
var fnSuccess = function(uData){
console.log('User ID: ' + uData.uid);
console.log('User Name: ' + uData.name);
};
var fnError = function(err){
console.error('Failed to load user info. Error: ' + err);
};
DronaHQ.user.getProfile(fnSuccess, fnError);
```
```
--------------------------------
### PUT /users/{userId}/actions/change_group
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Assigns or removes a list of groups for a specific user.
```APIDOC
## PUT /users/{userId}/actions/change_group
### Description
This API can be used to assign a list of groups to a user and can also be used to remove a list of groups assigned to a user.
### Method
PUT
### Endpoint
/users/{userId}/actions/change_group
### Parameters
#### Path Parameters
- **userId** (integer) - Required - The unique id of the user.
#### Request Body
- **token_key** (string) - Required - Your API key.
- **assign** (array) - Optional - An integer array of unique ids of groups to be assigned to the user.
- **remove** (array) - Optional - An integer array of unique ids of groups to be removed from the user.
### Response
#### Success Response (200)
- **user_id** (integer) - The unique id of the user.
- **assigned_to** (array) - An integer array of unique group ids to which the user was successfully assigned.
- **removed_from** (array) - An integer array of unique group ids from where the user was successfully removed.
- **invalid_groups** (array) - An integer array of unique group ids that are not valid.
- **failed_groups** (array) - An integer array of unique id of groups on which the operation of assigning/removing failed.
```
--------------------------------
### DELETE /users
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Deactivates users based on the provided token key and list of email addresses.
```APIDOC
## DELETE /users
### Description
Deactivates users based on the scope of the tokenkey.
### Method
DELETE
### Endpoint
/users
### Parameters
#### Request Body
- **token_key** (string) - Required - Your API key.
- **list_user_email** (array) - Required - A string array of the users email. A maximum of 50 IDs can be sent in one request.
### Response
#### Success Response (200)
- **users_success** (integer) - A string array of user email whose account has been successfully deactivated.
- **users_invalid** (array) - A string array of invalid user email.
- **user_not_exist** (array) - A string array of user not found in the API key scope.
- **users_failed** (array) - A string array of user email on which the operation of deactivation failed.
```
--------------------------------
### Access uploadcomplete event
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sync.html
Reference to the event triggered when the sync service finishes processing the queue.
```javascript
DronaHQ.sync.uploadcomplete
```
--------------------------------
### Retrieve a specific notification
Source: https://sdk.dronahq.com/en/stable/developer/api-device-notification.html
Uses a query parameter to fetch notification data by ID. Requires defining success and error callback functions.
```javascript
//Get the notification id from query string
function getQParameter(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var notiId = getQParameter('dm_noti_id');
var fnSuccess = function(notiData){
//notiData contains the JSON object
//that was sent using platform notification API
console.log(notiData);
};
var fnError = function(e){
if(e.code == '1'){
console.log('Invaid Notification ID');
}
};
DronaHQ.notification.getNotification(notid, fnSuccess, fnError);
```
--------------------------------
### db.executeSql
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Executes a single SQL statement within a transaction.
```APIDOC
## db.executeSql
### Description
Executes a single SQL statement. This method is used for INSERT, SELECT, and other SQL operations.
### Parameters
- **sql** (string) - Required - The SQL statement to execute.
- **params** (array) - Required - An array of parameters to bind to the SQL statement.
- **successcb** (function) - Optional - Callback receiving the resultSet.
- **errorcb** (function) - Optional - Callback receiving the error object.
```
--------------------------------
### Assign or remove users from a group
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-groups.html
Use this endpoint to modify group membership by providing user IDs in the assign or remove arrays.
```http
POST /groups/{groupId}/actions/assign_user
```
--------------------------------
### Demonstrate row result object mutability
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Shows that resultSet.rows.item objects are mutable and shared across multiple calls.
```javascript
db.readTransaction(function(tx) {
tx.executeSql("SELECT UPPER('First') AS uppertext", [], function(tx, resultSet) {
var obj1 = resultSet.rows.item(0);
obj1.uppertext = 'ANOTHER';
console.log('Second uppertext result: ' + resultSet.rows.item(0).uppertext);
console.log('SELECT error: ' + error.message);
});
});
```
--------------------------------
### DronaHQ.sync.getPendingUploadCount()
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sync.html
Retrieves the total count of pending upload requests.
```APIDOC
## DronaHQ.sync.getPendingUploadCount(fnsuccess, fnerror)
### Description
Returns the number of pending upload requests currently in the queue.
### Parameters
- **fnsuccess** (function) - Callback receiving the count.
- **fnerror** (function) - Callback for errors.
### Example
```javascript
DronaHQ.sync.getPendingUploadCount(function(count){}, function(e){});
```
```
--------------------------------
### Invalid database close in executeSql callback
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Closing a database within a db.executeSql callback is currently not possible due to a known bug.
```javascript
// BROKEN DUE TO BUG:db.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (res) {
var stringlength = res.rows.item(0).stringlength;
console.log('got stringlength: ' + res.rows.item(0).stringlength);
// BROKEN - this will trigger the error callback DUE TO BUG:
db.close(function() {
console.log('database is closed ok');
}, function(error) {
console.log('ERROR closing database');
});
});
```
--------------------------------
### Invalid database close in statement callback
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Closing a database within a statement callback is not supported and will trigger an error.
```javascript
// BROKEN:db.transaction(function(tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function(tx, res) {
console.log('got stringlength: ' + res.rows.item(0).stringlength);
// BROKEN - this will trigger the error callback:
db.close(function() {
console.log('database is closed ok');
}, function(error) {
console.log('ERROR closing database');
});
});
});
```
--------------------------------
### HTTP Status Codes
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-response-status-code.html
A reference table of HTTP status codes returned by the DronaHQ API and their meanings.
```APIDOC
## HTTP Status Codes
| Status Code | Description |
|---|---|
| 200 | OK - The request has succeeded. The client can read the result of the request in the body. |
| 204 | No Content - The request has succeeded but returns no message body. |
| 400 | Bad Request - The request could not be understood by the server due to malformed syntax. |
| 401 | Unauthorized - The authorization is refused for the resource with the provided API key. |
| 403 | Forbidden - The server understood the request, but is refusing to fulfill it. |
| 404 | Not Found - The requested resource could not be found. |
| 500 | Internal Server Error. |
| 503 | Service Unavailable - The server is currently unable to handle the request due to a temporary condition. |
```
--------------------------------
### DronaHQ.notification.getAllNotification
Source: https://sdk.dronahq.com/en/stable/developer/api-device-notification.html
Retrieves a list of all unread notifications.
```APIDOC
## DronaHQ.notification.getAllNotification(fnSuccess, fnError)
### Description
Generates a list of all unread notifications. Notifications not retrieved by getNotification() are considered unread.
### Parameters
- **fnSuccess** (function) - Required - Callback function executed on success, receiving an object containing an array of notifications.
- **fnError** (function) - Required - Callback function executed on error.
```
--------------------------------
### db.close(successcb, errorcb)
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Closes the database object and invalidates all associated access handles. It is safe to call this within a transaction callback, but not within a statement callback.
```APIDOC
## db.close(successcb, errorcb)
### Description
Closes the database object and invalidates all associated access handles. Note that closing the database within a statement callback is not supported.
### Parameters
- **successcb** (function) - Optional - Callback function executed upon successful closure.
- **errorcb** (function) - Optional - Callback function executed if an error occurs during closure.
```
--------------------------------
### Assign or Remove User Groups Endpoint
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
The PUT endpoint used to modify group memberships for a user.
```http
PUT /users/{userId}/actions/change_group
```
--------------------------------
### Deactivate Users Endpoint
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-users.html
Use this endpoint to deactivate users within the scope of the provided token key.
```http
DELETE /users
```
--------------------------------
### Remove a key-value pair
Source: https://sdk.dronahq.com/en/stable/developer/api-device-kvs.html
Deletes a specific key and its associated value from storage.
```javascript
DronaHQ.KVStore.removeItem(keyName, function() {
//success callback
}, function() {
//fail callback
});
```
--------------------------------
### DronaHQ.KVStore.removeItem
Source: https://sdk.dronahq.com/en/stable/developer/api-device-kvs.html
Removes a specific key and its associated value.
```APIDOC
## DronaHQ.KVStore.removeItem(keyName, successCallback, failCallback)
### Description
Allows micro-apps to remove a key and its associated string value.
### Parameters
- **keyName** (string) - Required - The key to remove.
- **successCallback** (function) - Required - Callback executed on success.
- **failCallback** (function) - Required - Callback executed on failure.
```
--------------------------------
### Handle mutable result set rows
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Note that objects returned by resultSet.rows.item are mutable and shared across multiple calls for the same row index.
```javascript
db.executeSql("SELECT UPPER('First') AS uppertext", [], function (resultSet) {
var obj1 = resultSet.rows.item(0);
obj1.uppertext = 'ANOTHER';
console.log('Second uppertext result: ' + resultSet.rows.item(0).uppertext);
console.log('SELECT error: ' + error.message);
});
```
--------------------------------
### Retrieve all unread notifications
Source: https://sdk.dronahq.com/en/stable/developer/api-device-notification.html
Fetches a list of all notifications currently marked as unread. Notifications retrieved via getNotification are excluded from this list.
```javascript
var fnSuccess = function(data){
var unreadNotiCount = data.notifications.length;
};
var fnError = function(e){};
DronaHQ.notification.getAllNotification(fnSuccess, fnError);
```
--------------------------------
### Close a database object
Source: https://sdk.dronahq.com/en/stable/developer/api-device-sqlite.html
Closes the database connection, invalidating all associated handle objects.
```javascript
db.close(successcb, errorcb);
```
--------------------------------
### Error Response Body
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-response-status-code.html
The structure of the JSON response body returned when an API request results in an error.
```APIDOC
## Error Response Body
When an error occurs, the response body contains the following fields:
- **error** (string) - The specific error code.
- **message** (string) - A textual description of the error.
- **reason** (string) - The probable cause or reason for the error.
```
--------------------------------
### DELETE /notifications/{noti_id}
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-notification.html
Deletes a notification based on its unique ID.
```APIDOC
## DELETE /notifications/{noti_id}
### Description
Deletes a notification on the basis of notification id within the scope of its token key.
### Method
DELETE
### Endpoint
/notifications/{noti_id}
### Parameters
#### Path Parameters
- **noti_id** (integer) - Required - Unique ID of the notification to be deleted.
#### Query Parameters
- **token_key** (string) - Required - Your API key.
### Response
#### Success Response (204)
- No content returned.
```
--------------------------------
### DronaHQ.notification.getNotification
Source: https://sdk.dronahq.com/en/stable/developer/api-device-notification.html
Retrieves notification data based on a specific notification ID.
```APIDOC
## DronaHQ.notification.getNotification(notid, fnSuccess, fnError)
### Description
Retrieves notification data based on a provided notification ID. The success callback receives the JSON object associated with the notification.
### Parameters
- **notid** (string) - Required - The unique identifier of the notification.
- **fnSuccess** (function) - Required - Callback function executed on success, receiving the notification data object.
- **fnError** (function) - Required - Callback function executed on error, receiving an error object with a code property.
```
--------------------------------
### Delete Notification Endpoint
Source: https://sdk.dronahq.com/en/stable/developer/api-rest-notification.html
Use this DELETE request to remove a notification from a user's inbox using its unique ID.
```http
DELETE /notifications/{noti_id}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.