Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import app from "../../zendesk.app.mjs";

export default {
key: "zendesk-set-custom-ticket-fields",
name: "Set Custom Ticket Fields",
description: "Sets one or more custom field values on a ticket. [See the documentation](https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#update-ticket).",
type: "action",
version: "0.0.1",
props: {
app,
ticketId: {
propDefinition: [
app,
"ticketId",
],
},
customFields: {
type: "string[]",
label: "Custom Fields",
description: "Array of custom field objects. Each item should be formatted as `{\"id\": \"field_id\", \"value\": \"field_value\"}`. Example: `{\"id\": \"23129751115165\", \"value\": \"ABCDE\"}`",
},
customSubdomain: {
propDefinition: [
app,
"customSubdomain",
],
},
},
methods: {
updateTicket({
ticketId, ...args
} = {}) {
return this.app.update({
path: `/tickets/${ticketId}`,
...args,
});
},
},
async run({ $: step }) {
const {
ticketId,
customFields,
customSubdomain,
} = this;

// Parse custom fields from string array to objects
const parsedCustomFields = customFields.map((field) => {
try {
return typeof field === "string"
? JSON.parse(field)
: field;
} catch (error) {
throw new Error(`Failed to parse custom field: ${field}. Each field must be valid JSON with "id" and "value" properties.`);
}
});

// Validate custom fields structure
parsedCustomFields.forEach((field, index) => {
if (!field.id) {
throw new Error(`Custom field at index ${index} is missing required "id" property`);
}
if (field.value === undefined) {
throw new Error(`Custom field at index ${index} is missing required "value" property`);
}
});

const response = await this.updateTicket({
step,
ticketId,
customSubdomain,
data: {
ticket: {
custom_fields: parsedCustomFields,
},
},
});

step.export("$summary", `Successfully updated ${parsedCustomFields.length} custom field(s) on ticket ${response.ticket.id}`);

return response;
},
};
2 changes: 1 addition & 1 deletion components/zendesk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/zendesk",
"version": "0.9.0",
"version": "0.9.1",
"description": "Pipedream Zendesk Components",
"main": "zendesk.app.mjs",
"keywords": [
Expand Down
Loading