Skip to content

Commit 8f8b225

Browse files
committed
ninjaone init
1 parent cd3067c commit 8f8b225

File tree

6 files changed

+601
-4
lines changed

6 files changed

+601
-4
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import ninjaone from "../../ninjaone.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "ninjaone-create-ticket",
6+
name: "Create Support Ticket",
7+
description: "Creates a new support ticket in NinjaOne. [See the documentation](https://app.ninjarmm.com/apidocs/?links.active=core)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
ninjaone,
12+
title: {
13+
type: "string",
14+
label: "Title",
15+
description: "Title of the support ticket",
16+
},
17+
description: {
18+
type: "string",
19+
label: "Description",
20+
description: "Description of the support ticket",
21+
},
22+
priority: {
23+
propDefinition: [
24+
ninjaone,
25+
"ticketPriority",
26+
],
27+
},
28+
assignedTechnician: {
29+
propDefinition: [
30+
ninjaone,
31+
"technician",
32+
],
33+
optional: true,
34+
},
35+
dueDate: {
36+
type: "string",
37+
label: "Due Date",
38+
description: "Due date for the support ticket. Format: YYYY-MM-DD",
39+
optional: true,
40+
},
41+
},
42+
async run({ $ }) {
43+
const response = await this.ninjaone.createSupportTicket({
44+
title: this.title,
45+
description: this.description,
46+
priority: this.priority,
47+
assignedTechnician: this.assignedTechnician,
48+
dueDate: this.dueDate,
49+
});
50+
51+
$.export("$summary", `Ticket created successfully with ID ${response.id}`);
52+
return response;
53+
},
54+
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import ninjaone from "../../ninjaone.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "ninjaone-update-device",
6+
name: "Update Device",
7+
description: "Update details for a specific device in NinjaOne. [See the documentation](https://app.ninjarmm.com/apidocs/?links.active=core)",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
ninjaone,
12+
deviceId: {
13+
propDefinition: [
14+
ninjaone,
15+
"deviceId",
16+
],
17+
},
18+
deviceAttributes: {
19+
propDefinition: [
20+
ninjaone,
21+
"deviceAttributes",
22+
],
23+
type: "string",
24+
label: "Device Attributes",
25+
description: "JSON string of attributes to update on the device",
26+
},
27+
},
28+
async run({ $ }) {
29+
const response = await this.ninjaone.updateDevice(this.deviceId, this.deviceAttributes);
30+
$.export("$summary", `Successfully updated device with ID ${this.deviceId}`);
31+
return response;
32+
},
33+
};
Lines changed: 232 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,239 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "ninjaone",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
ticketPriority: {
8+
type: "string",
9+
label: "Ticket Priority",
10+
description: "Filter support tickets by priority",
11+
async options() {
12+
const priorities = await this.getTicketPriorities();
13+
return priorities.map((priority) => ({
14+
label: priority.name,
15+
value: priority.id,
16+
}));
17+
},
18+
},
19+
ticketStatus: {
20+
type: "string",
21+
label: "Ticket Status",
22+
description: "Filter support tickets by status",
23+
async options() {
24+
const statuses = await this.getTicketStatuses();
25+
return statuses.map((status) => ({
26+
label: status.name,
27+
value: status.id,
28+
}));
29+
},
30+
},
31+
deviceGroup: {
32+
type: "string",
33+
label: "Device Group",
34+
description: "Specify the device group to monitor",
35+
async options() {
36+
const groups = await this.getDeviceGroups();
37+
return groups.map((group) => ({
38+
label: group.name,
39+
value: group.id,
40+
}));
41+
},
42+
},
43+
deviceType: {
44+
type: "string",
45+
label: "Device Type",
46+
description: "Specify the device type to monitor",
47+
async options() {
48+
const types = await this.getDeviceTypes();
49+
return types.map((type) => ({
50+
label: type.name,
51+
value: type.id,
52+
}));
53+
},
54+
},
55+
sessionType: {
56+
type: "string",
57+
label: "Session Type",
58+
description: "Filter remote access sessions by type",
59+
optional: true,
60+
async options() {
61+
const types = await this.getSessionTypes();
62+
return types.map((type) => ({
63+
label: type.name,
64+
value: type.id,
65+
}));
66+
},
67+
},
68+
technician: {
69+
type: "string",
70+
label: "Technician",
71+
description: "Filter remote access sessions by technician",
72+
optional: true,
73+
async options() {
74+
const technicians = await this.getTechnicians();
75+
return technicians.map((tech) => ({
76+
label: tech.name,
77+
value: tech.id,
78+
}));
79+
},
80+
},
81+
title: {
82+
type: "string",
83+
label: "Title",
84+
description: "Title of the support ticket",
85+
},
86+
description: {
87+
type: "string",
88+
label: "Description",
89+
description: "Description of the support ticket",
90+
},
91+
priority: {
92+
type: "string",
93+
label: "Priority",
94+
description: "Priority level of the support ticket",
95+
},
96+
assignedTechnician: {
97+
type: "string",
98+
label: "Assigned Technician",
99+
description: "Technician to assign the ticket to",
100+
optional: true,
101+
},
102+
dueDate: {
103+
type: "string",
104+
label: "Due Date",
105+
description: "Due date for the support ticket",
106+
optional: true,
107+
},
108+
deviceId: {
109+
type: "string",
110+
label: "Device ID",
111+
description: "Identifier of the device to update",
112+
},
113+
deviceAttributes: {
114+
type: "string[]",
115+
label: "Device Attributes",
116+
description: "Attributes to update on the device",
117+
},
118+
},
5119
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
120+
_baseUrl() {
121+
return "https://api.ninjaone.com/v2";
122+
},
123+
async _makeRequest(opts = {}) {
124+
const {
125+
$ = this, method = "GET", path = "/", headers, ...otherOpts
126+
} = opts;
127+
return axios($, {
128+
...otherOpts,
129+
method,
130+
url: this._baseUrl() + path,
131+
headers: {
132+
...headers,
133+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
134+
},
135+
});
136+
},
137+
async getTicketPriorities() {
138+
return this._makeRequest({
139+
path: "/ticketing/ticket-priorities",
140+
});
141+
},
142+
async getTicketStatuses() {
143+
return this._makeRequest({
144+
path: "/ticketing/ticket-statuses",
145+
});
146+
},
147+
async getDeviceGroups() {
148+
return this._makeRequest({
149+
path: "/device-groups",
150+
});
151+
},
152+
async getDeviceTypes() {
153+
return this._makeRequest({
154+
path: "/device-types",
155+
});
156+
},
157+
async getSessionTypes() {
158+
return this._makeRequest({
159+
path: "/session-types",
160+
});
161+
},
162+
async getTechnicians() {
163+
return this._makeRequest({
164+
path: "/technicians",
165+
});
166+
},
167+
async createSupportTicket({
168+
title, description, priority, assignedTechnician, dueDate,
169+
}) {
170+
return this._makeRequest({
171+
method: "POST",
172+
path: "/ticketing/ticket",
173+
data: {
174+
title,
175+
description,
176+
priority,
177+
assignedTechnician,
178+
dueDate,
179+
},
180+
});
181+
},
182+
async updateDevice(deviceId, deviceAttributes) {
183+
return this._makeRequest({
184+
method: "PATCH",
185+
path: `/device/${deviceId}`,
186+
data: JSON.parse(deviceAttributes),
187+
});
188+
},
189+
async emitNewSupportTicket({
190+
ticketPriority, ticketStatus,
191+
}) {
192+
const response = await this._makeRequest({
193+
path: "/ticketing/ticket",
194+
params: {
195+
priority: ticketPriority,
196+
status: ticketStatus,
197+
},
198+
});
199+
response.forEach((ticket) => this.$emit(ticket, {
200+
id: ticket.id,
201+
summary: `New ticket: ${ticket.title}`,
202+
ts: new Date().getTime(),
203+
}));
204+
},
205+
async emitDeviceOnline({
206+
deviceGroup, deviceType,
207+
}) {
208+
const response = await this._makeRequest({
209+
path: "/devices",
210+
params: {
211+
group: deviceGroup,
212+
type: deviceType,
213+
},
214+
});
215+
response.forEach((device) => this.$emit(device, {
216+
id: device.id,
217+
summary: `Device online: ${device.name}`,
218+
ts: new Date().getTime(),
219+
}));
220+
},
221+
async emitRemoteAccessSession({
222+
sessionType, technician,
223+
}) {
224+
const response = await this._makeRequest({
225+
path: "/device/{id}/activities",
226+
params: {
227+
sessionType,
228+
technician,
229+
},
230+
});
231+
response.forEach((session) => this.$emit(session, {
232+
id: session.id,
233+
summary: `Remote session initiated by ${session.technician}`,
234+
ts: new Date().getTime(),
235+
}));
9236
},
10237
},
238+
version: `0.0.${Date.now()}`,
11239
};

0 commit comments

Comments
 (0)