Skip to content

Commit d34e972

Browse files
Afstklaclaudemichelle0927
authored
Merging pull request #18502
* Add Set Custom Ticket Fields action for Zendesk Added new action to set one or more custom field values on a Zendesk ticket using the Zendesk API. Features: - Supports setting multiple custom fields in a single action - Accepts array of custom field objects with id and value properties - Includes validation for required properties - Supports custom subdomain for enterprise accounts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Bump version to 0.9.1 * updates * updates --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Michelle Bergeron <[email protected]>
1 parent a844abe commit d34e972

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import app from "../../zendesk.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
import { ConfigurationError } from "@pipedream/platform";
4+
5+
export default {
6+
key: "zendesk-set-custom-ticket-fields",
7+
name: "Set Custom Ticket Fields",
8+
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).",
9+
type: "action",
10+
version: "0.0.1",
11+
props: {
12+
app,
13+
ticketId: {
14+
propDefinition: [
15+
app,
16+
"ticketId",
17+
],
18+
},
19+
customFields: {
20+
type: "string[]",
21+
label: "Custom Fields",
22+
description: "Array of custom field objects. Each item should be formatted as `{\"id\": \"field_id\", \"value\": \"field_value\"}`. Example: `{\"id\": \"23129751115165\", \"value\": \"ABCDE\"}`",
23+
},
24+
customSubdomain: {
25+
propDefinition: [
26+
app,
27+
"customSubdomain",
28+
],
29+
},
30+
},
31+
methods: {
32+
updateTicket({
33+
ticketId, ...args
34+
} = {}) {
35+
return this.app.update({
36+
path: `/tickets/${ticketId}`,
37+
...args,
38+
});
39+
},
40+
},
41+
async run({ $: step }) {
42+
const {
43+
ticketId,
44+
customFields,
45+
customSubdomain,
46+
} = this;
47+
48+
// Parse custom fields from string array to objects
49+
const parsedCustomFields = parseObject(customFields);
50+
51+
if (!Array.isArray(parsedCustomFields)) {
52+
throw new ConfigurationError("Custom Fields must be an array of custom field objects");
53+
}
54+
55+
// Validate custom fields structure
56+
parsedCustomFields.forEach((field, index) => {
57+
if (!field.id) {
58+
throw new ConfigurationError(`Custom field at index ${index} is missing required "id" property`);
59+
}
60+
if (field.value === undefined) {
61+
throw new ConfigurationError(`Custom field at index ${index} is missing required "value" property`);
62+
}
63+
});
64+
65+
const response = await this.updateTicket({
66+
step,
67+
ticketId,
68+
customSubdomain,
69+
data: {
70+
ticket: {
71+
custom_fields: parsedCustomFields,
72+
},
73+
},
74+
});
75+
76+
step.export("$summary", `Successfully updated ${parsedCustomFields.length} custom field(s) on ticket ${response.ticket.id}`);
77+
78+
return response;
79+
},
80+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) {
3+
return {};
4+
}
5+
if (typeof obj === "string") {
6+
try {
7+
return JSON.parse(obj);
8+
} catch {
9+
return obj;
10+
}
11+
}
12+
if (Array.isArray(obj)) {
13+
return obj.map(parseObject);
14+
}
15+
if (typeof obj === "object") {
16+
return Object.fromEntries(Object.entries(obj).map(([
17+
key,
18+
value,
19+
]) => [
20+
key,
21+
parseObject(value),
22+
]));
23+
}
24+
return obj;
25+
};

components/zendesk/package.json

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

0 commit comments

Comments
 (0)