The following script might help if you'd like to programmatically Delete some Orphaned Nodes (donot exist on Author) on Publish/Preview. It uses Sling Content Distribute (SCD) available on Author to make DELETE calls to Publish.
For deleting nodes on Stage/Prod Author (no CRXDe) check this post
1) Get Token for Author from Developer Console
2) Add the Author Host, Token and Path to delete (on Publish) in the following script...
const QS = require('querystring');
let AUTHOR_HOST = 'author-p99999-e999999.adobeaemcloud.com';
let AEM_TOKEN = "eyJhb......";
let PATH = "/content/eaem-random-test/us/en/jcr:content/root/container/container/helloworld";
(async () => {
await doDeleteUsingDistribute(PATH);
})();
async function doDeleteUsingDistribute(nodePath){
const postData = {
action: 'DELETE',
path: nodePath
};
let payload = QS.stringify(postData);
try {
const response = await fetch(`https://${AUTHOR_HOST}/libs/sling/distribution/services/agents/publish`, {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + AEM_TOKEN,
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
body: payload
});
if (response.ok) {
console.log(response.status + " : DELETED NODE USING SCD : " + nodePath);
} else {
console.log("ERROR : " + response.status + " : Failed to delete node using SCD : " + nodePath);
}
} catch (e) {
console.log("ERROR DISTRIBUTE DELETE : " + nodePath + " , " + e);
}
}


No comments:
Post a Comment