Skip to content

Commit 623e4e5

Browse files
committed
fix tickets paging and timeframes
1 parent d3e2d69 commit 623e4e5

2 files changed

Lines changed: 42 additions & 7 deletions

File tree

plugins/NinjaOne/v1/dataStreams/scripts/tickets.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
// Process NinjaOne ticketing board data
22
const items = (data && data.data && Array.isArray(data.data)) ? data.data : (Array.isArray(data) ? data : []);
33

4+
// Apply SquaredUp timeframe client-side: the trigger/board endpoint has no
5+
// documented date-filter syntax, so filter raw Unix-second values here before
6+
// they get converted to ISO strings below.
7+
const startTime = parseInt('{{timeframe.unixStart}}', 10);
8+
const endTime = parseInt('{{timeframe.unixEnd}}', 10);
9+
const hasTimeframe = Number.isFinite(startTime) && Number.isFinite(endTime);
10+
11+
const pickTimestamp = (item) => {
12+
const candidates = [item.updatedAt, item.lastActivityAt, item.createdAt];
13+
for (const v of candidates) {
14+
if (typeof v === 'number' && v > 1000000000 && v < 10000000000) return v;
15+
}
16+
return null;
17+
};
18+
19+
const filtered = hasTimeframe
20+
? items.filter((item) => {
21+
const ts = pickTimestamp(item);
22+
return ts !== null && ts >= startTime && ts <= endTime;
23+
})
24+
: items;
25+
426
/**
527
* Recursively converts NinjaOne Unix timestamps (seconds) to ISO strings.
6-
* @param {any} obj
28+
* @param {any} obj
729
* @returns {any}
830
*/
931
const convertTimestamps = (obj) => {
@@ -25,7 +47,7 @@ const convertTimestamps = (obj) => {
2547
return obj;
2648
};
2749

28-
result = items.map(item => {
50+
result = filtered.map(item => {
2951
const converted = convertTimestamps(item);
3052

3153
return {

plugins/NinjaOne/v1/dataStreams/tickets.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,28 @@
77
"config": {
88
"httpMethod": "post",
99
"paging": {
10-
"mode": "none"
10+
"mode": "token",
11+
"pageSize": {
12+
"realm": "body",
13+
"path": "pageSize",
14+
"value": "100"
15+
},
16+
"in": {
17+
"realm": "payload",
18+
"path": "metadata.lastCursorId"
19+
},
20+
"out": {
21+
"realm": "body",
22+
"path": "lastCursorId"
23+
}
1124
},
1225
"expandInnerObjects": true,
1326
"endpointPath": "/v2/ticketing/trigger/board/{{object.boardId}}/run",
1427
"postRequestScript": "tickets.js",
28+
"pathToData": "data",
1529
"getArgs": [],
1630
"headers": [],
17-
"postBody": {
18-
"pageSize": 100
19-
}
31+
"postBody": {}
2032
},
2133
"matches": {
2234
"sourceType": {
@@ -172,5 +184,6 @@
172184
"lastQuarter",
173185
"lastYear",
174186
"none"
175-
]
187+
],
188+
"defaultTimeframe": "last7days"
176189
}

0 commit comments

Comments
 (0)