AngularJS Client Library

This library contains classes that make it easy to integrate BlackBerry IoT Platform services into your AngularJS app.

Download and install the SDK

To get access to this SDK, contact a representative from our sales team.

BlackBerry IoT Platform configuration

Apps connect to the cloud with an API KEY and API SECRET. To obtain these, you need to create an Application within the service and then add an API KEY and API SECRET.

Application configuration

To configure your application you'll need to add ng-cldc as an application dependency and use cldcProvider to configure the location of your authorization server:

angular
  .module('exampleApp', ['ng-cldc'])
  .config(function(cldcProvider) {
    cldcProvider.configure({
      authBase: 'http://localhost:9100/',
      // apiBase: 'https://iot.blackberry.com/api/1/'
    });
  })

It's also a good practice to load the profile of the logged in user (if there is one) when the app first starts:

  .run(function(CLDC) {
    CLDC.getUserPromise();
  });

Controller configuration

For any routes that always display user information, ensure you add a user resolver:

.config(function ($stateProvider, cldcProvider) {
  $stateProvider
    .state('blah', {
      resolve: { cldcUser: cldcProvider.resolveAuthUser() }
      ...
    });
});

The resolver can call a function (with injection) on failure, which is useful for redirecting the call when no user is logged in as shown here:

resolve: { cldcUser: cldcProvider.resolveAuthUser(function($state) { $state.go('home'); } }

With all the information above, it simplifies the process for creating a login page as shown below:

It's important to note that the route to this controller shouldn't use resolve because a login page must load when a user isn't logged in.

<h1 ng-hide="user">Please Log In</h1>
<h1 ng-show="user">Hello !</h1>

<a ng-sref="login"  ng-hide="user">Log In</a>
<a ng-sref="logout" ng-show="user">Log Out</a>
angular.module('exampleApp')
  .controller('LoginCtrl', function($scope, CLDC) {

    // Copy logged in user info (if any) to scope var for display
    $scope.user = CLDC.getUser();

    // Called by login button
    $scope.login = function() {
      CLDC.login();
    }

    // Called by logout button
    $scope.logout = function() {
      CLDC.logout();
    }

  });

Handle notifications

While the functions below should satisfy most of your app requirements, receiving notifications requires special handling because they are pushed from the server. To start listening for notifications, call startNotifications() on the CLDC service. Notification objects are then broadcasted through $rootScope. For example, here's how you would handle notifications:

// Fires for every notification
$rootScope.$on('cldc.notification', function(event, notification) {
    console.log(‘got’, notification.action, notification.type, notification.data);
});

// Disconnects if options.noReconnect is true
// By default, ng-cldc will auto reconnect with a minimum 5 second timeout
$rootScope.$on('cldc.notification.disconnected', function(event, notification) {
  toastr.info('Notifications disconnected');
});

var dataFilters = [];
var messageFilters = [];
var options = { noReconnect: false };

CLDC.startNotifications(dataFilters, messageFilters, options);

For more information about notifications, see Notifications.

How to use this SDK

After a user is logged in to your app, Restangular call can be made to the BlackBerry IoT Platform.

The calls are based on the HTTP REST APIs. For more information about the REST APIs, check out the REST documentation.

Below are examples of how to use each API.

Applications(apps)

Create an application

Devices are instances of applications that are used to connect into the system. In most cases, you would have a different application for each type of device that connects to the system. When you use this API, you can create an application. To be able to call this method, the calling device requires the app.create capability on the specified organization ('org_id').

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // AppCreate object
    var appcreate = {
      // Optional: The universally unique identifier (UUID) of the organization (UUID) that the application belongs to.
      org_id: "123e4567-e89b-12d3-a456-426655440000",
      // Required: The name of the application, such as "My Awesome App".
      name: "sample string",
      // Optional: A description of the application.
      description: "sample string"
    };

    CLDC.Restangular()
      .all("apps")
      .customPOST(appcreate)
      .then(function(response) {
        var app = JSON.parse(response.data);
        console.log(app.org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(app.name); // "sample string"
        console.log(app.description); // "sample string"
        console.log(app.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(app.created_on); // 12345
        console.log(app.tags); // [ apptag ]
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Get a list of applications

Retrieve a list of applications that belong to an organization ('org_id') or that have a specific API KEY ('api_key'). The calling device requires the app.read.by.org capability on the organization and app.read capability on the applications being listed. Don't provide both 'org_id' and 'api_key' parameters, otherwise you get a 400 response (bad request).

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("apps")
      .customGETLIST({}, null, {
        org_id: "123e4567-e89b-12d3-a456-426655440000", // The universally unique identifier (UUID) of the organization to get applications from.
        api_key: "sample string" // (DEPRECATED) The application's API KEY for a single application query.
      })
      .then(function(response) {
        var appArrayArray = JSON.parse(response.data);
        appArrayArray.forEach(function(appArray) {
          console.log(appArray.org_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(appArray.name); // "sample string"
          console.log(appArray.description); // "sample string"
          console.log(appArray.id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(appArray.created_on); // 12345
          console.log(appArray.tags); // [ apptag ]
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read an application

Read a single application based on its universally unique identifier (UUID). To be able to read an application, the calling device must have the app.read capability for the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .customGET()
      .then(function(response) {
        var app = JSON.parse(response.data);
        console.log(app.org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(app.name); // "sample string"
        console.log(app.description); // "sample string"
        console.log(app.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(app.created_on); // 12345
        console.log(app.tags); // [ apptag ]
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Update an application

Update the metadata for an application. The calling device requires the app.update capability for the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // AppUpdate object
    var appupdate = {
      // Optional: The name of the application, such as "My Awesome App".
      name: "sample string",
      // Optional: The description of the application, such as "My Awesome App does awesome things".
      description: "sample string"
    };

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .customPUT(appupdate)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Delete an application

Remove an application from the system. In addition to removing the application, this call causes all the devices for the specified application and the associated data for the devices to be removed from the system. The calling device must have the app.delete capability on the specified application to perform the action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

(DEPRECATED) Read an application API KEY and API SECRET

(DEPRECATED) Read a single application API KEY and API SECRET based on its universally unique identifier (UUID). To read the key and secret, the calling device must have the app.read.keys capability on the specified application. This API is deprecated, use GET:/apps/{id}/auth instead.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("keys")
      .customGET()
      .then(function(response) {
        var appkeys = JSON.parse(response.data);
        console.log(appkeys.api_key); // "sample string"
        console.log(appkeys.api_secret); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

(DEPRECATED) Update an application API KEY and API SECRET

(DEPRECATED) Update the API KEY and API SECRET for an application. The calling device must have the app.update.keys capability for the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // AppKeys object
    var appkeys = {
      // Required: A key, referred to as API KEY, that uniquely identifies the application during the authentication process. The authentication process is used to verify the authenticity of the application to the system.
      api_key: "sample string",
      // Required: A string, referred to as API SECRET that's used with the 'api_key' during the authentication process. Ensure that you don't share this secret and keep it secure.
      api_secret: "sample string"
    };

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("keys")
      .customPUT(appkeys)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read an application authentication information.

Read the application authentication information based on its universally unique identifier (UUID). The authentication information include the API KEY, API SECRET, redirect URI and development mode. To read application authentication, the calling device must have the app.read capability on the specified application. The redirect URI is the allowed URI in the redirect_uri of the authentication url in production mode. The authentication process is used to verify the authenticity of the application to the system.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("auth")
      .customGET()
      .then(function(response) {
        var appauthread = JSON.parse(response.data);
        console.log(appauthread.api_key); // "sample string"
        console.log(appauthread.api_secret); // "sample string"
        console.log(appauthread.redirect); // "sample string"
        console.log(appauthread.dev_mode); // true
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Update an application authentication information.

Update the application authentication information. The calling device must have the app.update capability for the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // AppAuth object
    var appauth = {
      // Optional: The redirect is the URI that is allowed as redirect_uri of the authentication url. The authentication process is used to verify the authenticity of the application to the system.
      redirect: "sample string",
      // Optional: True indicates that this application is in development mode. In this mode the redirect_uri param of the authentication url can be any url and authentication will pass. False indicates that this application is in production mode. This mode is more secure. The authentication will pass only, if the redirect_uri param of the authentication url is exactly matches the value of "redirect".
      dev_mode: true
    };

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("auth")
      .customPUT(appauth)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the data retention policies

Return all the data retention policies for the specified application. Data retention policies describe what data should be indexed and how long that data should be retained in the system. The calling device must have the data.retention.read capability for the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("data_retentions")
      .customGETLIST()
      .then(function(response) {
        var dataretentionArrayArray = JSON.parse(response.data);
        dataretentionArrayArray.forEach(function(dataretentionArray) {
          console.log(dataretentionArray.id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(dataretentionArray.app_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(dataretentionArray.category); // "component"
          console.log(dataretentionArray.standard); // "sample string"
          console.log(dataretentionArray.name); // "sample string"
          console.log(dataretentionArray.retention); // "sample string"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Create a data retention policy

Create a data retention policy in the system. Data retention policies describe what data should be indexed and how long that data should be retained in the system. The calling device must have the data.retention.create capability on the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // DataRetentionCreate object
    var dataretentioncreate = {
      // Required: The data type that this policy applies to.
        // Possible values: component,log,state,alarm
      category: "component",
      // Optional: Reserved for future use.
      standard: "sample string",
      // Required: The name of the data.
      name: "sample string",
      // Required: The number of days to store the data. The string "forever" can be used to specify to store the data indefinitely; "last_only" means to store only the most recent piece of data.
      retention: "sample string"
    };

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("data_retentions")
      .customPOST(dataretentioncreate)
      .then(function(response) {
        var dataretention = JSON.parse(response.data);
        console.log(dataretention.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(dataretention.app_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(dataretention.category); // "component"
        console.log(dataretention.standard); // "sample string"
        console.log(dataretention.name); // "sample string"
        console.log(dataretention.retention); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read a data retention policy

Read a single data retention policy. Data retention policies describe what data should be indexed and how long that data should be retained in the system. The calling device must have the data.retention.read permission for the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("data_retentions", "123e4567-e89b-12d3-a456-426655440000") // data_retention_id
      .customGET()
      .then(function(response) {
        var dataretention = JSON.parse(response.data);
        console.log(dataretention.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(dataretention.app_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(dataretention.category); // "component"
        console.log(dataretention.standard); // "sample string"
        console.log(dataretention.name); // "sample string"
        console.log(dataretention.retention); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Update a data retention policy

Update a data retention policy with new policy settings. Data retention policies describe what data should be indexed and how long that data should be retained in the system. The calling device must have the data.retention.update permission for the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // DataRetentionUpdate object
    var dataretentionupdate = {
      // Optional: The data type that this policy applies to. You can specify "component", "log", "state", and "alarm". The default is "state".
        // Possible values: component,log,state,alarm
      category: "component",
      // Optional: Reserved for future use.
      standard: "sample string",
      // Optional: The name of the data.
      name: "sample string",
      // Optional: The number of days to store the data. The string "forever" can be used to specify to store the data indefinitely; "last_only" means to store only the most recent piece of data.
      retention: "sample string"
    };

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("data_retentions", "123e4567-e89b-12d3-a456-426655440000") // data_retention_id
      .customPUT(dataretentionupdate)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Delete a data retention policy

Delete a data retention policy from the system. Data retention policies describe what data should be indexed and how long that data should be retained in the system. The calling device must have the data.retention.delete capability for the specified application.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("data_retentions", "123e4567-e89b-12d3-a456-426655440000") // data_retention_id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the capabilities for an application

Retrieve the list of capabilities. You can retrieve either the capabilities that this application has on other entities, or the capabilities that other entities have been granted on this application. Capabilities grant entities the permissions to perform certain actions on the system. Devices inherit all the capabilities of an application. The calling device must have the cap.read permission on the specified application to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("caps")
      .customGETLIST({}, null, {
        cap_type: "has", // The type of query to get a list for. You can specify "has" to get all the capabilities that the specified application has on other entities in the system. Otherwise, you can specify "grants", to get a list of all the capabilities that other entities have on this application. The default value of "grants" is used if no value is specified.

        inherit: true // Applications can inherit permissions from other entities, such as tags and organizations. Tags can be applied to the application and applications can belong to an organization. If you specify 'inherit' as "True", all the capabilities that are inherited are also returned. The default value of "False" is used if no value is specified.

      })
      .then(function(response) {
        var appcapabilityArrayArray = JSON.parse(response.data);
        appcapabilityArrayArray.forEach(function(appcapabilityArray) {
          console.log(appcapabilityArray.target_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(appcapabilityArray.cap_name); // "sample string"
          console.log(appcapabilityArray.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(appcapabilityArray.association); // "sample string"
          console.log(appcapabilityArray.expires_on); // "sample string"
          console.log(appcapabilityArray.granted_name); // "sample string"
          console.log(appcapabilityArray.granted_org_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(appcapabilityArray.granted_org_name); // "sample string"
          console.log(appcapabilityArray.granted_type); // "sample string"
          console.log(appcapabilityArray.target_name); // "sample string"
          console.log(appcapabilityArray.target_type); // "sample string"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Grant a capability on an application

Grant a capability to an entity. The created capability allows actions to be performed on the specified application. Use this method to give permissions to other entities in the system to perform actions to the specified application. The calling device must have the cap.create capability on the specified application. You can use the "List all the capabilities" from the Capabilities REST API (https://iot.blackberry.com/restdoc/#!/caps/list) to determine the valid strings that you can use.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customPUT({}, null, {
        granted_type: "app", // The type of entity that is being granted the created capability. The types can be "org" (organizations), "app" (applications), "device" (devices), "user" (users), and "tag" (tags).

        association: "same_user", // The capability association type. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

        expires_on: 9847562514 // The timestamp that indicates when the capability expires. Timestamps are 64-bit integers that represents the number of milliseconds since UNIX epoch. This number cannot be greater than 8640000000000000 (Sat, 13 Sep 275760 00:00:00 GMT).

      })
      .then(function(response) {
        var appcapability = JSON.parse(response.data);
        console.log(appcapability.target_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(appcapability.cap_name); // "sample string"
        console.log(appcapability.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(appcapability.association); // "sample string"
        console.log(appcapability.expires_on); // "sample string"
        console.log(appcapability.granted_name); // "sample string"
        console.log(appcapability.granted_org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(appcapability.granted_org_name); // "sample string"
        console.log(appcapability.granted_type); // "sample string"
        console.log(appcapability.target_name); // "sample string"
        console.log(appcapability.target_type); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Revoke a capability from the application

Remove a capability from an entity (specified using 'granted_to') on the specified application. The calling device must have the cap.delete capability on the specified application to remove a capability.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customDELETE({}, null, {
        association: "same_user" // The capability association type. The association type can be "same_user", which
  indicates to grant the capability to devices that belong to the same user.

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Add a tag to an application

Add an existing tag to an application. Before making this call, the specified tag must be created. After the tag is created, it can be applied to an application. The calling device must have the app.tag capability for the specified application and the tag.grant capability for the specified tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // tag_id
      .customPUT()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Remove a tag from an application

Remove a tag from an application. The calling device must have the app.untag capability for the specified application and the tag.grant capability for the specified tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("apps", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // tag_id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Capabilities(caps)

List all system-defined capabilities

Get the list of capabilities. This list contains the action name, the display name, and the supported targets. This list contains only system-defined capabilities and doesn't contain user-created capabilities. Since user-defined capabilities are application-specific, there is no available mechanism to discover user-defined capabilities. However, if your user-defined capabilities are granted on an entity, you can find the user-defined capabilities using the GET operation to retrieve the list of capabilities on any entity. For example, if you have an application that grants a user-defined permission, you can use the GET operation (List the capabilities for an application) and the UUID of the application to retrieve the list capabilities, which includes both system-defined and user-defined capabilities. You can use 'target_type' to determine which capabilities can be applied to a target. For example, set the 'target_type' to "file" to get the capabilities that a file entity can grant to other entities. No special capabilities are required to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("caps")
      .customGETLIST({}, null, {
        target_type: "sample string" // The target entity that the capability supports. The valid values you can enter include: "org" (organization), "app" (application), "device" (devices), "user" (users), "tag" (tags), and "firehose" (firehoses). You can also use "association" to determine the capabilities that can be granted as an association.

      })
      .then(function(response) {
        var capArrayArray = JSON.parse(response.data);
        capArrayArray.forEach(function(capArray) {
          console.log(capArray.name); // "sample string"
          console.log(capArray.display_name); // "sample string"
          console.log(capArray.supported_targets); // [ string ]
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Devices

Create a device

Call this method to create a device. If you have a manufacturing line, you can automate the process of creating devices using this method. The calling device must have the device.create capability for the application that the new device is being created on.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // DeviceCreate object
    var devicecreate = {
      // Optional: The universally unique identifier( UUID) of the user associated with the device.
      user_id: "123e4567-e89b-12d3-a456-426655440000",
      // Required: The name of the device.
      name: "sample string",
      // Optional: The description of the device.
      description: "sample string",
      // Optional: This string is a human-readable identifier for the device. For example a VIN number, MAC address, etc. This identifier differs from the UUID.
      identifier: "sample string",
      // Required: The application's UUID that this device belongs to.
      app_id: "123e4567-e89b-12d3-a456-426655440000",
      // Optional: (Deprecated) The RSA public key of the device.
      pub_key: "sample string",
      // Optional: The certificate signing request to use to create a client certificate, which can be used to authenticate access to this device.
      csr: "sample string"
    };

    CLDC.Restangular()
      .all("devices")
      .customPOST(devicecreate)
      .then(function(response) {
        var device = JSON.parse(response.data);
        console.log(device.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(device.user_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(device.description); // "sample string"
        console.log(device.private_key); // "sample string"
        console.log(device.pub_key); // "sample string"
        console.log(device.org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(device.created_on); // 12345
        console.log(device.name); // "sample string"
        console.log(device.identifier); // "sample string"
        console.log(device.app_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(device.issuer); // "sample string"
        console.log(device.version_hash); // "sample string"
        console.log(device.certificate); // "sample string"
        console.log(device.tags); // [ devicetag ]
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the devices belonging to a user

Return all the devices that are associated with the specified user. Without any additional capabilities, a user can always retrieve the list of devices that their UUID is associated with. For users to retrieve a list of devices associated with another user, they must be granted the device.read.by.user capability to perform this operation. For example, if you grant another user entity the device.read.by.user capability, the capability permits the other user to retrieve the list of devices that are associated with your UUID.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("devices")
      .customGETLIST({}, null, {
        user_id: "123e4567-e89b-12d3-a456-426655440000" // The universally unique identifier (UUID) of the user to query devices for. If this parameter is not provided, for user-based authenticated devices, the UUID of associated user from the device is used. For device-based authenticated devices, if no UUID is specified, a 400 error is returned.

      })
      .then(function(response) {
        var deviceArrayArray = JSON.parse(response.data);
        deviceArrayArray.forEach(function(deviceArray) {
          console.log(deviceArray.id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(deviceArray.user_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(deviceArray.description); // "sample string"
          console.log(deviceArray.private_key); // "sample string"
          console.log(deviceArray.pub_key); // "sample string"
          console.log(deviceArray.org_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(deviceArray.created_on); // 12345
          console.log(deviceArray.name); // "sample string"
          console.log(deviceArray.identifier); // "sample string"
          console.log(deviceArray.app_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(deviceArray.issuer); // "sample string"
          console.log(deviceArray.version_hash); // "sample string"
          console.log(deviceArray.certificate); // "sample string"
          console.log(deviceArray.tags); // [ devicetag ]
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read a device

Read a device to get its associated metadata. The calling device must have the device.read capability on the target device.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .customGET()
      .then(function(response) {
        var device = JSON.parse(response.data);
        console.log(device.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(device.user_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(device.description); // "sample string"
        console.log(device.private_key); // "sample string"
        console.log(device.pub_key); // "sample string"
        console.log(device.org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(device.created_on); // 12345
        console.log(device.name); // "sample string"
        console.log(device.identifier); // "sample string"
        console.log(device.app_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(device.issuer); // "sample string"
        console.log(device.version_hash); // "sample string"
        console.log(device.certificate); // "sample string"
        console.log(device.tags); // [ devicetag ]
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Update a device's metadata

Update the metadata for a device. The calling device must have the device.update capability for the specified device.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // DeviceUpdate object
    var deviceupdate = {
      // Optional: The UUID of the user that this device is associated with.
      user_id: "123e4567-e89b-12d3-a456-426655440000",
      // Optional: The name of the device.
      name: "sample string",
      // Optional: The description of the device.
      description: "sample string",
      // Optional: This string is a human-readable identifier for the device. For example a VIN number, MAC address, etc. This identifier differs from the UUID.
      identifier: "sample string",
      // Optional: (Deprecated) The RSA public key for the device.
      pub_key: "sample string"
    };

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .customPUT(deviceupdate)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Delete a device

Delete a device from the system. This call also deletes all associated data with the device (i.e., logs, states, etc). The calling device must have device.delete to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Sign a certificate request for a device

This method takes a Certificate Signing Request (CSR) and returns a certificate, which can be used to authenticate as this device. The caller must have the device.update capability to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // DeviceCSR object
    var devicecsr = {
      // Required: The PEM-encoded Certificate Signing Request (CSR).
      csr: "sample string"
    };

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("certificates")
      .customPOST(devicecsr)
      .then(function(response) {
        var string = JSON.parse(response.data);
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Get the list of certificates associated with a device

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("certificates")
      .customGET()
      .then(function(response) {
        var string = JSON.parse(response.data);
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Revoke a certificate for a device

This method revokes a certificate (identified by its serial number) that's associated with the device. After a certificate has been revoked, it can't be used to authenticate the device. The device.update capability is required to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("certificates", "sample string") // serial_number
      .customDELETE()
      .then(function(response) {
        var string = JSON.parse(response.data);
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the capabilities for a device

Retrieve the list of capabilities. You can retrieve either the capabilities that this device has on other entities, or the capabilities that other entities has been granted on this device. Capabilities grant entities the permissions to perform certain actions on the system. Devices inherit all the capabilities of an application. The calling device must have the cap.read permission on the specified application to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("caps")
      .customGETLIST({}, null, {
        cap_type: "has", // The type of query to get a list for. You can specify "has" to get all the capabilities that the specified application has on other entities in the system. Otherwise, you can specify "grants", to get a list of all the capabilities that other entities have on this application. The default value of "grants" is used if no value is specified.

        inherit: true // Applications can inherit permissions from other entities, such as tags and organizations. Tags can be applied to the application and applications can belong to an organization. If you specify 'inherit' as "True", all the capabilities that are inherited are also returned. The default value of "False" is used if no value is specified.

      })
      .then(function(response) {
        var devicecapabilityArrayArray = JSON.parse(response.data);
        devicecapabilityArrayArray.forEach(function(devicecapabilityArray) {
          console.log(devicecapabilityArray.target_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(devicecapabilityArray.cap_name); // "sample string"
          console.log(devicecapabilityArray.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(devicecapabilityArray.association); // "sample string"
          console.log(devicecapabilityArray.expires_on); // "sample string"
          console.log(devicecapabilityArray.granted_name); // "sample string"
          console.log(devicecapabilityArray.granted_org_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(devicecapabilityArray.granted_org_name); // "sample string"
          console.log(devicecapabilityArray.granted_type); // "sample string"
          console.log(devicecapabilityArray.target_name); // "sample string"
          console.log(devicecapabilityArray.target_type); // "sample string"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Grant a capability on a device

Grant a capability to an entity. The created capability allows actions to be performed on the specified device. Use this method to give permissions to other entities in the system to perform actions to the specified device. The calling device must have the cap.create capability on the specified device.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customPUT({}, null, {
        granted_type: "app", // The type of entity that's being granted the capability. The types can be "org" (organizations), "app" (applications), "device" (devices), "user" (users), or "tag" (tags).

        association: "same_user", // The capability association type. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

        expires_on: 9847562514 // The timestamp that indicates when the capability expires. Timestamps are 64-bit integers that represents the number of milliseconds since UNIX epoch. This number cannot be greater than 8640000000000000 (Sat, 13 Sep 275760 00:00:00 GMT).

      })
      .then(function(response) {
        var devicecapability = JSON.parse(response.data);
        console.log(devicecapability.target_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(devicecapability.cap_name); // "sample string"
        console.log(devicecapability.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(devicecapability.association); // "sample string"
        console.log(devicecapability.expires_on); // "sample string"
        console.log(devicecapability.granted_name); // "sample string"
        console.log(devicecapability.granted_org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(devicecapability.granted_org_name); // "sample string"
        console.log(devicecapability.granted_type); // "sample string"
        console.log(devicecapability.target_name); // "sample string"
        console.log(devicecapability.target_type); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Revoke a capability from a device

Revoke a capability that an entity ('granted_to') has been granted to perform on the specified device. The calling device requires the cap.delete capability on the specified device.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customDELETE({}, null, {
        association: "same_user" // The capability association type. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Add a tag to a device

Add an existing tag to the specified device. To use this method, the calling device must have the device.tag capability on the specified device and the tag.grant capability on the specified tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // tag_id
      .customPUT()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Remove a tag from a device

Remove a previously associated tag from a device. To be able to call this method, the calling device must have the device.untag capability on the specified device and the tag.grant capability on the specified tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // tag_id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Create a data object

Allow a device to store data on the system associated with it. The data is provided in bulk format with 1-100 data points allowed. No capabilities are required to create the data, but devices can create data only for themselves.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // DataCreateData object
    var datacreatedata = {
      // Required: The name of the data.
      id: "123e4567-e89b-12d3-a456-426655440000",
      // Required: The timestamp of when the data was created. The timestamp is a 64-bit integer that represents the number of milliseconds since UNIX epoch.
      recorded_on: 12345,
      // Required: The key-value pairs of the recorded data. Nested data can be stored (keys with arrays or objects for example).
      values: { sample: true }
    };

    // DataCreateBulk object
    var datacreatebulk = {
      // Optional: Reserved for future use.
      standard: "sample string",
      // Optional: The data type. You can specify "component", "log", "state", and "alarm". The default is "state".
        // Possible values: component,log,state,alarm
      category: "component",
      // Required
      data: [ datacreatedata ]
    };

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("data")
      .customPOST(datacreatebulk)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

GET data objects

Return named data set for a device. Devices can read their own data. To read the data of other devices, the caller must have the data.read capability on the target device.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("data")
      .customGETLIST({}, null, {
        standard: "sample string", // Reserved for future use.
        category: "component", // The data type that this data applies to. The default is "state".

        limit: 12345 // The number of results to provide, max is 1000. If not set, default as 25.
      })
      .then(function(response) {
        var mdataArrayArray = JSON.parse(response.data);
        mdataArrayArray.forEach(function(mdataArray) {
          console.log(mdataArray.id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(mdataArray.standard); // "sample string"
          console.log(mdataArray.category); // "component"
          console.log(mdataArray.recorded_on); // 12345
          console.log(mdataArray.values); // { sample: true }
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read a data object

Return the named data for a device. Devices can read their own data. To read the data of other devices, the caller must have the data.read capability on the target device.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("data", "123e4567-e89b-12d3-a456-426655440000") // data_id
      .customGET({}, null, {
        standard: "sample string", // Reserved for future use.
        category: "component" // The data type that this data applies to. The default is "state".

      })
      .then(function(response) {
        var data = JSON.parse(response.data);
        console.log(data.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(data.standard); // "sample string"
        console.log(data.category); // "component"
        console.log(data.device_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(data.recorded_on); // 12345
        console.log(data.values); // { sample: true }
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Delete a data object from a device

Delete the named data object of a device. Calling devices can always delete data on themselves. To delete data on other devices, the calling device must have the data.delete capability on the target device.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("devices", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("data", "123e4567-e89b-12d3-a456-426655440000") // data_id
      .customDELETE({}, null, {
        standard: "sample string", // Reserved for future use.
        category: "component" // The type of object. You can specify "component", "log", "state", and "alarm". The default is "state".

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Firehoses

Retrieve a list of firehoses belonging to an organization

Read a list of firehoses belonging to an organization. The calling device must have the firehose.list capability on the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("firehoses")
      .customGETLIST({}, null, {
        org_id: "123e4567-e89b-12d3-a456-426655440000" // The universally unique identifier (UUID) of the organization from which to get the list of firehoses.
      })
      .then(function(response) {
        var firehoseArrayArray = JSON.parse(response.data);
        firehoseArrayArray.forEach(function(firehoseArray) {
          console.log(firehoseArray.org_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(firehoseArray.name); // "sample string"
          console.log(firehoseArray.description); // "sample string"
          console.log(firehoseArray.id); // "123e4567-e89b-12d3-a456-426655440000"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Create a firehose

Creates a data pipe that stream events and data from devices. The calling device must have the firehose.create capability on the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // FirehoseCreate object
    var firehosecreate = {
      // Optional: The organization ID (UUID) of the organization on which you wish to create a firehose.
      org_id: "123e4567-e89b-12d3-a456-426655440000",
      // Required: The name of the firehose, such as "Firehose for Application Type A".
      name: "sample string",
      // Optional: The description of the firehose, such as "This firehose reports all events and data changes from devices of Application Type A".
      description: "sample string"
    };

    CLDC.Restangular()
      .all("firehoses")
      .customPOST(firehosecreate)
      .then(function(response) {
        var firehose = JSON.parse(response.data);
        console.log(firehose.org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(firehose.name); // "sample string"
        console.log(firehose.description); // "sample string"
        console.log(firehose.id); // "123e4567-e89b-12d3-a456-426655440000"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read a firehose

Read a single firehose based on its universally unique identifier (UUID). The calling device must have the firehose.read capability on the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .customGET()
      .then(function(response) {
        var firehose = JSON.parse(response.data);
        console.log(firehose.org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(firehose.name); // "sample string"
        console.log(firehose.description); // "sample string"
        console.log(firehose.id); // "123e4567-e89b-12d3-a456-426655440000"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Update the metadata for a firehose

Update the metadata for a firehose. The calling device must have the firehose.update capability on the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // FirehoseUpdate object
    var firehoseupdate = {
      // Optional: The name of the firehose, such as "Firehose for Application Type A".
      name: "sample string",
      // Optional: The description of the firehose, such as "This firehose reports all events and data changes from devices of Application Type A".
      description: "sample string"
    };

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .customPUT(firehoseupdate)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Delete a firehose

Remove a firehose from the system. In addition to removing the firehose, this call causes all the subscriptions for the specified firehose to be removed from the system. The calling device must have the firehose.delete capability on the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the entities that have been granted access to the firehose

Retrieve the entities (organizations, applications, users, devices and tags) that have been granted the firehose.attach capability. This capability permits devices to attach and consume event data from the firehose.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("caps")
      .customGETLIST()
      .then(function(response) {
        var firehosecapabilityArrayArray = JSON.parse(response.data);
        firehosecapabilityArrayArray.forEach(function(firehosecapabilityArray) {
          console.log(firehosecapabilityArray.target_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(firehosecapabilityArray.cap_name); // "sample string"
          console.log(firehosecapabilityArray.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Grant a capability on a firehose

Grant a capability to an entity. The created capability allows actions to be performed on the specified firehose. Use this method to give permissions to other entities in the system to perform actions to the specified firehose. The calling device must have the cap.create capability on the specified firehose.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customPUT({}, null, {
        granted_type: "app", // The type of entity that is being granted the capability. The types can be "org" (organizations), "app" (applications), "device" (devices), "user" (users), and "tag" (tags).

        expires_on: 9847562514 // The timestamp that indicates when the capability expires. Timestamps are 64-bit integers that represents the number of milliseconds since UNIX epoch. This number cannot be greater than 8640000000000000 (Sat, 13 Sep 275760 00:00:00 GMT).

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Revoke a capability from the firehose

Remove a capability from an entity (specified using 'granted_to') on the specified firehose. The calling device must have the cap.delete capability on the specified firehose to remove a capability.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the subscriptions of a firehose

Returns all the subscriptions for the specified firehose. The calling device must have the firehose.subscription.list capability on the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("subscriptions")
      .customGETLIST()
      .then(function(response) {
        var subscriptionArrayArray = JSON.parse(response.data);
        subscriptionArrayArray.forEach(function(subscriptionArray) {
          console.log(subscriptionArray.id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(subscriptionArray.firehose_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(subscriptionArray.scope_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(subscriptionArray.scope_type); // "sample string"
          console.log(subscriptionArray.scope_name); // "sample string"
          console.log(subscriptionArray.event_type); // "sample string"
          console.log(subscriptionArray.event_filter); // "sample string"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Create a subscription

Creates a subscription for a firehose. Firehose subscriptions describe what data is streamed to the recipient. The calling device must have the firehose.subscription.create capability on the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // SubscriptionCreate object
    var subscriptioncreate = {
      // Required: The UUID of the entity the subscription is scoped to.
      scope_id: "123e4567-e89b-12d3-a456-426655440000",
      // Required: The scope type.  Valid values are "app" and "device".
      scope_type: "sample string",
      // Required: This field determines which events are streamed.  Valid values are "data", "file", "lifecycle", and "*". The life cycle events include create, delete, updates events for the scope type.
      event_type: "sample string",
      // Optional: This field narrows the stream to only data with this "matching" string.  Only applicable when the event_type is "data".
      event_filter: "sample string"
    };

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("subscriptions")
      .customPOST(subscriptioncreate)
      .then(function(response) {
        var subscription = JSON.parse(response.data);
        console.log(subscription.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(subscription.firehose_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(subscription.scope_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(subscription.scope_type); // "sample string"
        console.log(subscription.scope_name); // "sample string"
        console.log(subscription.event_type); // "sample string"
        console.log(subscription.event_filter); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read a subscription

Reads a single firehose subscription. The calling device must have the firehose.subscription.read capability on the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("subscriptions", "123e4567-e89b-12d3-a456-426655440000") // subscription_id
      .customGET()
      .then(function(response) {
        var subscription = JSON.parse(response.data);
        console.log(subscription.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(subscription.firehose_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(subscription.scope_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(subscription.scope_type); // "sample string"
        console.log(subscription.scope_name); // "sample string"
        console.log(subscription.event_type); // "sample string"
        console.log(subscription.event_filter); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Delete a subscription

Deletes a subscription from firehose. The calling device must have the firehose.subscription.delete capability for the organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("subscriptions", "123e4567-e89b-12d3-a456-426655440000") // subscription_id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Attach to a firehose

Begins streaming from the specified firehose. The calling device must have the firehose.attach capability.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("data")
      .customGET({}, null, {
        limit: 3.14579 // Limit the number of record sent at any one time (default 10000)
      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Acknowledge data received from a firehose

Acknowledge the point of event data that is received on a firehose using a token. The token specifies the starting point of where to start sending event data if the device later reconnects.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // FirehoseAck object
    var firehoseack = {
      // Required: A base64-encoded token used acknowledge a piece of event data that was received.
      token: "sample string"
    };

    CLDC.Restangular()
      .one("firehoses", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("token")
      .customPUT(firehoseack)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Messages

Retrieve messages for the authenticated device

Return the first 'limit' number of messages waiting to be delivered (not acknowledged) to the authenticated device. No capabilities are required for this action, devices can always retrieve their own messages.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("messages")
      .customGETLIST({}, null, {
        limit: 12345 // The maximum number of messages to return. You can specify a range of 1-25.

      })
      .then(function(response) {
        var messageArrayArray = JSON.parse(response.data);
        messageArrayArray.forEach(function(messageArray) {
          console.log(messageArray.type); // "sample string"
          console.log(messageArray.sender_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(messageArray.target_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(messageArray.msg_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(messageArray.watermark_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(messageArray.data); // { sample: true }
          console.log(messageArray.sent_on); // 12345
          console.log(messageArray.created_on); // 12345
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Send a message to a device

Send a message from the authenticated device to another device. The authenticated device requires the message.create.<message_type> capability (where message_type is application-specific) for the target device. For example, to send the message.create.wipe message, the device that sends the message must be granted the message.create.wipe capability on the target device.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // MessageCreate object
    var messagecreate = {
      // Required: The type of message is application-defined. For example, the message type could be message.create.wipe (to wipe the device), message.create.unlock (to unlock a door), or message.create.ping (to ping a device).
      type: "sample string",
      // Required: The UUID of the receiving or target device.
      target_id: "123e4567-e89b-12d3-a456-426655440000",
      // Optional: The timestamp when the message was sent by the device. This timestamp is a 64-bit integer that represents the number of milliseconds since UNIX epoch. There can be situations when messages are sent long before the server receives them, such as when using a proxy.
      sent_on: 12345,
      // Required: The data of the message in JSON format. The object is application-defined and created by the sending device.
      data: { sample: true }
    };

    CLDC.Restangular()
      .all("messages")
      .customPOST(messagecreate)
      .then(function(response) {
        var message = JSON.parse(response.data);
        console.log(message.type); // "sample string"
        console.log(message.sender_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(message.target_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(message.msg_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(message.watermark_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(message.data); // { sample: true }
        console.log(message.sent_on); // 12345
        console.log(message.created_on); // 12345
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Acknowledge received messages up to a watermark

Acknowledge received messages up to the watermark.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // MessageAcknowledge object
    var messageacknowledge = {
      // Optional: Each message contains an identifier. You can use that identifier to acknowledge all messages up to and including that message.
      watermark_id: "123e4567-e89b-12d3-a456-426655440000"
    };

    CLDC.Restangular()
      .all("messages")
      .customPUT(messageacknowledge)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Files

Retrieve the information about a file

Get information about a file using its universally unique identifier (UUID). The UUID for the file that can be shared with others. Information about the file includes the URL where to download the file, the filename, description of the file, when the file was created and uploaded, the size of the file, and any metadata to describe the file. The calling device must have the file.read capability to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("files", "123e4567-e89b-12d3-a456-426655440000") // id
      .customGET()
      .then(function(response) {
        var fileinfo = JSON.parse(response.data);
        console.log(fileinfo.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(fileinfo.filename); // "sample string"
        console.log(fileinfo.description); // "sample string"
        console.log(fileinfo.created_on); // 12345
        console.log(fileinfo.uploaded_on); // 12345
        console.log(fileinfo.size); // 12345
        console.log(fileinfo.metadata); // { sample: true }
        console.log(fileinfo.download_url); // "sample string"
        console.log(fileinfo.owner_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(fileinfo.owner_type); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Delete a file

Delete a previously created file. The calling device must have the file.delete capability on the specified file to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("files", "123e4567-e89b-12d3-a456-426655440000") // id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Update the metadata for a file

Update the metadata relating to a file. It isn't possible to change the file content directly. To change the file content, delete the file and recreate the file. The calling device must have the file.update capability on the specified file to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // FileUpdate object
    var fileupdate = {
      // Optional: A description for the file.
      description: "sample string",
      // Optional: A metadata for the file.
      metadata: { sample: true }
    };

    CLDC.Restangular()
      .one("files", "123e4567-e89b-12d3-a456-426655440000") // id
      .customPUT(fileupdate)
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Create a file

Create a file object in the system. You provide the file as part multipart form data with this method. Files receive a universally unique identifier (UUID) that identifies the file in the system. The calling device must have the file.create capability to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("files")
      .customPOST()
      .then(function(response) {
        var filesinfo = JSON.parse(response.data);
        console.log(filesinfo.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(filesinfo.filename); // "sample string"
        console.log(filesinfo.description); // "sample string"
        console.log(filesinfo.created_on); // 12345
        console.log(filesinfo.uploaded_on); // 12345
        console.log(filesinfo.size); // 12345
        console.log(filesinfo.metadata); // { sample: true }
        console.log(filesinfo.owner_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(filesinfo.owner_type); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Retrieve a list of files

Returns the filename, universally unique identifiers (UUIDs) of files, and other information about the files associated with the device. The calling device must have the file.read permission to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("files")
      .customGETLIST({}, null, {
        device_id: "123e4567-e89b-12d3-a456-426655440000" // The universally unique identifier (UUID) of the device to get files listed under.

      })
      .then(function(response) {
        var filesinfoArrayArray = JSON.parse(response.data);
        filesinfoArrayArray.forEach(function(filesinfoArray) {
          console.log(filesinfoArray.id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(filesinfoArray.filename); // "sample string"
          console.log(filesinfoArray.description); // "sample string"
          console.log(filesinfoArray.created_on); // 12345
          console.log(filesinfoArray.uploaded_on); // 12345
          console.log(filesinfoArray.size); // 12345
          console.log(filesinfoArray.metadata); // { sample: true }
          console.log(filesinfoArray.owner_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(filesinfoArray.owner_type); // "sample string"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Download the file contents

Return a 302, with the location of the content as the location header. For redirects, an error may occur if the client does not remove the authorization header. When this error occurs, use the 'download_url' value from the GET /files{id} route. The calling device must have the file.read capability on the specified file to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("files", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("content")
      .customGET()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the capabilities for a file

Retrieve the list of capabilities that other entities have been granted on this file. The calling device must have the cap.read capability on the specified file to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("files", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("caps")
      .customGETLIST()
      .then(function(response) {
        var filecapabilityArrayArray = JSON.parse(response.data);
        filecapabilityArrayArray.forEach(function(filecapabilityArray) {
          console.log(filecapabilityArray.target_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(filecapabilityArray.cap_name); // "sample string"
          console.log(filecapabilityArray.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(filecapabilityArray.association); // "sample string"
          console.log(filecapabilityArray.expires_on); // "sample string"
          console.log(filecapabilityArray.granted_name); // "sample string"
          console.log(filecapabilityArray.granted_org_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(filecapabilityArray.granted_org_name); // "sample string"
          console.log(filecapabilityArray.granted_type); // "sample string"
          console.log(filecapabilityArray.target_name); // "sample string"
          console.log(filecapabilityArray.target_type); // "sample string"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Grant a capability on a file

Grant a capability to an entity. The created capability allows operations to be performed on the specified file. Use this method to give capabilities to other entities in the system to perform operations on the specified file. The calling device must have the cap.create capability on the specified file. You can use the "List all the capabilities" from the Capabilities REST API (https://iot.blackberry.com/restdoc/#!/caps/list) to determine the valid capabilities that you can use.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("files", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customPUT({}, null, {
        granted_type: "app", // The type of entity that's being granted. The types can be "org" (organizations), "app" (applications), "device" (devices), "user" (users), and "tag" (tags).

        association: "same_user", // The capability association type.
        expires_on: 9847562514 // The timestamp that indicates when the capability expires. Timestamps are 64-bit integers that represents the number of milliseconds since UNIX epoch. This number cannot be greater than 8640000000000000 (Sat, 13 Sep 275760 00:00:00 GMT).

      })
      .then(function(response) {
        var filecapability = JSON.parse(response.data);
        console.log(filecapability.target_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(filecapability.cap_name); // "sample string"
        console.log(filecapability.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(filecapability.association); // "sample string"
        console.log(filecapability.expires_on); // "sample string"
        console.log(filecapability.granted_name); // "sample string"
        console.log(filecapability.granted_org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(filecapability.granted_org_name); // "sample string"
        console.log(filecapability.granted_type); // "sample string"
        console.log(filecapability.target_name); // "sample string"
        console.log(filecapability.target_type); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Revoke a capability from a file

Remove a capability from an entity (granted_to) on the specified universally unique identifier (UUID) of the file. To be able to remove a capability, the calling device must have the cap.delete capability on the specified UUID of the file.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("files", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customDELETE({}, null, {
        association: "same_user" // The capability association type. The association type can be "same_user", which indicates to grant the capability to devices that belong to the same user.

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Notifications

Register for a notification stream

Any device can post to this path and it will get its own unique stream of notifications. This REST route doesn't close and continues to stay open. The route also sends keep-alive messages approximately every five minutes. The keep-alive messages are "\r\n" characters. Notifications are JSON-formatted objects that are separated with "\r\n" characters. The notifications with the "\r\n" separators are delivered on one line to make it easier to parse. To get notifications for data, the device must have data.read capability on the device where the data resides. To receive notifications for updates to files, you must have the file.read

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // DataFilter object
    var datafilter = {
      // Required: The universally unique identifier (UUID) of the device to monitor for changes.
      device_id: "123e4567-e89b-12d3-a456-426655440000",
      // Optional: The data identifier to monitor for changes on the specified 'device_id'. The identifier you choose is meaningful to your application.
      data_id: "123e4567-e89b-12d3-a456-426655440000",
      // Optional: The data type that this policy applies to. You can specify "component", "log", "state", and "alarm". The default is "state".
        // Possible values: component,log,state,alarm
      category: "component",
      // Optional: Reserved for future use.
      standard: "sample string"
    };

    // MessageFilter object
    var messagefilter = {
      // Optional: The message type to filter. The message type you specify is what you receive a notification for. If you filter for a message called message.create.ping, your would get a notification each time your device is sent a message of that type.
      type: "sample string"
    };

    // FileFilter object
    var filefilter = {
      // Optional: The universally unique identifier (UUID) of the device to monitor for changes.
      device_id: "123e4567-e89b-12d3-a456-426655440000"
    };

    // NotificationFilter object
    var notificationfilter = {
      // Optional
      data_filters: [ datafilter ],
      // Optional
      message_filters: [ messagefilter ],
      // Optional
      file_filters: [ filefilter ]
    };

    CLDC.Restangular()
      .all("notifications")
      .customPOST(notificationfilter)
      .then(function(response) {
        var notificationArrayArray = JSON.parse(response.data);
        notificationArrayArray.forEach(function(notificationArray) {
          console.log(notificationArray.type); // "message"
          console.log(notificationArray.action); // "new"
          console.log(notificationArray.data); // { sample: true }
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Organizations(orgs)

Retrieve the information of an organization

Retrieve the information of an organization. The capability organization.read is required to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .customGET()
      .then(function(response) {
        var org = JSON.parse(response.data);
        console.log(org.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(org.name); // "sample string"
        console.log(org.tags); // [ orgtag ]
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Add a user to an organization

Organizations can have many users inside them. Organizations are created by one user who is automatically tagged as an administer for that new organization. That administrator can add more users using this method. Before a user can be added to an organization, the user must exist in the system. The caller must have the user.add.org capability to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // user_id
      .customPUT()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Remove a user from an organization

Remove a user from an organization. The caller must have the user.remove.org capability to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // user_id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Add a user to an organization using their email

Add a user to an organization using their email. The calling device must have the user.add.org capability to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("invite", "sample string") // email
      .customPUT()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Add a tag to an organization

Add a tag to an organization. Tags can have permissions applied to them. Using a tag on an organization allows you to grant permissions to that organization. To be able to call this method, the calling device must have the organization.tag capability on the target organization and the tag.grant permission on the tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // tag_id
      .customPUT()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Remove a tag from an organization

Remove a tag from an organization. To be able to call this method the calling device must have the organization.tag capability on the organization and the tag.grant capability on the tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // tag_id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the capabilities for an organization

Retrieve the list of capabilities. You can retrieve either the capabilities that this organization has on other entities, or the capabilities that other entities have been granted on this organization. Capabilities grant entities the permissions to perform certain actions on the system. The calling device must have the cap.read permission on the specified organization to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("caps")
      .customGETLIST({}, null, {
        cap_type: "has", // The type of capability. You can use "has" to get the list capabilities the user has; or use "grants" to retrieve the list of capabilities that the user has granted to other entities.

        inherit: true // Organizations can inherit permissions from other entities, such as tags. Tags can be applied to the organization. If you specify 'inherit' as "true", all the capabilities are inherited through those entities.

      })
      .then(function(response) {
        var orgcapabilityArrayArray = JSON.parse(response.data);
        orgcapabilityArrayArray.forEach(function(orgcapabilityArray) {
          console.log(orgcapabilityArray.target_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(orgcapabilityArray.cap_name); // "sample string"
          console.log(orgcapabilityArray.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Grants capability on an organization

Grant a capability to an entity. The created capability allows actions to be performed on the specified organization. Use this method to give permissions to other entities in the system to perform actions to the specified organization. The calling device must have the cap.create capability on the specified organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customPUT({}, null, {
        granted_type: "org", // The type of entity that's being granted the created capability. The types can be "org" (organizations), "app" (applications), "device" (devices), "user" (users), and "tag" (tags).

        association: "same_user", // The association type for the created capability. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

        expires_on: 9847562514 // The timestamp that indicates when the capability expires. Timestamps are 64-bit integers that represents the number of milliseconds since UNIX epoch. This number cannot be greater than 8640000000000000 (Sat, 13 Sep 275760 00:00:00 GMT).

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Revoke a capability from an organization

Revoke a capability from an organization. The cap.delete capability is required to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("orgs", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customDELETE({}, null, {
        association: "same_user" // The association type for the created capability. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Perform an Elasticsearch query for an item

Return the Elasticsearch results of the provided query. The available capabilities augment this query. For information about Elasticsearch queries, see the Elasticsearch documentation at: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl.html. To get results for your search, which include devices, file metadata, or search data, you must grant the proper capability. You can grant the the search.device capability to allow information about devices to be searched, the search.file capability to allow file metadata to be searched, or the search.data capability to allow data that's saved on the platform by devices to be searched. For data, you can specify categories or specific data objects to limit what can be searched. For example, you can grant the search.data.default.alarm capability to permit only alarm categories to be searched.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // ElasticDSL object
    var elasticdsl = {
    };

    CLDC.Restangular()
      .one("search", "device") // document
      .customPOST(elasticdsl, null, {
        size: 12345, // The number of results to provide.  Sometimes it is useful to specify zero, such as when you perform faceted searches and only the count of the search is required.

        from: 12345, // Defines the offset from the first result you want to fetch.

        app_ids: "sample string", // The comma-separated list of application universally unique identifiers (UUIDs). This list specifies the scope of the search. Only data for the specified applications are searched. This parameter helps to reduce the search time significantly. It's recommended that you know the applications to search before you use this method.

        org_ids: "sample string", // A comma-separated list of organization universally unique identifiers (UUIDs). This list specifies the scope of the search. Only data for the specified organizations are searched. This parameter helps to reduce the search time significantly. It's recommended that you know the organizations to search before you use this method.

      })
      .then(function(response) {
        var elasticresult = JSON.parse(response.data);
        console.log(elasticresult.took); // 12345
        console.log(elasticresult.timed_out); // true
        console.log(elasticresult.hits); // hitsummary
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Tags

Create a tag

Create a named exposing or non-exposing tag. Non-exposing tags can be granted capabilities to perform actions on other entities. When an entity is tagged with a non-exposing tag, the capabilities are transposed to the tagged entity. This transposition causes the tagged entity to be granted the same capabilities that were granted to the tag. Exposing tags work like non-exposing tags to grant capabilities on targets. In addition, exposing tags can be targets that grant capabilities to other entities. Therefore, any capabilities that were granted by an exposing tag, as well as any capabilities granted to the tag are transposed to the tagged entity. The effect of the transposition is that the tagged entity is granted the same capabilities that were granted to the tag and the tagged entity grants the same capabilities to other entities as the tag. To create a tag, the caller must have the tag.create capability.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // TagCreate object
    var tagcreate = {
      // Required: Tags can be owned and managed by a user or by an organization. Typically, organizations create the first set of rules across their applications and can delegate some of the permission management down to the end users (e.g., users can share their location if they want to). In cases where users manage the permissions, the owner would be the user ("user"); otherwise, the owner is the organization ("org").
        // Possible values: org,user
      owner_type: "org",
      // Optional: The owner of the tag.  The owner is identified by the UUID of the organization or user. If this value isn't provided, it is determined by the caller's organization or user in the 'owner_type' property.
      owner_id: "123e4567-e89b-12d3-a456-426655440000",
      // Required: The name of the tag. This name doesn't need to be unique. Often, this name appears on the application screens to end users. For example, when you create your organization, a tag with the name of Admin is created. The user that created the organization is assigned the Admin tag.
      name: "sample string",
      // Required: A description about the tag that users and administrators can see. The description must be 4-200 characters in length.
      description: "sample string",
      // Optional: A color for the tag. The color is specified as hex triplet and starts with a hash character. If no value is specified, the default value is "#000000" (black). For more information about the values you can use, see http://en.wikipedia.org/wiki/Web_colors.
      color: "#abc",
      // Optional: An immutable value specified at creation time of the tag. When "True", the tag can be designated as the target of granted capabilities, which is known as an exposing tag. When "False", the tag can't be the target of a capability, which is known as a non-exposing tag. The advantage of using a non-exposing tag is that no additional capabilities are required. If no value is specified, the default value is "True".
      exposing: true
    };

    CLDC.Restangular()
      .all("tags")
      .customPOST(tagcreate)
      .then(function(response) {
        var tag = JSON.parse(response.data);
        console.log(tag.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(tag.owner_type); // "org"
        console.log(tag.owner_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(tag.name); // "sample string"
        console.log(tag.description); // "sample string"
        console.log(tag.color); // "#abc"
        console.log(tag.exposing); // true
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the available tags

Return a list of all the tags and the information for each tag. To get the list of tags, the caller must have the tag.read capability.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("tags")
      .customGETLIST()
      .then(function(response) {
        var tagArrayArray = JSON.parse(response.data);
        tagArrayArray.forEach(function(tagArray) {
          console.log(tagArray.id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(tagArray.owner_type); // "org"
          console.log(tagArray.owner_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(tagArray.name); // "sample string"
          console.log(tagArray.description); // "sample string"
          console.log(tagArray.color); // "#abc"
          console.log(tagArray.exposing); // true
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read a tag

Read a particular tag by its universally unique identifier (UUID). This method returns the information of a particular tag. To read a tag, the caller must have the tag.read capability.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // id
      .customGET()
      .then(function(response) {
        var tag = JSON.parse(response.data);
        console.log(tag.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(tag.owner_type); // "org"
        console.log(tag.owner_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(tag.name); // "sample string"
        console.log(tag.description); // "sample string"
        console.log(tag.color); // "#abc"
        console.log(tag.exposing); // true
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Update a tag

Update a tag with new values. To update a tag, the caller must have the tag.update capability.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    // TagUpdate object
    var tagupdate = {
      // Optional: The name of the tag. This name doesn't need to be unique. Often, this name appears on the application screens to end users. For example, when you create your organization, a tag with the name of Admin is created. The user that created the organization is assigned the Admin tag.
      name: "sample string",
      // Optional: A description about the tag that users and administrators can see.
      description: "sample string",
      // Optional: A color for the tag. The color is specified as hex triplet and starts with a hash character. For more information about values you can use, see http://en.wikipedia.org/wiki/Web_colors.
      color: "#abc"
    };

    CLDC.Restangular()
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // id
      .customPUT(tagupdate)
      .then(function(response) {
        var tagcapability = JSON.parse(response.data);
        console.log(tagcapability.target_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(tagcapability.cap_name); // "sample string"
        console.log(tagcapability.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(tagcapability.association); // "sample string"
        console.log(tagcapability.granted_name); // "sample string"
        console.log(tagcapability.granted_org_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(tagcapability.granted_org_name); // "sample string"
        console.log(tagcapability.granted_type); // "sample string"
        console.log(tagcapability.target_name); // "sample string"
        console.log(tagcapability.target_type); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Delete a tag

Delete a tag from the entity. After the tag is deleted, the tag is removed from all entities that were assigned the removed tag. To delete a tag, the caller must have the tag.delete capability.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the capabilities assigned to a tag

Retrieve the list of capabilities. You can retrieve either capabilities that this tag has on other entities, or the capabilities that other entities have been granted on this tag. Capabilities grant entities the permissions to perform certain actions on the system. The calling device must have the cap.read permission on the specified application to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("caps")
      .customGETLIST({}, null, {
        cap_type: "has", // List the capabilities assigned to the tag. You can specify "has" to get all the capabilities that the specified tag has on other entities in the system. Otherwise, you can specify "grants", to get a list of all the capabilities that other entities have on this tag. If this parameter isn't provided, the value of "grants" is used.

        inherit: true // Whether to include the capabilities the specified tag inherits from a user or organization. When this parameter is set to true, the capabilities that are inherited and granted directly to the tag are returned in the response, otherwise, only the capabilities granted to the tag are returned.

      })
      .then(function(response) {
        var tagcapabilityArrayArray = JSON.parse(response.data);
        tagcapabilityArrayArray.forEach(function(tagcapabilityArray) {
          console.log(tagcapabilityArray.target_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(tagcapabilityArray.cap_name); // "sample string"
          console.log(tagcapabilityArray.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(tagcapabilityArray.association); // "sample string"
          console.log(tagcapabilityArray.granted_name); // "sample string"
          console.log(tagcapabilityArray.granted_org_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(tagcapabilityArray.granted_org_name); // "sample string"
          console.log(tagcapabilityArray.granted_type); // "sample string"
          console.log(tagcapabilityArray.target_name); // "sample string"
          console.log(tagcapabilityArray.target_type); // "sample string"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Grant a capability on a tag

Grant a capability to another entity. The created capability allows actions to be performed on entities that are tagged with this tag. Use this method to give permissions to other entities in the system to perform actions to other entities tagged with this tag. The calling device must have the cap.create capability on the specified application and the tag must be an exposing tag. If you use this call on a non-exposing tag, you get a 400 response code.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customPUT({}, null, {
        granted_type: "org", // The type of entity that's being granted the capability. The types can be "org" (organizations), "app" (applications), "device" (devices), "user" (users), and "tag" (tags).

        association: "same_user", // The capability association type. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

        expires_on: 9847562514 // The timestamp that indicates when the capability expires. Timestamps are 64-bit integers that represents the number of milliseconds since UNIX epoch. This number cannot be greater than 8640000000000000 (Sat, 13 Sep 275760 00:00:00 GMT).

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Revoke a capability from a tag

Remove a capability from a tag. Entities that have been assigned the specified tag no longer have the specified capability. The calling device must have the cap.delete capability to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customDELETE({}, null, {
        association: "same_user" // The capability association type. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Retrieve the list of entities that match a specified tag

Retrieve the list of entities that are tagged with the specified tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("entities")
      .customGETLIST()
      .then(function(response) {
        var tagentityArrayArray = JSON.parse(response.data);
        tagentityArrayArray.forEach(function(tagentityArray) {
          console.log(tagentityArray.tag_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(tagentityArray.tagged_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(tagentityArray.type); // "sample string"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Users

Retrieve a list of users belonging to an organization

Provide a list of all users belonging to an organization.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("users")
      .customGETLIST({}, null, {
        org_id: "123e4567-e89b-12d3-a456-426655440000" // The UUID of the organization.
      })
      .then(function(response) {
        var userArrayArray = JSON.parse(response.data);
        userArrayArray.forEach(function(userArray) {
          console.log(userArray.id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(userArray.email); // "sample string"
          console.log(userArray.created_on); // 12345
          console.log(userArray.tags); // [ usertag ]
          console.log(userArray.orgs); // [ string ]
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read a user

Read a user using its universally unique identifier (UUID). The user.read capability is required to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // id
      .customGET()
      .then(function(response) {
        var user = JSON.parse(response.data);
        console.log(user.id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(user.email); // "sample string"
        console.log(user.created_on); // 12345
        console.log(user.tags); // [ usertag ]
        console.log(user.orgs); // [ string ]
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Read a user's profile

Read a user's profile information. The user.read.profile capability is required to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("profile")
      .customGET()
      .then(function(response) {
        var userprofile = JSON.parse(response.data);
        console.log(userprofile.user_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(userprofile.first_name); // "sample string"
        console.log(userprofile.last_name); // "sample string"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Add a tag to a user

Add a tag to a user. The calling device must have the user.tag capability for the specified user and the tag.grant capability for the specified tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // tag_id
      .customPUT()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Remove a tag from a user

Remove a tag from a user. The calling device must have the user.untag capability for the specified user and the tag.grant capability for the specified tag.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("tags", "123e4567-e89b-12d3-a456-426655440000") // tag_id
      .customDELETE()
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

List the capabilities of a user

Get the list of capabilities. You can retrieve either the capabilities that this user has on other entities, or the capabilities that other entities have been granted on this user. Devices that are associated with the user (i.e., the user logged into the device), inherit the capabilities when the device is granted the "inherit_user" (specified in "scope" parameter of the https://iot.blackberry.com/auth/dialog/authorize endpoint) during the authorization process. The cap.read capability is required to perform this operation.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // id
      .all("caps")
      .customGETLIST({}, null, {
        cap_type: "has", // The type of capability. You can use "has" to get the list capabilities that the user has or use "grants" to retrieve the list of capabilities that the user has granted to other entities.

        inherit: true // Applications inherit permissions from other entities, such as tags and organizations. Tags can be applied to the application and applications belong to an organization. If you specify 'inherit' as "true", all the capabilities are inherited through those entities.

      })
      .then(function(response) {
        var usercapabilityArrayArray = JSON.parse(response.data);
        usercapabilityArrayArray.forEach(function(usercapabilityArray) {
          console.log(usercapabilityArray.target_id); // "123e4567-e89b-12d3-a456-426655440000"
          console.log(usercapabilityArray.cap_name); // "sample string"
          console.log(usercapabilityArray.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
        })
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Grant a capability on a user

Grant a capability to an entity. The created capability allows actions to be performed on the specified user. Use this method to give permissions to other entities in the system to perform actions to the specified user. The calling device must have the cap.create capability on the specified user.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customPUT({}, null, {
        granted_type: "org", // The type of entity that's being granted the capability. The types can be "org" (organizations), "app" (applications), "device" (devices), "user" (users), and "tag" (tags).

        association: "same_user", // The association type for the created capability. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

        expires_on: 9847562514 // The timestamp that indicates when the capability expires. Timestamps are 64-bit integers that represents the number of milliseconds since UNIX epoch. This number cannot be greater than 8640000000000000 (Sat, 13 Sep 275760 00:00:00 GMT).

      })
      .then(function(response) {
        var usercapability = JSON.parse(response.data);
        console.log(usercapability.target_id); // "123e4567-e89b-12d3-a456-426655440000"
        console.log(usercapability.cap_name); // "sample string"
        console.log(usercapability.granted_to); // "123e4567-e89b-12d3-a456-426655440000"
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Revoke a capability from a user

Revoke a capability from a user. The cap.delete capability is required to perform this action.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .one("users", "123e4567-e89b-12d3-a456-426655440000") // id
      .one("caps", "sample string") // cap_name
      .all("123e4567-e89b-12d3-a456-426655440000") // granted_to
      .customDELETE({}, null, {
        association: "same_user" // The capability association type. The association type can be "same_user", which
 indicates to grant the capability to devices that belong to the same user.

      })
      .then(function(response) {
        console.log('Success!');
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });

Get the user id

Get the user id in the format of universally unique identifier (UUID) by providing the user email address.

Example
angular.module('exampleApp')
  .controller('MyCtrl', function(CLDC) {

    CLDC.Restangular()
      .all("users")
      .one("id", "sample string") // email
      .customGET()
      .then(function(response) {
        var string = JSON.parse(response.data);
      })
      .catch(function(err) {
        console.error('An error occurred:', err);
      });
  });