How Can I Delete Old Attachments from a Workflow?

This topic was automatically generated from Slack. You can find the original thread here.

Hello or anyone who can help, is there a way for me to delete old attachments from a workflow?
I can’t delete an attachment so I uploaded another file with the same file name but it’s not being overridden. My workflow still uses the first attachment uploaded.

To delete old attachments from a workflow, you can use the Pipedream API to list and delete attachments. First, you’ll need to list the workflow’s executions using the GET /workflows/:id/executions endpoint. Then, for each execution, you can use the DELETE /executions/:id/attachments/:attachment_id endpoint to delete the specific attachment. Here’s an example of how to do this using the @pipedream/platform axios: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { pipedreamApiKey: { type: "string", label: "Pipedream API Key", secret: true, }, workflowId: { type: "string", label: "Workflow ID", }, }, async run({ $ }) { const apiRoot = "https://api.pipedream.com/v1"; const headers = { Authorization: `Bearer ${this.pipedreamApiKey}`, }; // List workflow executions const executionsResponse = await axios($, { method: "GET", url: `${apiRoot}/workflows/${this.workflowId}/executions`, headers, }); // Iterate through executions and delete attachments for (const execution of executionsResponse) { if (execution.attachments && execution.attachments.length > 0) { for (const attachment of execution.attachments) { await axios($, { method: "DELETE", url: `${apiRoot}/executions/${execution.id}/attachments/${attachment.id}`, headers, }); } } } return { message: "Attachments deleted" }; }, }); Replace pipedreamApiKey and workflowId with your own values. This code will list the executions of the specified workflow and delete any attachments associated with them.

WOAH awesome. Thanks!

This is not working

Yeah seems like this is not the legit answer. Can someone pls help with this concern :pray: Thank you