I have API access to a satellite tracking system that I use. The reports for that service are horrible, and I would like to start to using one login service for all my customers. Is there a way to pull the json data from the API into Tago.io and use the Tago dashboard for all my customer logins…
Hi @eddie , yes you can pull data from the devices that are stored in another database by using Analysis. One way is to create a script to GET data from the web service , you can create an Actions based on time to execute this Script, let’s say at every 1min or so just as an example.
Here goes the link about Analysis: https://docs.tago.io/en/articles/120-creating-analysis
And here how trigger an action based on schedule: https://docs.tago.io/en/articles/244-trigger-by-schedule
So it appears that I am far more intimidated by this than I first thought I would be.
Looking that the documentation I still can’t quite figure it. This is what’s generated by the API…{ "readings": [ { "esn": "2-32####8", "asset": { "id": 632754, "name": "Barge Test", "number": "2-32####8", "account": { "name": "Test Group" } }, "status": { "speed": "0.0", "input1": "false", "input2": "false", "heading": "0", "stopped": "true", "ignition": "false", "message_type": "Interval Location", "battery_status": "true" }, "payload": "0x**********2e00", "position": { "type": "Point", "coordinates": [ -93.******4062805, 30.******1270599 ] }, "timestamp": "2021-11-19T13:06:13.000Z", "gps_odometer": null, "political_area": "Texas" } ] }
I am not sure what or how to properly get this into the analysis.
It seems that you probably called for a GET request through your API software tool (postman, insomnia, etc…). Now you will need to implement that call into your analysis environment.
You will need to make use of a popular library for RESTful calls called AXIOS →
I’ve also developed a SAP script so you can modify and make use of it:
const { Analysis, Device, Utils } = require("@tago-io/sdk");
const axios = require('axios');
// The function myAnalysis will run when you execute your analysis
async function myAnalysis(context) {
// reads the values from the environment and saves it in the variable env_vars
const env_vars = Utils.envToJson(context.environment);
if (!env_vars.device_token)
return context.log("Missing device_token environment variable");
if (!environment.account_token) throw "Missing account_token environment var";
const account = new Account({ token: environment.account_token });
const device = new Device({ token: env_vars.device_token });
const result_from_api = axios.get("https://yourapiurl.com/test", { params: "example" })
const obj_to_save = {
variable: "api_result",
value: result_from_api,
};
await device.sendData(obj_to_save);
}
module.exports = new Analysis(myAnalysis);
// To run analysis on your machine (external)
// module.exports = new Analysis(myAnalysis, { token: "YOUR-TOKEN" });