Hi everyone,
I’m trying to keep only one version of an attachment in Confluence page but I’m kinda stuck.
My current approach to achieve this is to delete the old attachment and then upload the new one, but sometimes the delete just fails with this:
Unable to purge content with id: ContentId{id=642088971}
Here’s my delete code:
export const deleteAttachment = async (attachmentId) => {
return new Promise(async (resolve, reject) => {
try {
const response = await requestConfluence(
`/wiki/api/v2/attachments/${attachmentId}?purge=true`,
{ method: "DELETE" }
);
if (response.status >= 200 && response.status < 300) {
resolve(true);
} else {
reject(response);
}
} catch (error) {
reject(error);
}
});
};
Sometimes it works, sometimes it doesn’t… no idea why.
And just to add, I also create/update attachments like this:
const response = await requestConfluence(
`/wiki/rest/api/content/${pageId}/child/attachment?status=${isDraft ? "draft" : "current"}`,
{
method: "PUT",
body: payload,
}
);
But this keeps creating more and more versions of the same file and starts eating storage.
SO is there actually a proper way to only keep one attachment version? Or a correct API to replace an attachment without stacking infinite versions?
Any advice appreciated.