Skip to content

Commit 5654d23

Browse files
ConnectWise actions improvements (#16091)
* pnpm * Adding isDefault field and flex additionalOptions field * Version bumps * Adding optional note creation to ticket * import path fix * Package bump * Update components/connectwise_psa/actions/create-contact/create-contact.mjs * Update components/connectwise_psa/actions/create-contact/create-contact.mjs --------- Co-authored-by: Leo Vu <[email protected]>
1 parent c60b18a commit 5654d23

File tree

4 files changed

+90
-5
lines changed

4 files changed

+90
-5
lines changed

components/connectwise_psa/actions/create-contact/create-contact.mjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { parseObjectEntries } from "../../common/utils.mjs";
12
import connectwise from "../../connectwise_psa.app.mjs";
23

34
export default {
45
key: "connectwise_psa-create-contact",
56
name: "Create Contact",
67
description: "Creates a new contact in Connectwise. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Contacts/postCompanyContacts)",
7-
version: "0.0.1",
8+
version: "0.1.0",
89
type: "action",
910
props: {
1011
connectwise,
@@ -91,6 +92,18 @@ export default {
9192
"country",
9293
],
9394
},
95+
isDefault: {
96+
type: "boolean",
97+
label: "Primary Contact",
98+
description: "Whether the contact is the primary (default) contact for the company",
99+
optional: true,
100+
},
101+
additionalOptions: {
102+
type: "object",
103+
label: "Additional Options",
104+
description: "Additional parameters to send in the request. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Contacts/postCompanyContacts) for available parameters. Values will be parsed as JSON where applicable.",
105+
optional: true,
106+
},
94107
},
95108
async run({ $ }) {
96109
const communicationItems = [];
@@ -145,6 +158,8 @@ export default {
145158
id: this.department,
146159
}
147160
: undefined,
161+
defaultFlag: this.isDefault,
162+
...(this.additionalOptions && parseObjectEntries(this.additionalOptions)),
148163
},
149164
});
150165
$.export("$summary", `Successfully created contact with ID: ${response.id}`);

components/connectwise_psa/actions/create-ticket/create-ticket.mjs

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "connectwise_psa-create-ticket",
55
name: "Create Ticket",
66
description: "Creates a new ticket in Connectwise. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Tickets/postServiceTickets)",
7-
version: "0.0.1",
7+
version: "0.1.0",
88
type: "action",
99
props: {
1010
connectwise,
@@ -31,6 +31,23 @@ export default {
3131
"priority",
3232
],
3333
},
34+
note: {
35+
type: "string[]",
36+
label: "Note(s)",
37+
description: "Text content of one or more notes to add to the ticket",
38+
optional: true,
39+
},
40+
},
41+
methods: {
42+
createTicketNote({
43+
id, ...args
44+
}) {
45+
return this.connectwise._makeRequest({
46+
method: "POST",
47+
path: `/service/tickets/${id}/notes`,
48+
...args,
49+
});
50+
},
3451
},
3552
async run({ $ }) {
3653
const response = await this.connectwise.createTicket({
@@ -52,7 +69,38 @@ export default {
5269
: undefined,
5370
},
5471
});
55-
$.export("$summary", `Successfully created ticket with ID: ${response.id}`);
56-
return response;
72+
const { id } = response;
73+
const { note } = this;
74+
const createdNotes = [];
75+
if (id && note?.length) {
76+
const notes = Array.isArray(note)
77+
? note
78+
: [
79+
note,
80+
];
81+
for (let note of notes) {
82+
const response = await this.createTicketNote({
83+
$,
84+
id,
85+
data: {
86+
text: note,
87+
detailDescriptionFlag: true,
88+
},
89+
});
90+
createdNotes.push(response);
91+
}
92+
}
93+
const amountNotes = createdNotes.length;
94+
$.export("$summary", `Successfully created ticket (ID: ${id})${amountNotes
95+
? ` and added ${amountNotes} notes`
96+
: ""}`);
97+
return {
98+
...(amountNotes
99+
? {
100+
createdNotes,
101+
}
102+
: undefined),
103+
...response,
104+
};
57105
},
58106
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function optionalParseAsJSON(value) {
2+
try {
3+
return JSON.parse(value);
4+
} catch (e) {
5+
return value;
6+
}
7+
}
8+
9+
export function parseObjectEntries(value) {
10+
const obj = typeof value === "string"
11+
? JSON.parse(value)
12+
: value;
13+
return Object.fromEntries(
14+
Object.entries(obj).map(([
15+
key,
16+
value,
17+
]) => [
18+
key,
19+
optionalParseAsJSON(value),
20+
]),
21+
);
22+
}

components/connectwise_psa/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/connectwise_psa",
3-
"version": "0.1.1",
3+
"version": "0.2.0",
44
"description": "Pipedream Connectwise PSA Components",
55
"main": "connectwise_psa.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)