Skip to content

Commit d532f7f

Browse files
committed
[Components] ninjaone #14845
Sources - New Device Online (Instant) Actions - Create Ticket - Update Device
1 parent 8f8b225 commit d532f7f

File tree

12 files changed

+625
-480
lines changed

12 files changed

+625
-480
lines changed
Lines changed: 151 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,180 @@
1+
import { ConfigurationError } from "@pipedream/platform";
2+
import {
3+
PRIORITY_OPTIONS,
4+
SEVERITY_OPTIONS,
5+
TYPE_OPTIONS,
6+
} from "../../common/constants.mjs";
7+
import {
8+
normalCase,
9+
parseObject,
10+
} from "../../common/utils.mjs";
111
import ninjaone from "../../ninjaone.app.mjs";
2-
import { axios } from "@pipedream/platform";
312

413
export default {
514
key: "ninjaone-create-ticket",
615
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}}",
16+
description: "Creates a new support ticket in NinjaOne. [See the documentation](https://app.ninjarmm.com/apidocs/?links.active=core#/ticketing/create)",
17+
version: "0.0.1",
918
type: "action",
1019
props: {
1120
ninjaone,
12-
title: {
21+
clientId: {
22+
propDefinition: [
23+
ninjaone,
24+
"clientId",
25+
],
26+
},
27+
ticketFormId: {
28+
propDefinition: [
29+
ninjaone,
30+
"ticketFormId",
31+
],
32+
},
33+
organizationId: {
34+
propDefinition: [
35+
ninjaone,
36+
"organizationId",
37+
],
38+
optional: true,
39+
},
40+
locationId: {
41+
propDefinition: [
42+
ninjaone,
43+
"locationId",
44+
({ organizationId }) => ({
45+
organizationId,
46+
}),
47+
],
48+
optional: true,
49+
},
50+
nodeId: {
51+
propDefinition: [
52+
ninjaone,
53+
"deviceId",
54+
({ organizationId }) => ({
55+
organizationId,
56+
}),
57+
],
58+
optional: true,
59+
},
60+
subject: {
1361
type: "string",
14-
label: "Title",
15-
description: "Title of the support ticket",
62+
label: "Subject",
63+
description: "The subject of the ticket",
64+
},
65+
descriptionPublic: {
66+
type: "boolean",
67+
label: "Public Description",
68+
description: "Whether the ticket's description is public or not",
1669
},
17-
description: {
70+
descriptionBody: {
1871
type: "string",
19-
label: "Description",
20-
description: "Description of the support ticket",
72+
label: "Description Body",
73+
description: "The description of the ticket",
74+
optional: true,
2175
},
22-
priority: {
76+
descriptionHTML: {
77+
type: "string",
78+
label: "Description HTML",
79+
description: "The description HTML of the ticket",
80+
optional: true,
81+
},
82+
descriptiontimeTracked: {
83+
type: "integer",
84+
label: "Time Tracked",
85+
description: "Time in seconds",
86+
optional: true,
87+
},
88+
descriptionDuplicateInIncidents: {
89+
type: "boolean",
90+
label: "Duplicate In Incidents",
91+
description: "Whether the ticket will duplicate in the same incident",
92+
optional: true,
93+
},
94+
status: {
2395
propDefinition: [
2496
ninjaone,
25-
"ticketPriority",
97+
"status",
2698
],
2799
},
28-
assignedTechnician: {
100+
type: {
101+
type: "string",
102+
label: "Type",
103+
description: "The type of the ticket",
104+
options: TYPE_OPTIONS,
105+
optional: true,
106+
},
107+
cc: {
108+
type: "string[]",
109+
label: "CC",
110+
description: "A list of emails to be copied in the notification email",
111+
optional: true,
112+
},
113+
assignedAppUserId: {
29114
propDefinition: [
30115
ninjaone,
31-
"technician",
116+
"assignedAppUserId",
32117
],
33118
optional: true,
34119
},
35-
dueDate: {
120+
severity: {
121+
type: "string",
122+
label: "Severity",
123+
description: "The severity's level of the ticket",
124+
options: SEVERITY_OPTIONS,
125+
optional: true,
126+
},
127+
priority: {
36128
type: "string",
37-
label: "Due Date",
38-
description: "Due date for the support ticket. Format: YYYY-MM-DD",
129+
label: "Priority",
130+
description: "The priority's level of the ticket",
131+
options: PRIORITY_OPTIONS,
132+
optional: true,
133+
},
134+
tags: {
135+
propDefinition: [
136+
ninjaone,
137+
"tags",
138+
],
39139
optional: true,
40140
},
41141
},
42142
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-
});
143+
try {
144+
const {
145+
ninjaone,
146+
descriptionPublic,
147+
descriptionBody,
148+
descriptionHTML,
149+
descriptiontimeTracked,
150+
descriptionDuplicateInIncidents,
151+
cc,
152+
tags,
153+
...data
154+
} = this;
155+
156+
const response = await ninjaone.createSupportTicket({
157+
$,
158+
data: {
159+
...data,
160+
description: {
161+
public: descriptionPublic,
162+
body: descriptionBody,
163+
htmlBody: descriptionHTML,
164+
timeTracked: descriptiontimeTracked,
165+
duplicateInIncidents: descriptionDuplicateInIncidents,
166+
},
167+
cc: {
168+
emails: parseObject(cc),
169+
},
170+
tags: parseObject(tags),
171+
},
172+
});
50173

51-
$.export("$summary", `Ticket created successfully with ID ${response.id}`);
52-
return response;
174+
$.export("$summary", `Ticket created successfully with ID: ${response.id}`);
175+
return response;
176+
} catch ({ response }) {
177+
throw new ConfigurationError(normalCase(response.data.resultCode) || response.data);
178+
}
53179
},
54180
};
Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import ninjaone from "../../ninjaone.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "ninjaone-update-device",
65
name: "Update Device",
76
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}}",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
ninjaone,
@@ -14,20 +13,60 @@ export default {
1413
ninjaone,
1514
"deviceId",
1615
],
16+
description: "The Id of the device to update ",
1717
},
18-
deviceAttributes: {
18+
displayName: {
19+
type: "string",
20+
label: "Display Name",
21+
description: "The name of the device",
22+
optional: true,
23+
},
24+
nodeRoleId: {
1925
propDefinition: [
2026
ninjaone,
21-
"deviceAttributes",
27+
"nodeRoleId",
2228
],
23-
type: "string",
24-
label: "Device Attributes",
25-
description: "JSON string of attributes to update on the device",
29+
optional: true,
30+
},
31+
policyId: {
32+
propDefinition: [
33+
ninjaone,
34+
"policyId",
35+
],
36+
optional: true,
37+
},
38+
organizationId: {
39+
propDefinition: [
40+
ninjaone,
41+
"organizationId",
42+
],
43+
optional: true,
44+
},
45+
locationId: {
46+
propDefinition: [
47+
ninjaone,
48+
"locationId",
49+
({ organizationId }) => ({
50+
organizationId,
51+
}),
52+
],
53+
optional: true,
2654
},
2755
},
2856
async run({ $ }) {
29-
const response = await this.ninjaone.updateDevice(this.deviceId, this.deviceAttributes);
30-
$.export("$summary", `Successfully updated device with ID ${this.deviceId}`);
57+
const {
58+
ninjaone,
59+
deviceId,
60+
...data
61+
} = this;
62+
63+
const response = await ninjaone.updateDevice({
64+
$,
65+
deviceId,
66+
data,
67+
});
68+
69+
$.export("$summary", `Successfully updated device with ID ${deviceId}`);
3170
return response;
3271
},
3372
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const LIMIT = 100;
2+
3+
export const TYPE_OPTIONS = [
4+
"PROBLEM",
5+
"QUESTION",
6+
"INCIDENT",
7+
"TASK",
8+
];
9+
10+
export const SEVERITY_OPTIONS = [
11+
"NONE",
12+
"MINOR",
13+
"MODERATE",
14+
"MAJOR",
15+
"CRITICAL",
16+
];
17+
18+
export const PRIORITY_OPTIONS = [
19+
"NONE",
20+
"LOW",
21+
"MEDIUM",
22+
"HIGH",
23+
];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};
25+
26+
export const normalCase = (s) =>
27+
s?.replace (/^[-_]*(.)/, (_, c) => c.toUpperCase())
28+
.replace (/[-_]+(.)/g, (_, c) => " " + c);

0 commit comments

Comments
 (0)