Reputation: 21
I want to delete one page's attachments with Python by Confluence API but it doesn't provide such API. Is there any method? enter image description here
Upvotes: 0
Views: 306
Reputation: 1075
The Confluence API does provide a possibility to get the page attachment list (or a single one by its file name) and delete all one by one. To do so try something like this (converting JavaScript to Python first):
var headers = {
'Authorization': 'Basic <base64 encoded username:password>',
'X-Atlassian-Token': 'nocheck'
};
// this might differ depending on the server configuration:
var apiRoot = 'https://confluence.host.net/rest/api';
// page id:
var containerId = '171607042'
// get all attachments:
var getAttachmentsUrl = `${apiRoot}/content/${containerId}/child/attachment`;
// get only the one attachment:
var fileName = 'some.file';
getAttachmentsUrl += `?fileName=${encodeURIComponent(fileName)}`;
fetch(getAttachmentsUrl, {headers})
.then(r => r.json())
.then(o => Promise.all(o.results.map(
i=>fetch(i._links.self, {method: "DELETE", headers})
)))
.then(r => console.log('r', r));
Upvotes: 1