Search…
API Module
1
import api from 'api';
Copied!

Methods

logs(options)

Queries the org's log. Very useful for creating daily activity reports, searching for access anomalies, etc.
Arguments
  • options (Object)
    • where
    • map
    • group
    • sort
    • limit
    • skip

stats(options)

Queries the org's stats.
Arguments
  • options (Object)
    • where
    • map
    • group
    • sort
    • limit
    • skip

Examples

The following example finds statistics on all the scripts that ran yesterday (does not factor in script errors or local time).Logs Example
1
import api from 'api'
2
import moment from 'moment'
3
4
5
let startId = new ObjectID(moment(new Date()).utc().subtract(1,'day').startOf('day').toDate())
6
let endId = new ObjectID(moment(new Date()).utc().subtract(1,'day').endOf('day').toDate())
7
8
return api.logs({
9
where: {
10
_id: {$gte: startId, $lte: endId},
11
src: consts.logs.sources.script
12
}
13
})
Copied!
Logs Example Response
1
{
2
"data": [
3
{
4
"_id": "59486583514ef1010000388f",
5
"beg": "2017-06-20T00:00:03.161Z",
6
"cms": 0,
7
"ctt": 0,
8
"end": "2017-06-20T00:00:03.308Z",
9
"err": {
10
"faults": []
11
},
12
"in": 0,
13
"lvl": 2,
14
"oid": "5888b91d35f8c91536c6ddea",
15
"ops": 11852,
16
"out": 0,
17
"pid": "5888b91d35f8c91536c6ddea",
18
"pis": [],
19
"pts": [],
20
"req": "59486583fc65ed0100bf97c9",
21
"sid": "589a14f9494aeb77296e4309",
22
"src": 2,
23
"stp": "job",
24
"sts": 200,
25
"trc": []
26
}
27
]
28
}
Copied!
The following example returns the login statistics for the previous two days.Stats Example
1
import api from 'api'
2
import moment from 'moment'
3
4
let starting = moment(new Date()).utc().subtract(2,'day').startOf('day').toDate()
5
6
return api.stats({
7
where: {
8
starting: {$gte: starting},
9
code: consts.stats.sources.logins
10
}
11
})
Copied!
Stats Example Response
1
{
2
"data": [
3
{
4
"_id": "59237b84967e8b6cd67ed775",
5
"active": 35,
6
"code": 3,
7
"ending": "2017-05-22T23:59:59.999Z",
8
"object": "stat",
9
"org": "58208081214454926424e515",
10
"starting": "2017-05-22T00:00:00.000Z",
11
"today": 1
12
},
13
{
14
"_id": "5924cd03967e8b6cd6bb7a52",
15
"active": 35,
16
"code": 3,
17
"ending": "2017-05-23T23:59:59.999Z",
18
"object": "stat",
19
"org": "58208081214454926424e515",
20
"starting": "2017-05-23T00:00:00.000Z",
21
"today": 1
22
}
23
]
24
}
Copied!
Last modified 2mo ago