Skip to content

Add comprehensive tag management for Freshdesk tickets #17610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 44 additions & 0 deletions components/freshdesk/actions/add-ticket-tags/add-ticket-tags.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import freshdesk from "../../freshdesk.app.mjs";

export default {
key: "freshdesk-add-ticket-tags",
name: "Add Ticket Tags",
description: "Add tags to a ticket (appends to existing tags). [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
type: "action",
version: "0.0.1",
props: {
freshdesk,
ticketId: {
propDefinition: [
freshdesk,
"ticketId",
],
},
ticketTags: {
propDefinition: [
freshdesk,
"ticketTags",
],
description: "Array of tags to add to the ticket. These will be added to any existing tags.",
},
},
async run({ $ }) {
const {
ticketId,
ticketTags,
} = this;

if (!ticketTags || ticketTags.length === 0) {
throw new Error("At least one tag must be provided");
}

const response = await this.freshdesk.addTicketTags({
ticketId,
tags: ticketTags,
$,
});

$.export("$summary", `Successfully added ${ticketTags.length} tag(s) to ticket ${ticketId}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import freshdesk from "../../freshdesk.app.mjs";

export default {
key: "freshdesk-remove-ticket-tags",
name: "Remove Ticket Tags",
description: "Remove specific tags from a ticket. [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
type: "action",
version: "0.0.1",
props: {
freshdesk,
ticketId: {
propDefinition: [
freshdesk,
"ticketId",
],
},
ticketTags: {
propDefinition: [
freshdesk,
"ticketTags",
],
description: "Array of tags to remove from the ticket. Only these specific tags will be removed.",
},
},
async run({ $ }) {
const {
ticketId,
ticketTags,
} = this;

if (!ticketTags || ticketTags.length === 0) {
throw new Error("At least one tag must be provided");
}

const response = await this.freshdesk.removeTicketTags({
ticketId,
tags: ticketTags,
$,
});

$.export("$summary", `Successfully removed ${ticketTags.length} tag(s) from ticket ${ticketId}`);
return response;
},
};
44 changes: 44 additions & 0 deletions components/freshdesk/actions/set-ticket-tags/set-ticket-tags.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import freshdesk from "../../freshdesk.app.mjs";

export default {
key: "freshdesk-set-ticket-tags",
name: "Set Ticket Tags",
description: "Set tags on a ticket (replaces all existing tags). [See the documentation](https://developers.freshdesk.com/api/#update_ticket)",
type: "action",
version: "0.0.1",
props: {
freshdesk,
ticketId: {
propDefinition: [
freshdesk,
"ticketId",
],
},
ticketTags: {
propDefinition: [
freshdesk,
"ticketTags",
],
description: "Array of tags to set on the ticket. This will replace all existing tags.",
},
},
async run({ $ }) {
const {
ticketId,
ticketTags,
} = this;

if (!ticketTags || ticketTags.length === 0) {
throw new Error("At least one tag must be provided");
}

const response = await this.freshdesk.setTicketTags({
ticketId,
tags: ticketTags,
$,
});

$.export("$summary", `Successfully set ${ticketTags.length} tag(s) on ticket ${ticketId}`);
return response;
},
};
7 changes: 7 additions & 0 deletions components/freshdesk/actions/update-ticket/update-ticket.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ export default {
description: "Custom fields as key-value pairs (make sure types match your config)",
optional: true,
},
tags: {
propDefinition: [
freshdesk,
"ticketTags",
],
description: "Array of tags to set on the ticket. This will replace all existing tags.",
},
},
async run({ $ }) {
const {
Expand Down
74 changes: 74 additions & 0 deletions components/freshdesk/freshdesk.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ export default {
}));
},
},
ticketTags: {
type: "string[]",
label: "Tags",
description: "Array of tags to apply to the ticket. Each tag must be 32 characters or less.",
optional: true,
},
},
methods: {
setLastDateChecked(db, value) {
Expand Down Expand Up @@ -266,5 +272,73 @@ export default {
}
return input;
},
/**
* Set tags on a ticket (replaces all existing tags)
* @param {object} args - Arguments object
* @param {string|number} args.ticketId - The ticket ID
* @param {string[]} args.tags - Array of tags to set
* @returns {Promise<object>} API response
*/
async setTicketTags({
ticketId, tags, ...args
}) {
return this._makeRequest({
url: `/tickets/${ticketId}`,
method: "PUT",
data: {
tags,
},
...args,
});
},
/**
* Add tags to a ticket (appends to existing tags)
* @param {object} args - Arguments object
* @param {string|number} args.ticketId - The ticket ID
* @param {string[]} args.tags - Array of tags to add
* @returns {Promise<object>} API response
*/
async addTicketTags({
ticketId, tags, ...args
}) {
// Get current ticket to merge tags
const ticket = await this.getTicket({
ticketId,
...args,
});
const currentTags = ticket.tags || [];
const newTags = [...new Set([...currentTags, ...tags])]; // Remove duplicates

return this.setTicketTags({
ticketId,
tags: newTags,
...args,
});
},
/**
* Remove specific tags from a ticket
* @param {object} args - Arguments object
* @param {string|number} args.ticketId - The ticket ID
* @param {string[]} args.tags - Array of tags to remove
* @returns {Promise<object>} API response
*/
async removeTicketTags({
ticketId, tags, ...args
}) {
// Get current ticket to filter tags
const ticket = await this.getTicket({
ticketId,
...args,
});
const currentTags = ticket.tags || [];
const tagsToRemove = new Set(tags);
const remainingTags = currentTags.filter(tag => !tagsToRemove.has(tag));

return this.setTicketTags({
ticketId,
tags: remainingTags,
...args,
});
},
},
};