Attachments and the rest API

Justin Naidl asked on June 24, 2016 15:43

I have 2 Attachment fields MyDocs and CustDocs on a page type. I have transforms setup that display them and setup the proper links to them and everything. The issue I am running into is when I delete them they still show up on the form tab of the page. This causes a problem because when a new version of the page is created it adds all the documents listed there despite one having been deleted.

I started to dig into the SQL a bit to see if I could reverse engineer whats happening. The CMS_Attachment record is being deleted but none of the history records.

The query it uses to populate the admin form as far as I can tell is:

WITH AllData AS 
(
SELECT [AttachmentHistoryID], [AttachmentGUID], [AttachmentImageWidth], [AttachmentImageHeight], [AttachmentExtension], [AttachmentName], [AttachmentSize], [AttachmentOrder], [AttachmentTitle], [AttachmentDescription], ROW_NUMBER() OVER (ORDER BY [AttachmentOrder], [AttachmentName], [AttachmentHistoryID]) AS [CMS_RN] 
FROM CMS_AttachmentHistory 
WHERE ([AttachmentHistoryID] IN (
SELECT [AttachmentHistoryID]
FROM CMS_VersionAttachment
WHERE [VersionHistoryID] = @VersionHistoryID
)) AND ([AttachmentGroupGUID] = @AttachmentGroupGUID)
) 
SELECT *, (SELECT COUNT(*) FROM AllData) AS [CMS_TOT] 
FROM AllData 
WHERE CMS_RN BETWEEN 1 AND 5 
ORDER BY CMS_RN

So, it's focused on the history as opposed to the current state. I've tried the following 2 urls for deleting the attachment.

  • https://testsite/rest/cms.attachment/282
  • https://testsite/rest/cms.attachment/282?destroyhistory=true

Both of them remove the attachment but none of the history so they still show up. What am I doing wrong? Also just in general can anybody point me to some resources on working with the rest api with attachments. They seem to behave differently than the rest of the api. I've come across https://bitwizards.com/blog/august-2013/retrieving-attachment-info-using-the-kentico-res, https://docs.kentico.com/display/API9/Attachments, and https://docs.kentico.com/display/K9/Manipulating+data+using+REST#ManipulatingdatausingREST-Uploadingattachmentfiles and did my best from there.

Thanks, ~Justin

   Please, sign in to be able to submit a new answer.