API

ClearBlade

Build and run industrial IoT solutions anywhere

Getting started

The ClearBlade library provides all the methods necessary for interacting with the ClearBlade Platform and its resources from within a code service.

ClearBlade.js Library enables users to:

  1. Query a local or remote data collection
  2. Listen to an MQTT topic and process the payload
  3. Store data into a collection
  4. Modify devices attributes
  5. Create a timer or trigger
  6. Register new users
  7. Log users in or out

Class: ClearBlade

The available methods for the ClearBlade class and examples of how to use them are listed below:

ClearBlade.init(options)

This method sets up the ClearBlade object with a few configuration values necessary for subsequent operations against the ClearBlade Platform.

Passing the request into the init function is the simplest and most performant way to establish an authorized instance of the ClearBlade object. The ClearBlade object will inherit the permissions associated with the calling user.

Request Example:

    //In this example the passed in information on the request object is used to init the ClearBlade object
    ClearBlade.init({request:req});

To establish a new session for the ClearBlade object; the options object contains all the parameters passed into the init method. It can contain the following keys / value pairs:

Mandatory Parameters:

  • systemKey - the system key of the system you would like to access (available in req object)
  • systemSecret - the system secret of the system you would like to access (available in req object)

Optional Parameters:

  • email - the email of the user you would like to login/register for subsequent operations
  • password - the password of the user you would like to login/register for subsequent operations
  • registerUser - boolean that signifies that the email and password params should be used to register a new user with the platform. The newly registered user will be logged in
  • useUser - an object in the form of {"authToken": "userToken"} used to set the user for any ensuing operations
  • callback - a function that takes a boolean for error checking and a JSON object. Must be supplied if any of the following options are supplied: email, password,
  • registerUser. If none of the mentioned options are supplied, an anonymous token will be used for following operations.

Basic Example:

        //this example simply initializes the ClearBlade object with the desired system. 
        ClearBlade.init({
            systemKey: req.systemKey,
            systemSecret: req.systemSecret
        });

Authorization Example:

        //this example uses a users email and password to log in
        ClearBlade.init({
            systemKey: req.systemKey,
            systemSecret: req.systemSecret,
            email: "<USER_EMAIL>",
            password: "<PASSWORD>",
            callback: function(err, body) {
                if(err) {
                    resp.error("initialization error " + JSON.stringify(body));
                } else {
                    resp.success(body);
                }
            }
        });

Registration Example:

        //this example uses an email and password to register a new user with the platform
        ClearBlade.init({
            systemKey: req.systemKey,
            systemSecret: req.systemSecret,
            registerUser: true,
            email: "<USER_EMAIL>",
            password: "<USER_PASSWORD>",
            callback: function(err, body) {
                if(err) {
                    resp.error("Registration Error " + JSON.stringify(body));
                } else {
                    resp.success(body); //Returns a user token
                }
            }
        });

Pre-authed example:

        // Uses an email and auth token of a pre-authorized user - no need for a callback
        ClearBlade.init({
            systemKey: req.systemKey,
            systemSecret: req.systemSecret,
            useUser: {
                email: req.userid
                authToken: req.userToken
            }
        });

ClearBlade.setUser(email, authToken)

This method sets the user to be used for all operations against the ClearBlade Platform.

Example:

    ClearBlade.init({
        systemKey: req.systemKey,
        systemSecret: req.systemSecret
    });
    ClearBlade.setUser("userEmail", "<PASSWORD>");

ClearBlade.loginAnon(callback)

This method will log into the ClearBlade platform anonymously and use the token for subsequent requests.

Example:

    ClearBlade.init({
        systemKey: req.systemKey,
        systemSecret: req.systemSecret
    });
    ClearBlade.loginAnon(function(err, body) {
        if(err) {
            resp.error("Anonymous login failure: " + JSON.stringify(body));
        } else {
            resp.success(body); // `body` object contains Auth Token
        }
    });

ClearBlade.registerUser(email, password, callback)

This method will register a user against the ClearBlade Platform with the supplied email and password and then log them in.

Example:

    ClearBlade.init({
        systemKey: req.systemKey,
        systemSecret: req.systemSecret
    });
    ClearBlade.registerUser("<USER_EMAIL>", "<PASSWORD>", function(err, body) {
        if(err) {
            resp.error("Register user failure: " + JSON.stringify(body));
        } else {
            resp.success(body); // `body` object contains Auth Token
        }
    });

ClearBlade.isCurrentUserAuthenticated(callback)

This method is used to check and see if current users authentication token is still valid.

Example:

    ClearBlade.init({
        systemKey: req.systemKey,
        systemSecret: req.systemSecret
    });
    ClearBlade.isCurrentUserAuthenticated(function(err, body) {
        if(err) {
            resp.error("Auth check fail: " + JSON.stringify(body));
        } else {
            resp.success(body); // `body` contains a boolean value
        }
    });

ClearBlade.loginUser(email, password, callback)

This method is used to log a user into the ClearBlade Platform before making requests.

Example:

    ClearBlade.init({
        systemKey: req.systemKey,
        systemSecret: req.systemSecret
    });
    ClearBlade.loginUser("<USER_EMAIL>", "<USER_PASSWORD>", function(err, body) {
        if(err) {
            resp.error("User login failure: " + JSON.stringify(body));
        } else {
            resp.success(body); // Return an auth token
        }
    });

ClearBlade.logoutUser(callback)

This method is used to log the current user out from the platform.

Example:

    ClearBlade.init({
        systemKey: req.systemKey,
        systemSecret: req.systemSecret
    });
    ClearBlade.loginUser("<USER_EMAIL>", "<PASSWORD>", function(err, body) {
        if(err) {
            resp.error("user login fail " + JSON.stringify(body));
        } else {
            ClearBlade.logoutUser(function(e, res) {
                if(e) {
                    resp.error("user logout fail " + JSON.stringify(body));
                } else {
                    resp.success(res); // Returns {"authToken":null,"email":null}
                }
            });
        }
    });

ClearBlade.getDeviceByName(name, callback)

This method is used to retrieve a device from the Devices Auth table.

Example:

    ClearBlade.init({request: req});
    ClearBlade.getDeviceByName("Test Device", function(err, data) {
        if(err){
            resp.error("Unable to get device: " + JSON.stringify(data)
        }
        else{
            resp.success(data)
        }
    });

ClearBlade.createDevice(name, object, causeTrigger, callback)

This method is used to create a new device in the Devices Auth table.

Example:

    ClearBlade.init({request: req});

    var object = {
        "name": "deviceName",
        "type": "",
        "state": "",
        "enabled": true,
        "allow_key_auth": true,
        "allow_certificate_auth": true
    };

    ClearBlade.createDevice("Test Device", object, True, function(err, data) {
        if(err){
            resp.error("Unable to create device: " + JSON.stringify(data))
        }
        resp.success(data);
    });

ClearBlade.getAllDevicesForSystem(callback)

This method is used to retrieve all devices from the Devices Auth table

Example:

    ClearBlade.init({request: req});

    ClearBlade.getAllDevicesForSystem(function(err, data) {
        if(err){
            resp.error("Unable to get all devices: " + JSON.stringify(data))
        }
        resp.success(data) 
    });

Class: ClearBlade.Query(options);

Queries make it possible to retrieve and update data in collections based on criteria. The ClearBlade.Query object is used to rapidly create the query and ultimately perform possible fetch, update, create, and delete actions.

Dive into the Query concept: Query: Learn More

To instantiate a query object you have three options:

Here are the mutually exclusive values for the object:

  • collectionName (string) - the name of the collection you want to access
  • collectionID (string) - the ID of the collection you want to access
  • collection (string) - the ID of the collection you want to access
  1. Supply an object containing the <COLLECTION_NAME>
        var query = ClearBlade.Query({collectionName:"<COLLECTION_NAME>"});

Alternatively, the collectionID key can be used with the <COLLECTION_ID> value

        var query = ClearBlade.Query({collectionID:"<COLLECTION_ID>"});

Additionally, the <COLLECTION_ID> can be used

        var query = ClearBlade.Query("<COLLECTION_ID>");
  1. Supply nothing (this only applies when using the methods on the ClearBlade.Collection or ClearBlade.User classes to make requests against data)
        var query = ClearBlade.Query();

Query.columns([string])

This method is used to limit the columns returned by the query to the specified array of strings.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.columns(["<COLUMN_NAME_1>", "<COLUMN_NAME_2>"]);

Query.ascending(field)

This method is used to sort the response from the query by a particular field in ascending order.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.ascending("<COLUMN_NAME_1>");
    // if applicable, apply second sort for entries with same value for column 'colName'
    query.ascending("<COLUMN_NAME_2>");

Query.descending(field)

This method is used to sort the response from the query by a particular field in descending order.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.descending("<COLUMN_NAME_1>");
    // if applicable, apply second sort for entries with same value for column 'colName'
    query.descending("<COLUMN_NAME_2>");

Query.equalTo(field, value)

This method is used to filter the data by using an equality operator on a given column.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});

    // Column Type: String
    query.equalTo("<COLUMN_NAME_1>", "mustEqualThis");

    // Column Type: Boolean
    query.equalTo("<COLUMN_NAME_1>", true)     // this is valid
    query.equalTo("<COLUMN_NAME_2>", "true") 	// this is valid

    // Column Types: Int, BigInt, Float, Double
    query.equalTo("<COLUMN_NAME_2>", 100) 		// this is valid
    query.equalTo("<COLUMN_NAME_2>", "100") 	// !! this is NOT valid !!

Query.greaterThan(field, value)

This method is used to filter the data by using a greater than operator on a given column.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.greaterThan("YOUR_COLUMN_OF_TYPE_INT", 4);

Query.greaterThanEqualTo(field, value)

This method is used to filter the data by using a greater than equal to operator on a given column.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.greaterThanEqualTo("YOUR_COLUMN_OF_TYPE_INT", 4);

Query.lessThan(field, value)

This method is used to filter the data by using a less than operator on a given column.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.lessThan("YOUR_COLUMN_OF_TYPE_INT", 4);

Query.lessThanEqualTo(field, value)

This method is used to filter the data by using a less than equal to operator on a given column.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.lessThanEqualTo("YOUR_COLUMN_OF_TYPE_INT", 4);

Query.notEqualTo(field, value)

This method is used to filter the data by using a not equal to operator on a given column.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.notEqualTo("YOUR_COLUMN_OF_TYPE_STRING", "hello");

Query.matches(field, value)

This method is used to filter the data by using a regular expression against a given column.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.matches("YOUR_COLUMN_OF_TYPE_STRING", "mustContainThis");

Query.setPage(pageSize, pageNum)

This method is used to set the desired page and page size for the request.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.setPage(25, 3);

You can set the page number to 0 to retrieve all results.

    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.setPage(0, 0);

Query.or(query)

chains an existing query object to the Query object with or on the same column - "title"

   // Assume your collection's name is "Activity"
    var query1 = ClearBlade.Query({collectionName: "Activity"})
    var query2 = ClearBlade.Query({collectionName: "Activity"})

    query1.equalTo('title','Engineer')
    query2.equalTo('title','Manager')

    // If an entry has 'Engineer' or 'Manager' in 'title' column
    // they will be fetched with `finalQuery`
    var finalQuery = query1.or(query2)

chains an existing query object to the Query object with or on different columns - "title", "city"

    // Assume your collection's name is "Activity"
    var query1 = ClearBlade.Query({collectionName: "Activity"})
    var query2 = ClearBlade.Query({collectionName: "Activity"})

    query1.equalTo('title','Engineer')
    query2.equalTo('city','Austin')
    // If an entry has 'Engineer' in 'title' column
    // or 'Austin' in the 'city' column
    // they will be fetched with `finalQuery`
    var finalQuery = query1.or(query2)

Query.fetch(callback)

Reqests an item or a set of items from the query. Requires that the Query object was initialized with a collection.

    //@param {function} callback - Supplies processing for what to do with the data that is returned from the collection
   	var callback = function (err, data) {
   	    if (err) {
   	    	resp.error("fetch error : " + JSON.stringify(data));
   	    } else {
   	    	resp.success(data);
   	    }
   	};
   	var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
   	query.fetch(callback);

Query.update(changes, callback)

Updates an existing item or set of items. Requires that a collection was set when the Query was initialized.

Example:

    // @param {Object} changes - Object representing the attributes that you want changed
    // @param {function} callback - Function that handles the response of the server
    //This example assumes a collection of items that have the columns name and age.
    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    query.equalTo('name', 'John');
    var changes = {
        age: 23
    };
    var callback = function (err, data) {
        if (err) {
        	resp.error("update error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
   
    query.update(changes, callback);
    //sets John's age to 23

Query.remove(callback)

Removes an existing item or set of items. Requires that a collection was set when the Query was initialized. Example:

    //@param {function} callback Function that handles the response from the server
    var query = ClearBlade.Query({collectionName: "<COLLECTION_NAME>"});
    //This example contains the item with 'name' column entry is 'John'
    query.equalTo('name', 'John');
    var callback = function (err, data) {
        if (err) {
        	resp.error("removal error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
   
    query.remove(callback);
    //removes every item whose 'name' attribute is equal to 'John'

Class: ClearBlade.Collection(options)

To instantiate a collection object you can either supply an object containing <COLLECTION_NAME>, <COLLECTION_ID> or a string for the collectionID. Here are the mutually exclusive values for the object:

  • collectionName (string) - the name of the collection you want to access
  • collectionID (string) - the ID of the collection you want to access
  • collection (string) - the ID of the collection you want to access
    //With collectionName key and value:
    var collection = ClearBlade.Collection({collectionName: "<COLLECTION_NAME>"});
    //With collectionID key and value
    var collection = ClearBlade.Collection({collectionID:"<COLLECTION_ID>"});
    //With collectionID value
    var collection = ClearBlade.Collection("<COLLECTION_ID>");

The available methods for the Collection class and examples of how to use them are listed below:

Collection.fetch(query, callback)

Reqests an item or a set of items from the collection.

  • @param {Query} _query Used to request a specific item or subset of items from the collection on the server. Optional.
  • @param {function} callback Supplies processing for what to do with the data that is returned from the collection

Basic Example:

    var callback = function (err, data) {
        if (err) {
        	resp.error("fetch error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
   
   	var col = ClearBlade.Collection({collectionName:"<COLLECTION_NAME>"});
    col.fetch(callback);

Example with Query:

    var callback = function (err, data) {
        if (err) {
        	resp.error("fetch error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
   
   	var col = ClearBlade.Collection({collectionName:"<COLLECTION_NAME>"});
   	var query = ClearBlade.Query();
   	query.equalTo("YOUR_COLUMN_OF_TYPE_STRING", "hello");
    col.fetch(query, callback);

Collection.create(newItem, callback)

Creates a new item in the collection and returns the created item to the callback

  • @param {Object} newItem - An object that represents an item that you want to add to the collection
  • @param {function} callback - Supplies processing for what to do with the data that is returned from the collection

Example:

   	//This example assumes a collection of items that have the columns: name, height, and age.
    var newPerson = {
        name: 'Jim',
        height: 70,
        age: 32
    };
    var callback = function (err, data) {
        if (err) {
        	resp.error("creation error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
    var col = ClearBlade.Collection( {collectionName: "<COLLECTION_NAME>" } );
    col.create(newPerson, callback);
    //this inserts the the newPerson item into the collection that col represents

Collection.update(_query, changes, callback)

Updates an existing item or set of items

  • @param {Query} _query Query object to denote which items or set of Items will be changed
  • @param {Object} changes Object representing the attributes that you want changed
  • @param {function} callback Function that handles the response of the server

Example:

    //This example assumes a collection of items that have the columns name and age.
    var query = new ClearBlade.Query();
    query.equalTo('name', 'John');
    var changes = {
        age: 23
    };
    var callback = function (err, data) {
        if (err) {
        resp.error("update error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
   
   	var col = ClearBlade.Collection({collectionName:"<COLLECTION_NAME>");
    col.update(query, changes, callback);
    //sets John's age to 23

Collection.remove(_query, callback)

Removes an item or set of items from the specified collection

  • @param {Query} _query Query object that used to define what item or set of items to remove
  • @param {function} callback Function that handles the response from the server

Example:

    //This example assumes that you have a collection with the item whose 'name' attribute is 'John'
    var query = new ClearBlade.Query();
    query.equalTo('name', 'John');
    var callback = function (err, data) {
        if (err) {
        	resp.error("update error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
   
   	var col = ClearBlade.Collection({collectionName: "<COLLECTION_NAME>"});
    col.remove(query, callback);
    //removes every item whose 'name' attribute is equal to 'John'

Collection.count(_query, callback)

Retrieves the count of items in a collection that match the supplied query

  • @param {Query} _query - Query object that used to define what item or set of items to remove. Optional
  • @param {function} callback - Function that handles the response from the server

Basic Example:

   var callback = function (err, data) {
        if (err) {
        	resp.error("count error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
   
   	var col = ClearBlade.Collection({collectionName: "<COLLECTION_NAME>"});
    col.count(callback);
    //this returns an object in the form of {count: 5}

    Example with Query:

    var callback = function (err, data) {
        if (err) {
        	resp.error("count error : " + JSON.stringify(data));
        } else {
        	resp.success(data);
        }
    };
   
   	var col = ClearBlade.Collection({collectionName: "<COLLECTION_NAME>"});
   	var query = ClearBlade.Query();
   	query.equalTo("name", "John");
    col.count(query, callback);
    //this returns an object in the form of {count: 2}

Class: ClearBlade.Messaging()

To instantiate a Messaging object all you need to do is call:


    var msg = ClearBlade.Messaging();

The available methods for the Messaging class and examples of how to use them are listed below:

Messaging.getMessageHistory(topic, startTime, count, callback)

Retrieves the message history for a topic within the specified parameters.

  • @param {string} topic - String that signifies which topic to search
  • @param {Number} startTime - Number in epoch time that signifies when to start the search
  • @param {Number} count - Number that signifies how many messages to return
  • @param {function} callback - Function that handles the response from the server

Example:

    var msg = ClearBlade.Messaging();
    msg.getMessageHistory("coolTopic", 1438368131, 25, function(err, body) {
        if(err) {
            resp.error("message history error : " + JSON.stringify(data));
        } else {
            resp.success(body);
        }
    });

Message.publish(topic, payload)

Publishes to a topic.

  • @param {string} topic - Is the topic path of the message to be published. This will be sent to all listeners on the topic. No default.
  • @param {string} payload - The payload to be sent. Also no default.

Example:

    var callback = function (data) {
    	resp.success(data);
    };
    var msg = ClearBlade.Messaging();
    msg.publish("ClearBlade/is awesome! Topic","ClearBlade totally rules");

Message.getCurrentTopics(callback)

Returns the current topics for a system

  • @param {function} callback - Function that handles the response from the server

Example:


    var callback = function (err, data) {
        if(err) {
            resp.error("Unable to retrieve current topics: " + JSON.stringify(data));
        } else {
            resp.success(data);
        }
    };

    var msg = ClearBlade.Messaging();
    msg.getCurrentTopics(callback);

Message.getAndDeleteMessageHistory(topic, count, callback)

This call deletes all of the message history for mqtt topic 'topic'. But, before doing so, it gathers the last 'count' items in the history for use as the return value. If count is less than zero, all items in the message history for that topic are returned. Otherwise, the last (latest) 'count' items are returned.

The return value is a list of js objects, one for each returned item in the message history.

  • @param {string} topic - String that signifies which topic to search
  • @param {int} count - Number that signifies how many messages to return
  • @param {function} callback - Function that handles the response from the server

Example:


    var callback = function (err, data) {
        if(err) {
            resp.error("getcurrenttopics error: " + JSON.stringify(data));
        } else {
            resp.success(data);
        }
    };

    var msg = ClearBlade.Messaging();
    msg.getAndDeleteMessageHistory("TestTopic", 0, callback);

Class: ClearBlade.Code()

The code class is used to call other code services from within a service. To instantiate the code class just call:

    var code = ClearBlade.Code();

Code.execute(name, params, loggingEnabled, callback)

Executes another code service.

  • @param {string} name - String representing the name of the code service that should be executed.
  • @param {Object} params - Object that contains all the parameters that will be used for the code service. Optional.
  • @param {Boolean} loggingEnabled - Boolean that represents whether or not the code service should use logging

Class: ClearBlade User()

    var user = ClearBlade.User();
    user.getUser(function(err, data) {
        resp.success(JSON.stringify(data));
    });

This class allows for interacting with user information.

User.getUser(callback)

Returns the user table row for the user that the service is running as.

User.allUsers(query,callback)

Accepts a ClearBlade.Query object and a callback. It will return all users that match on the query. (excepting attempting to match on the password field)

User.setUsers(query,changes,callback)

operates on the users table in much the same way update works on a collection.

User.setUser(changes,callback)

updates just the user the service is running as.

User.count(query,callback)

returns a count of users who have matched the query

Events: ClearBlade Timer

ClearBlade.Timer.Create(name, options, callback)

Create a new Timer (runs a function at a set interval)

ClearBlade.Timer.Create("runValidatorEveryHour",
    {
        frequency: 3600,
        service_name: "validator"
    },
    function(err, response) {
        if (err) {
            resp.error(response)
        }
        resp.success("Timer successfully created");
    });

ClearBlade.Timer.Fetch(name, callback)

Fetch an existing Timer

timer.Update(options, callback)

ClearBlade.Timer.Fetch("runValidatorEveryHour", function (err, timer) {
        if (err) {
            resp.error(response);
        } else {
            timer.Update({def_module:"<COLLECTION_ID>",def_name:"bar"}, function (err, response){
                if (err) {
                    resp.error(response);
                }
                resp.success("Timer successfully updated");
            });
        }
    });

timer.Delete(name, callback)

ClearBlade.Timer.Fetch("runValidatorEveryHour", function (err, timer) {
        if (err) {
            resp.error(timer);
        }
        timer.Delete(function (err, response) {
            if (err) {
                resp.error(response);
            }
            resp.success("Timer deleted");
            });
    });

Events: ClearBlade Trigger

ClearBlade.Trigger.Create(name, options, callback)

Create a new Trigger (runs a service after a defined action is detected)

ClearBlade.Trigger.Create("runTestAfterPublishOnTopicFoo", {
        "def_module":      "Messaging",
        "def_name":        "Publish",
        "key_value_pairs": {topic:"foo"},
        "service_name":    "test",
    },
    function cb(err, t) {
        resp.success("OK");
    });

ClearBlade.Trigger.Fetch(name, callback)

Fetch an existing Trigger

trigger.Update(options, callback)

ClearBlade.Trigger.Fetch("runTestAfterPublishOnTopicFoo", function (err, trigger) {
        if (err) {
            resp.error(trigger);
        }
        trigger.Update({
            def_module:"COLLECTION_ID",
            def_name:"bar"
        }, function(err, response){
            if (err) {
                resp.error(response);
            }
            resp.success("Trigger updated");
        });
    });

trigger.Delete(options, callback)

ClearBlade.Trigger.Fetch("unTestAfterPublishOnTopicFoo", function(err, trigger) {
        if (err) {
            resp.error(trigger);
        }
        trigger.Delete(function(err, response) {
            if (err) {
                resp.error(response);
            }
            resp.success("Trigger deleted");
        });
    });