Tago’s SDK for JavaScript Documentation¶
Device¶
In order to modify, add, delete or do anything else with the data inside buckets, it is necessary to use the device function.
To setup an device object, you need a token (that you need to get in our website). Be sure to use tokens with the correct write/read previlegies for the current function that you want to use. For example, a token with only read previlegies can’t create, modify or delete anything from a device.
.info¶
Get all information from the device
const Device = require('tago/device');
const mydev = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
mydev.info()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.insert¶
Insert a new data into a bucket. You can get more information about what information can be passed with insert in our api documentation
const Device = require('tago/device');
const mydev = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
var data = {
'variable': 'temperature',
'unit' : 'F',
'value' : 55,
'time' : '2015-11-03 13:44:33',
'location': {'lat': 42.2974279, 'lng': -85.628292}
};
mydev.insert(data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.edit¶
Edit an existing data from bucket. You can get more information about what information can be passed with edit in our api documentation
const Device = require('tago/device');
const mydev = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
var data = {
'unit' : 'C',
'value' : 12,
};
mydev.edit('57c730af5c00ce0c7046c3c2', data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.find¶
Get a list of data from bucket respecting the query options passed. You can get more information about what information can be passed with .find in our get documentation
const Device = require('tago/device');
const mydev = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
var filter = {
'variable': 'myvar',
'query': 'last_value',
'end_date': '2014-12-25 23:33:22',
'start_date': '2014-12-20 23:33:22'
};
mydev.find(filter)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.remove¶
Remove a data from the bucket. It’s possible to remove in three ways: * The last data inserted by the device * The last data inserted by device into a variable * A specific data by it ID
const Device = require('tago/device');
const mydev = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
mydev.remove()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
or
const Device = require('tago/device');
const mydev = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
mydev.remove('myvariable')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
or
const Device = require('tago/device');
const mydev = new Device('0e479db0-tag0-11e6-8888-790d555b633a');
mydev.remove('577d81ac7ee399ef1a6e98da')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
Analysis¶
It’s possible to run analysis scripts on your computer, or inside Tago server. In the follow pages, you will be instructed on how to setup an analysis on your computer, use our services, and manage any data from Tago.
If you want to get instructions about how to upload your script or how to use third-party packages inside our server, take a look at admin analysis documentation
Setting Up Analysis¶
Through analysis, it is possible to insert any calculation and manage your data from Tago in any way you want. We provide some services, such as SMS and email, but you are free to use any third party packages that you need.
To setup an analysis, you first need a analysis token. That can be retrieved from the admin analysis section..
from tago import Tago
import os
analysis_token = os.environ.get('TAGO_TOKEN_DEVICE') or 'f0ba1f34-2bec-4cba-80ba-088624e37fb2'
def func_callback(context, scope):
print "context"
print context
print "scope"
print scope
def test_socket():
s = Tago(analysis_token).analysis.run_analysis(func_callback, 0)
test_socket()
context¶
As you can setup some predefined parameters in your analysis, it’s possible to get these value from the context variable defined in the admin. It is a object, and it comes with follow properties:
PROPERTY VALUE environment All environment variables token Token of the analysis .log(/msg/) Print a message to the admin console
scope¶
Every time an action triggers a script, the variable scope will be generated. This scope will bring all others variables generated at the same time by the same event. For example, if you submit a form, together with the variable that the script is reading, the scope will return a list of all values/variable input in that form. This allows you to manipulate data in real time, and more easily the new values inserted in your bucket.
Runtime Timeout¶
Tago Analysis has a mechanism that prevents scripts from being locked in their executions by applying a timeout of 30 seconds. It means that if a script takes more than 30 seconds to be completed, Tago will abort it, and the script will not be completed.
This limitation doesn’t apply when running the analyze from your own machine. Check the information below to learn how to run scripts from an external server (e.g. from your own computer).
Running in your machine¶
You always have the option to run your script from your own machine or from Tago server without any technical difference. When running the script from your machine, you will need to install all the packages used by your analysis by using the command npm install mypackage.
Be sure to set your analysis configuration with the option to run the script from “external”. And finally, get the analysis token from the same configuration screen, and put it on the second parameter when calling new Analysis. Check out this example:
module.exports = new Analysis(myanalysis, ‘c89f0d50-38e2-11e6-966e-b94d760acc7d’);
Tago-Builder and Using Another Packages¶
When you are programming, it can be useful to use another packages inside your code; Or you may want to organize your project using require and subfoulders.
Also, Tago only accepts one single .js file when uploading your script to our servers. ago provides a builder CLI that can build your entire project and generate a single .js file with the whole code. You can access the repository clicking here
To use our Tago-Builder, follow the following steps:
- Type in your terminal `npm install -g tago-builder`
- Wait it for the installation to be completed
- Type in your terminal `tago-builder ‘my script’.js ‘new name’.tago.js (the last parameter is optional).
- Upload the generated ‘my script’.tago.js file to Tago.
If everything is okay, a new file called ‘my script’.tago.js will be generated. Now you can upload this file to Tago!
Services¶
We provide some functions that can greatly help your application. When creating a analysis, you are can use Tago services on your own, just make sure you understand the policies and cost associate with the usage.
When setting up a service, you need to pass an analysis-token. For convenience, the context returns a property token that you can use to setup a service object.
from tago import Tago
from tago.services.sms import SMS as sms
import os
TOKEN = os.environ.get('TAGO_TOKEN_ANALYSIS') or 'f0ba1f34-2bec-4cba-80ba-088624e37fb2'
# Main function to be executed when the analysis are called
def myanalysis(context, scope) {
# Setting up a SMS service
sms = Services(context.token).sms
}
def test_analysis():
s = Tago(analysis_token).analysis.run_analysis(myanalysis, 0)
test_analysis()
sms¶
You can configure the system to send SMS directly from your analysis to yourself or your customers. Another option is to use the Actions to send SMS.
Some costs may occur when using the SMS service, which varies based on the country of operation. Check pricing, terms of use, and your plan before using the SMS service.
.send¶
Whenever you need to send a sms, use .send function.
from tago import Tago
from tago.services.sms import SMS as sms
import os
TOKEN = os.environ.get('TAGO_TOKEN_ANALYSIS') or 'f0ba1f34-2bec-4cba-80ba-088624e37fb2'
# Main function to be executed when the analysis are called
def myanalysis(context, scope) {
# Setting up a SMS service
sms = Services(context.token).sms
sms.send('+11234567890', 'test tago services')
}
def test_analysis():
s = Tago(analysis_token).analysis.run_analysis(myanalysis, 0)
test_analysis()
email¶
Email service allows you to send e-mail through your analysis. Cost may occur when using the e-mail service.
.send¶
Whenever you need to send an email, use .send function.
from tago import Tago
from tago.services.email import Email as email
import os
TOKEN = os.environ.get('TAGO_TOKEN_ANALYSIS') or 'f0ba1f34-2bec-4cba-80ba-088624e37fb2'
# Main function to be executed when the analysis are called
def myanalysis(context, scope) {
# Setting up a SMS service
email = Services(context.token).email
email.send('xyz@ncsu.edu', 'tago test', 'test tago services', 'xyz@ncsu.edu', '')
}
def test_analysis():
s = Tago(analysis_token).analysis.run_analysis(myanalysis, 0)
test_analysis()
Extra¶
Tago support 3party API’s to make your life easily, like Google Maps and Weather service. All 3party services below is free to use with a free token that you can get in the owner’s website.
geocoding¶
Whenever you need to get a geolocation (lat/lon) based on a valid address, or vice versa. Use geocoding function. Google Geocoding API docs: https://developers.google.com/maps/documentation/geocoding/
.getGeolocation¶
Convert the address to a valid geolocation, if it exists.
'use strict';
const Analysis = require('tago/analysis');
const Extra = require('tago/extra');
//Main function to be executed when an analysis is called
function myanalysis(context, scope) {
const api_key = 'AIzbSyCLOZEH4go819yAyszUqddIiKZs2-GpJaE'; // API that you can get in the google website
const geocoding = new Extra('geocoding', api_key);
const address = '1017 Main Campus Dr, Raleigh, NC 27606, USA';
geocoding.getGeolocation(address).then(console.log).catch(console.log);
//Print [-78.6772532,35.7704823];
}
module.exports = new Analysis(myanalysis, 'c89f0d50-38e2-11e6-966e-b94d760acc7d');
.getAddress¶
Convert a valid geolocation to an address, if it exists.
'use strict';
const Analysis = require('tago/analysis');
const Extra = require('tago/extra');
//Main function to be executed when an analysis is called
function myanalysis(context, scope) {
const api_key = 'AIzbSyCLOZEH4go819yAyszUqddIiKZs2-GpJaE'; // API that you can get in the google website
const geocoding = new Extra('geocoding', api_key);
const geolocation = '35.7704823,-78.6772532';
geocoding.getAddress(geolocation).then(console.log).catch(console.log);
//Print '1017 Main Campus Dr, Raleigh, NC 27606, USA';
}
module.exports = new Analysis(myanalysis, 'c89f0d50-38e2-11e6-966e-b94d760acc7d');
currency¶
Check several currencies in real-time, and the historical exchange rates for more than 168 countries. Currency API: https://currencylayer.com/
.convert¶
Return the current exchange rate of one currency to another one.
'use strict';
const Analysis = require('tago/analysis');
const Extra = require('tago/extra');
//Main function to be executed when the analysis is called
function myanalysis(context, scope) {
const api_key = '0aa94a3590d5068eb6830d1bf2222d21-GpJaE'; // API that you can get in the currencylayer website
const currency = new Extra('currency', api_key);
const from = 'USD';
const to = 'BRL';
currency.convert(from, to).then(console.log).catch(console.log);
//Print Example: 3.29883848
}
module.exports = new Analysis(myanalysis, 'c89f0d50-38e2-11e6-966e-b94d760acc7d');
distance¶
Whenever you need to calculate the distance between two points use distance service. Google Distance API docs: https://developers.google.com/maps/documentation/distance-matrix/intro
.measure¶
Measure is a service that provides the travel distance and time for a matrix of origins and destinations.
'use strict';
const Analysis = require('tago/analysis');
const Extra = require('tago/extra');
//Main function to be executed when analysis are called
function myanalysis(context, scope) {
const api_key = 'AIzbSyCLOZEH4go819yAyszUqddIiKZs2-GpJaE'; // API that you can get in the google website
const distance = new Extra('distance', api_key);
const origins = [ "New York, NY, USA" ];
const destinations = [ "Washington, DC, USA" ];
const language = 'EN';
const mode = 'driving';
distance.measure(origins, destinations, language, mode).then(console.log).catch(console.log);
//Print
//TODO; PUT PRINT HERE;
}
module.exports = new Analysis(myanalysis, 'c89f0d50-38e2-11e6-966e-b94d760acc7d');
weather¶
Whenever you need to get weather conditions around the world, use weather service. Wunderground API: https://www.wunderground.com/weather/api/
.current¶
Get the current weather conditions.
'use strict';
const Analysis = require('tago/analysis');
const Extra = require('tago/extra');
//Main function to be executed when the analysis is called
function myanalysis(context, scope) {
const api_key = 'c5e1c5e9dd23967a'; // API that you can get in the wunderground website
const weather = new Extra('weather', api_key);
const query = '1017 Main Campus Dr, Raleigh, NC 27606, USA'; //address
//or
query = '35.7704823,-78.6772532'; //geolocation
//or
query = '27605'; //zipcode
const full = false;
const language = "EN"
weather.current(query, full, language).then(console.log).catch(console.log);
//Print {"station_id":"KNCRALEI48","observation_time":"Last Updated on July 8, 5:40 PM EDT","observation_time_rfc822":"Fri, 08 Jul 2016 17:40:04 -0400","observation_epoch":"1468014004","local_time_rfc822":"Fri, 08 Jul 2016 17:42:43 -0400","local_epoch":"1468014163","local_tz_short":"EDT","local_tz_long":"America/New_York","local_tz_offset":"-0400","weather":"Partly Cloudy","temperature_string":"88.9 F (31.6 C)","temp_f":88.9,"temp_c":31.6,"relative_humidity":"68%","wind_string":"Calm","wind_dir":"North","wind_degrees":-9999,"wind_mph":0,"wind_gust_mph":0,"wind_kph":0,"wind_gust_kph":0,"pressure_mb":"1011","pressure_in":"29.86","pressure_trend":"-","dewpoint_string":"77 F (25 C)","dewpoint_f":77,"dewpoint_c":25,"heat_index_string":"102 F (39 C)","heat_index_f":102,"heat_index_c":39,"windchill_string":"NA","windchill_f":"NA","windchill_c":"NA","feelslike_string":"102 F (39 C)","feelslike_f":"102","feelslike_c":"39","visibility_mi":"10.0","visibility_km":"16.1","solarradiation":"--","UV":"3","precip_1hr_string":"0.00 in ( 0 mm)","precip_1hr_in":"0.00","precip_1hr_metric":" 0","precip_today_string":"0.00 in (0 mm)","precip_today_in":"0.00","precip_today_metric":"0","icon":"partlycloudy","nowcast":""}";
}
module.exports = new Analysis(myanalysis, 'c89f0d50-38e2-11e6-966e-b94d760acc7d');
.forecast¶
Returns a summary of the weather forecast for the next 10 days. This includes high and low temperatures, a string text forecast and other conditions.
'use strict';
const Analysis = require('tago/analysis');
const Extra = require('tago/extra');
//Main function to be executed when the analysis is called
function myanalysis(context, scope) {
const api_key = 'c5e1c5e9dd23967a'; // API that you can get in the wunderground website
const weather = new Extra('weather', api_key);
const query = '1017 Main Campus Dr, Raleigh, NC 27606, USA'; //address
//or
query = '35.7704823,-78.6772532'; //geolocation
//or
query = '27605'; //zipcode
const full = false;
const language = "EN"
weather.forecast(query, full, language).then(console.log).catch(console.log);
//Print array of 'current weather' for every day in the next 10 days;
}
module.exports = new Analysis(myanalysis, 'c89f0d50-38e2-11e6-966e-b94d760acc7d');
.history¶
Returns a summary of the weather conditions for the last 10 days. This includes high and low temperatures, a string text and other conditions.
'use strict';
const Analysis = require('tago/analysis');
const Extra = require('tago/extra');
//Main function to be executed when the analysis is called
function myanalysis(context, scope) {
const api_key = 'c5e1c5e9dd23967a'; // API that you can get in the wunderground website
const weather = new Extra('weather', api_key);
const date = '2016-07-07';
const query = '1017 Main Campus Dr, Raleigh, NC 27606, USA'; //address
//or
query = '35.7704823,-78.6772532'; //geolocation
//or
query = '27605'; //zipcode
const full = false;
const language = "EN"
weather.history(date, query, full, language).then(console.log).catch(console.log);
//Print array of 'current weather' for every day until reachs a specified date in the past;
}
module.exports = new Analysis(myanalysis, 'c89f0d50-38e2-11e6-966e-b94d760acc7d');
.alert¶
Returns the short name description, expiration time and a long text description of a severe alert, if one has been issued for the searched location.
'use strict';
const Analysis = require('tago/analysis');
const Extra = require('tago/extra');
//Main function to be executed when the analysis is called
function myanalysis(context, scope) {
const api_key = 'c5e1c5e9dd23967a'; // API that you can get in the wunderground website
const weather = new Extra('weather', api_key);
const query = '1017 Main Campus Dr, Raleigh, NC 27606, USA'; //address
//or
query = '35.7704823,-78.6772532'; //geolocation
//or
query = '27605'; //zipcode
const full = false;
const language = "EN"
weather.alert(query, full, language).then(console.log).catch(console.log);
//Print array of the several alerts in the last days;
}
module.exports = new Analysis(myanalysis, 'c89f0d50-38e2-11e6-966e-b94d760acc7d');
Account¶
In order to modify information in the account, dashboard, bucket, device and any other settings, it is necessary to use the device functions.
To setup an account object, you need a token that you need to get in our admin website. Make sure to use tokens with the correct write/read previlegies for the current function that you want to use. For example, a token with only read previlegies can’t create, modify or delete anything from an account.
.info¶
Get all account information
const Account = require('tago/account');
const myacc = new Account('0e479db0-tag0-11e6-8888-790d555b633a');
myacc.info()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.tokenList¶
Get all tokens from the account
const Account = require('tago/account');
const myacc = new Account('0e479db0-tag0-11e6-8888-790d555b633a');
myacc.tokenList()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.tokenCreate¶
Generate and retrieve a new token for the account
const Account = require('tago/account');
const myacc = new Account('0e479db0-tag0-11e6-8888-790d555b633a');
myacc.tokenCreate({"name":"My First Token", "expire_time": New Date()})
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.tokenDelete¶
Delete current token of the account
const Account = require('tago/account');
const myacc = new Account('0e479db0-tag0-11e6-8888-790d555b633a');
myacc.tokenDelete()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
Devices¶
Across the account function, it is possible to manage all your devices. Make sure that you use an account token with “write” permission when using functions to create, edit and delete. The Device method is completly different from the class Device, since this one can only manage devices, and can’t do anything with data related to the device.
.list¶
Retrieve a list with all devices from account
const Account = require('tago/account');
const accdevices = new Account('0e479db0-tag0-11e6-8888-790d555b633a').devices;
accdevices.list()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.create¶
Generate and retrieve a new device for the account
const Account = require('tago/account');
const accdevices = new Account('0e479db0-tag0-11e6-8888-790d555b633a').devices;
var data = {
"name":"My first device",
"description":"Creating my first device",
"active":true,
"visible":true,
"tags": [
{"key": "client", "value": "John"}
]
"configuration_params": [
{"sent": false, "key": "check_rate", "value": 600}
{"sent": false, "key": "measure_time", "value": 0}
]
};
accdevices.create(data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.edit¶
Modify any property of the device.
const Account = require('tago/account');
const accdevices = new Account('0e479db0-tag0-11e6-8888-790d555b633a').devices;
var data = {
"name":"New name for my device",
"description":"In this way I can change the description too",
"active":false,
"visible":true,
"tags": [
{"key": "client", "value": "Mark"}
]
};
accdevices.edit('576dc932415f403531fd2cf6', data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.info¶
Get information about the device
const Account = require('tago/account');
const accdevices = new Account('0e479db0-tag0-11e6-8888-790d555b633a').devices;
accdevices.info('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.delete¶
Delete device for the account
const Account = require('tago/account');
const accdevices = new Account('0e479db0-tag0-11e6-8888-790d555b633a').devices;
accdevices.delete('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.tokenList¶
Retrieve a list of all tokens of the device
const Account = require('tago/account');
const accdevices = new Account('0e479db0-tag0-11e6-8888-790d555b633a').devices;
accdevices.tokenList('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.tokenCreate¶
Generate and retrieve a new token for the device
const Account = require('tago/account');
const accdevices = new Account('0e479db0-tag0-11e6-8888-790d555b633a').devices;
accdevices.tokenCreate({"name":"My First Token", "expire_time": "never", "permission":"full"})
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.tokenDelete¶
Delete an token of the Device
const Account = require('tago/account');
const accdevices = new Account('0e479db0-tag0-11e6-8888-790d555b633a').devices;
accdevices.tokenDelete('298d17f0-7061-11e6-ab66-b174d8afb89d')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
Buckets¶
Across the account function, it is possible to manage all your buckets. Be sure to use an account token with “write” permissions when using functions like create, edit and delete.
.list¶
Retrieve a list with all buckets from account
const Account = require('tago/account');
const accbuckets = new Account('0e479db0-tag0-11e6-8888-790d555b633a').buckets;
accbuckets.list()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.create¶
Generate and retrieve a new bucket for the account
const Account = require('tago/account');
const accbuckets = new Account('0e479db0-tag0-11e6-8888-790d555b633a').buckets;
var data = {
"name":"My first bucket",
"description":"Creating my first bucket",
"visible":true,
"tags": [
{"key": "client", "value": "Francisco"}
]
};
accbuckets.create(data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.edit¶
Modify any property of the bucket.
const Account = require('tago/account');
const accbuckets = new Account('0e479db0-tag0-11e6-8888-790d555b633a').buckets;
var data = {
"name":"New name for my bucket",
"description":"This way I can change the description too",
"visible":true,
"tags": [
{"key": "client", "value": "Leonardo"}
]
};
accbuckets.edit('576dc932415f403531fd2cf6', data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.info¶
Get information about the bucket
const Account = require('tago/account');
const accbuckets = new Account('0e479db0-tag0-11e6-8888-790d555b633a').buckets;
accbuckets.info('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.delete¶
Delete bucket for the account
const Account = require('tago/account');
const accbuckets = new Account('0e479db0-tag0-11e6-8888-790d555b633a').buckets;
accbuckets.delete('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
Actions¶
Across the account function, it is possible to manage all your actions. Be sure to use an account token with “write” permissions when using functions like create, edit and delete.
.list¶
Retrieve a list with all actions from account
const Account = require('tago/account');
const accactions = new Account('0e479db0-tag0-11e6-8888-790d555b633a').actions;
accactions.list()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.create¶
Generate and retrieve a new action for the account
const Account = require('tago/account');
const accactions = new Account('0e479db0-tag0-11e6-8888-790d555b633a').actions;
var data = {
"name": "a simple action",
"description": "trigger when the variable test is higher than 2, and reset it when is less than 2",
"when_reset_bucket": "571920982c452fa00c6af660",
"when_reset_origin": "571920a5cc7d43a00c642ca1",
"when_reset_variable": "test",
"when_reset_condition": "<",
"when_reset_value": "2",
"when_set_bucket": "571920982c452fa00c6af660",
"when_set_origin": "571920a5cc7d43a00c642ca1",
"when_set_variable": "test",
"when_set_condition": ">",
"when_set_value": "2",
"type": "script",
"script": "577d4c457ee399ef1a6e6cf6",
"lock": false,
"active": true,
"tags": [
{"key":"Trigger", "value":"2"}
]
};
accactions.create(data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.edit¶
Modify any property of the action.
const Account = require('tago/account');
const accactions = new Account('0e479db0-tag0-11e6-8888-790d555b633a').actions;
var data = {
"name":"New name for my action",
"description":"In this way I can change the description too",
"visible":true,
"tags": [
{"key": "client", "value": "Mark"}
]
};
accactions.edit('576dc932415f403531fd2cf6', data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.info¶
Get information about the action
const Account = require('tago/account');
const accactions = new Account('0e479db0-tag0-11e6-8888-790d555b633a').actions;
accactions.info('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.delete¶
Delete action for the account
const Account = require('tago/account');
const accactions = new Account('0e479db0-tag0-11e6-8888-790d555b633a').actions;
accactions.delete('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
Analysis¶
Across the account function, it is possible to manage all your analysis. Be sure to use an account token with “write” permissions when using functions like create, edit and delete. The analysis method is completly different from the class analysis, since it only manages the analysis information and not the code that it runs.
.list¶
Retrieve a list with all analysis from account
const Account = require('tago/account');
const accanalysis = new Account('0e479db0-tag0-11e6-8888-790d555b633a').analysis;
accanalysis.list()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.create¶
Generate and retrieve a new analysis for the account
const Account = require('tago/account');
const accanalysis = new Account('0e479db0-tag0-11e6-8888-790d555b633a').analysis;
var data = {
"name":"My first analysis",
"description":"Creating my first analysis",
"active":true,
"interval": '1 minute',
"variables": [
{"key": "max_battery", "value": "3100"}
],
"tags": [
{"key": "client", "value": "Mark"}
]
};
accanalysis.create(data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.edit¶
Modify any property of the analysis.
const Account = require('tago/account');
const accanalysis = new Account('0e479db0-tag0-11e6-8888-790d555b633a').analysis;
var data = {
"name":"New name for my analysis",
"description":"In this way I can change the description too",
"active":false,
"interval": '2 minutes',
"variables": [
{"key": "max_battery", "value": "3000"}
],
"tags": [
{"key": "client", "value": "Mark"}
]
};
accanalysis.edit('576dc932415f403531fd2cf6', data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.info¶
Get information about the analysis
const Account = require('tago/account');
const accanalysis = new Account('0e479db0-tag0-11e6-8888-790d555b633a').analysis;
accanalysis.info('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.delete¶
Delete analysis for the account
const Account = require('tago/account');
const accanalysis = new Account('0e479db0-tag0-11e6-8888-790d555b633a').analysis;
accanalysis.delete('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.run¶
Force Analysis to run immediately
const Account = require('tago/account');
const accanalysis = new Account('0e479db0-tag0-11e6-8888-790d555b633a').analysis;
accanalysis.run('576dc932415f403531fd2cf6')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
Dashboards¶
Across the account function, it is possible to manage all your dashboards. Be sure to use an account token with “write” permissions when using functions like create, edit and delete.
.list¶
Retrieve a list with all dashboards from account
const Account = require('tago/account');
const accdashboards = new Account('0e479db0-tag0-11e6-8888-790d555b633a').dashboards;
accdashboards.list()
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.create¶
Generate and retrieve a new dashboard for the account
const Account = require('tago/account');
const accdashboards = new Account('0e479db0-tag0-11e6-8888-790d555b633a').dashboards;
var data = {
"name":"My first dashboard",
"arrangement": [
{"widget_id": "577c28d269d2861f1b2e93b8", "x":0, "y":0, "width":2, "height":3 }
]
"tags": [
{"key": "client", "value": "Mark"}
]
};
accdashboards.create(data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.edit¶
Modify any property of the dashboards.
const Account = require('tago/account');
const accdashboards = new Account('0e479db0-tag0-11e6-8888-790d555b633a').dashboards;
var data = {
"label":"New name for my dashboards",
};
accdashboards.edit('877c28d269d2861f1b2e96b8', data)
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.info¶
Get information about the dashboards
const Account = require('tago/account');
const accdashboards = new Account('0e479db0-tag0-11e6-8888-790d555b633a').dashboards;
accdashboards.info('877c28d269d2861f1b2e96b8')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});
.delete¶
Delete dashboards for the account
const Account = require('tago/account');
const accdashboards = new Account('0e479db0-tag0-11e6-8888-790d555b633a').dashboards;
accdashboards.delete('877c28d269d2861f1b2e96b8')
.then((result) => {
//You can treat the result here
})
.catch((error) => {
//You can treat errors here
});