From 9719686060acfb5210b962dc5b88a7584a1018f0 Mon Sep 17 00:00:00 2001 From: Pierce McEntagart Date: Wed, 1 Mar 2023 18:42:35 -0500 Subject: [PATCH] Add support for ticket comment attachment redaction --- fixture/PUT/redact_ticket_comment_attachment.json | 11 +++++++++++ zendesk/attachment.go | 8 ++++++++ zendesk/attachment_test.go | 12 ++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 fixture/PUT/redact_ticket_comment_attachment.json diff --git a/fixture/PUT/redact_ticket_comment_attachment.json b/fixture/PUT/redact_ticket_comment_attachment.json new file mode 100644 index 00000000..d277ba61 --- /dev/null +++ b/fixture/PUT/redact_ticket_comment_attachment.json @@ -0,0 +1,11 @@ +{ + "attachment": { + "content_type": "application/binary", + "content_url": "https://company.zendesk.com/attachments/myfile.dat", + "file_name": "myfile.dat", + "id": 498483, + "size": 2532, + "thumbnails": [], + "url": "https://company.zendesk.com/api/v2/attachments/498483.json" + } +} diff --git a/zendesk/attachment.go b/zendesk/attachment.go index 6166a453..11cdb68a 100644 --- a/zendesk/attachment.go +++ b/zendesk/attachment.go @@ -196,3 +196,11 @@ func (z *Client) GetAttachment(ctx context.Context, id int64) (Attachment, error return result.Attachment, nil } + +// RedactCommentAttachment deletes an attachment with attachmentID on comment with commentID for ticket with ticketID +// https://developer.zendesk.com/api-reference/ticketing/tickets/ticket-attachments/#redact-comment-attachment +func (z *Client) RedactCommentAttachment(ctx context.Context, ticketID, commentID, attachmentID int64) error { + path := fmt.Sprintf("/api/v2/tickets/%d/comments/%d/attachments/%d/redact", ticketID, commentID, attachmentID) + _, err := z.put(ctx, path, nil) + return err +} diff --git a/zendesk/attachment_test.go b/zendesk/attachment_test.go index ddd60a0c..3d6199b2 100644 --- a/zendesk/attachment_test.go +++ b/zendesk/attachment_test.go @@ -118,3 +118,15 @@ func TestGetAttachment(t *testing.T) { t.Fatalf("Returned attachment does not have the expected ID %d. Attachment id is %d", expectedID, attachment.ID) } } + +func TestRedactCommentAttachment(t *testing.T) { + mockAPI := newMockAPI(http.MethodPut, "redact_ticket_comment_attachment.json") + client := newTestClient(mockAPI) + defer mockAPI.Close() + + err := client.RedactCommentAttachment(ctx, 123, 456, 789) + + if err != nil { + t.Fatalf("Failed to redact ticket comment attachment: %s", err) + } +}