-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
48 lines (41 loc) · 1.52 KB
/
Copy pathexample.js
File metadata and controls
48 lines (41 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require("dotenv").config({ path: "./process.env" });
const canary = require("./index.js"); // when using from npm use require('canarylabs-web-api')
// Basic running example
const credentials = {
username: process.env.MY_USERNAME || "default_username",
password: process.env.MY_PASSWORD || "default_password",
baseURL:
process.env.MY_BASE_URL ||
"https://yourdomain.canarylabs.online:55236/api/v2",
};
let userTokenBody = {
application: "Web API",
timezone: "Eastern Standard Time",
};
// Example usage:
(async () => {
try {
let result = await canary.getUserToken(credentials, userTokenBody);
console.log("getusertoken", result);
// Make sure browseTags returns a promise
let browseTagsResult = await canary.browseTags(credentials);
console.log("Browse tags", browseTagsResult);
// Check if browseTags was successful before calling getLiveDataToken
if (browseTagsResult) {
let liveDataResult = await canary.getLiveDataToken(credentials);
console.log("Live Data Result", liveDataResult);
if (liveDataResult) {
let liveValues = await canary.getCurrentValues(credentials, {
tags: ["Company.Site.Flow.FT1200_PV"],
});
const dataArray = liveValues.data["Company.Site.Flow.FT1200_PV"];
const firstObject = dataArray[0].v;
console.log('Flow Mater 1200:',firstObject);
}
} else {
console.log("Error in browseTags. Cannot proceed to getLiveDataToken.");
}
} catch (error) {
console.error("Error:", error);
}
})();