我想通过Confluence API使用Python删除一页的附件,但它不提供此类API。有什么办法吗?enter image description here
Confluence API确实提供了获取页面附件列表(或文件名中的一个)并删除所有附件的可能性。为此,请尝试类似的操作(首先将JavaScript转换为Python):
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));