@pipedream/zendesk 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -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
|
+
};
|
package/common/utils.mjs
ADDED
|
@@ -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
|
+
};
|