-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
actionNew Action RequestNew Action RequestenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Description
Is there a specific app this action is for?
Zoho Desk
Please provide a link to the relevant API docs for the specific service / operation.
Following up on this thread #19403
Getting Zoho attachments seems to be possible via the route /tickets/${this.ticketId}/threads/${this.threadId}/attachments/${this.attachmentId}/content
when you add the organization ID to it. String made a working action for me :)
import zoho_desk from "@pipedream/zoho_desk"
import fs from "fs"
export default defineComponent({
name: "Get Thread Attachment",
description: "Retrieve attachment data from a Zoho Desk ticket thread and download it to /tmp directory",
type: "action",
props: {
zoho_desk,
orgId: {
propDefinition: [
zoho_desk,
"orgId",
],
},
ticketId: {
propDefinition: [
zoho_desk,
"ticketId",
],
},
threadId: {
propDefinition: [
zoho_desk,
"threadId",
({ ticketId, orgId }) => ({
ticketId,
orgId,
}),
],
},
attachmentId: {
type: "string",
label: "Attachment ID",
description: "The ID of the attachment to retrieve",
},
},
async run({ $ }) {
// First, get thread details to extract attachment information
const threadDetails = await this.zoho_desk.getThreadDetails({
$,
ticketId: this.ticketId,
threadId: this.threadId,
headers: {
orgId: this.orgId,
},
});
// Find the attachment in the thread details to get its name
const attachment = threadDetails.attachments?.find(att => att.id === this.attachmentId);
const attachmentName = attachment?.name || `attachment_${this.attachmentId}`;
// Get the attachment content
const response = await this.zoho_desk.makeRequest({
$,
path: `/tickets/${this.ticketId}/threads/${this.threadId}/attachments/${this.attachmentId}/content`,
headers: {
orgId: this.orgId,
},
params: {
inline: true,
},
responseType: "arraybuffer", // Handle binary data properly
});
// Create the file path in /tmp directory
const filePath = `/tmp/${attachmentName}`;
// Write the attachment content to the file
fs.writeFileSync(filePath, Buffer.from(response));
$.export("$summary", `Successfully downloaded attachment ${attachmentName} from thread ${this.threadId} to ${filePath}`);
return {
filePath,
fileName: attachmentName,
fileSize: response.byteLength,
attachmentId: this.attachmentId,
threadId: this.threadId,
ticketId: this.ticketId,
};
},
})
Metadata
Metadata
Assignees
Labels
actionNew Action RequestNew Action RequestenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Type
Projects
Status
Done