|
| 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"; |
1 | 11 | import ninjaone from "../../ninjaone.app.mjs"; |
2 | | -import { axios } from "@pipedream/platform"; |
3 | 12 |
|
4 | 13 | export default { |
5 | 14 | key: "ninjaone-create-ticket", |
6 | 15 | 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", |
9 | 18 | type: "action", |
10 | 19 | props: { |
11 | 20 | 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: { |
13 | 61 | 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", |
16 | 69 | }, |
17 | | - description: { |
| 70 | + descriptionBody: { |
18 | 71 | 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, |
21 | 75 | }, |
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: { |
23 | 95 | propDefinition: [ |
24 | 96 | ninjaone, |
25 | | - "ticketPriority", |
| 97 | + "status", |
26 | 98 | ], |
27 | 99 | }, |
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: { |
29 | 114 | propDefinition: [ |
30 | 115 | ninjaone, |
31 | | - "technician", |
| 116 | + "assignedAppUserId", |
32 | 117 | ], |
33 | 118 | optional: true, |
34 | 119 | }, |
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: { |
36 | 128 | 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 | + ], |
39 | 139 | optional: true, |
40 | 140 | }, |
41 | 141 | }, |
42 | 142 | 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 | + }); |
50 | 173 |
|
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 | + } |
53 | 179 | }, |
54 | 180 | }; |
0 commit comments