diff --git a/components/connectwise_psa/actions/create-contact/create-contact.mjs b/components/connectwise_psa/actions/create-contact/create-contact.mjs index 4ac0d16d6d05b..04dd9982095d7 100644 --- a/components/connectwise_psa/actions/create-contact/create-contact.mjs +++ b/components/connectwise_psa/actions/create-contact/create-contact.mjs @@ -1,10 +1,11 @@ +import { parseObjectEntries } from "../../common/utils.mjs"; import connectwise from "../../connectwise_psa.app.mjs"; export default { key: "connectwise_psa-create-contact", name: "Create Contact", description: "Creates a new contact in Connectwise. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Contacts/postCompanyContacts)", - version: "0.0.1", + version: "0.1.0", type: "action", props: { connectwise, @@ -91,6 +92,18 @@ export default { "country", ], }, + isDefault: { + type: "boolean", + label: "Primary Contact", + description: "Whether the contact is the primary (default) contact for the company", + optional: true, + }, + additionalOptions: { + type: "object", + label: "Additional Options", + 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.", + optional: true, + }, }, async run({ $ }) { const communicationItems = []; @@ -145,6 +158,8 @@ export default { id: this.department, } : undefined, + defaultFlag: this.isDefault, + ...(this.additionalOptions && parseObjectEntries(this.additionalOptions)), }, }); $.export("$summary", `Successfully created contact with ID: ${response.id}`); diff --git a/components/connectwise_psa/actions/create-ticket/create-ticket.mjs b/components/connectwise_psa/actions/create-ticket/create-ticket.mjs index 850a2d9d1f910..dc654a55d70f0 100644 --- a/components/connectwise_psa/actions/create-ticket/create-ticket.mjs +++ b/components/connectwise_psa/actions/create-ticket/create-ticket.mjs @@ -4,7 +4,7 @@ export default { key: "connectwise_psa-create-ticket", name: "Create Ticket", description: "Creates a new ticket in Connectwise. [See the documentation](https://developer.connectwise.com/Products/ConnectWise_PSA/REST#/Tickets/postServiceTickets)", - version: "0.0.1", + version: "0.1.0", type: "action", props: { connectwise, @@ -31,6 +31,23 @@ export default { "priority", ], }, + note: { + type: "string[]", + label: "Note(s)", + description: "Text content of one or more notes to add to the ticket", + optional: true, + }, + }, + methods: { + createTicketNote({ + id, ...args + }) { + return this.connectwise._makeRequest({ + method: "POST", + path: `/service/tickets/${id}/notes`, + ...args, + }); + }, }, async run({ $ }) { const response = await this.connectwise.createTicket({ @@ -52,7 +69,38 @@ export default { : undefined, }, }); - $.export("$summary", `Successfully created ticket with ID: ${response.id}`); - return response; + const { id } = response; + const { note } = this; + const createdNotes = []; + if (id && note?.length) { + const notes = Array.isArray(note) + ? note + : [ + note, + ]; + for (let note of notes) { + const response = await this.createTicketNote({ + $, + id, + data: { + text: note, + detailDescriptionFlag: true, + }, + }); + createdNotes.push(response); + } + } + const amountNotes = createdNotes.length; + $.export("$summary", `Successfully created ticket (ID: ${id})${amountNotes + ? ` and added ${amountNotes} notes` + : ""}`); + return { + ...(amountNotes + ? { + createdNotes, + } + : undefined), + ...response, + }; }, }; diff --git a/components/connectwise_psa/common/utils.mjs b/components/connectwise_psa/common/utils.mjs new file mode 100644 index 0000000000000..9c3cdbf569744 --- /dev/null +++ b/components/connectwise_psa/common/utils.mjs @@ -0,0 +1,22 @@ +function optionalParseAsJSON(value) { + try { + return JSON.parse(value); + } catch (e) { + return value; + } +} + +export function parseObjectEntries(value) { + const obj = typeof value === "string" + ? JSON.parse(value) + : value; + return Object.fromEntries( + Object.entries(obj).map(([ + key, + value, + ]) => [ + key, + optionalParseAsJSON(value), + ]), + ); +} diff --git a/components/connectwise_psa/package.json b/components/connectwise_psa/package.json index 12cb51c301656..1cba42742869e 100644 --- a/components/connectwise_psa/package.json +++ b/components/connectwise_psa/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/connectwise_psa", - "version": "0.1.1", + "version": "0.2.0", "description": "Pipedream Connectwise PSA Components", "main": "connectwise_psa.app.mjs", "keywords": [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b06348ad6990c..2fa3b1a7ab523 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1584,8 +1584,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/bloomerang: - specifiers: {} + components/bloomerang: {} components/blue: {} @@ -6172,8 +6171,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/hyperbrowser: - specifiers: {} + components/hyperbrowser: {} components/hyperise: dependencies: