Skip to content

Instantly share code, notes, and snippets.

@ivanbuzyka
Created September 28, 2023 10:43
Show Gist options
  • Save ivanbuzyka/d1f7cbbd671948748dcf68db14e15c86 to your computer and use it in GitHub Desktop.
Save ivanbuzyka/d1f7cbbd671948748dcf68db14e15c86 to your computer and use it in GitHub Desktop.
HTML + JavaScript implementation for calling Sitecore xConnect purge API without authentication (HTML file should be run from within logged in CM browser session). This particular example calls POST contacts API, it can be extended to use other API and supply parameters
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Sitecore Purge API</title>
</head>
<body>
<h1>POST Request Example</h1>
<button id="purge-button">Purge</button>
<div id="response-panel" style="display: none;"></div>
<script>
const purgeButton = document.getElementById('purge-button');
const responsePanel = document.getElementById('response-panel');
purgeButton.addEventListener('click', function() {
const url = 'https://sitecore.cm/sitecore/api/datatools/purge/tasks/contacts';
const params = new URLSearchParams();
params.append('CutoffDays', '181');
params.append('BatchSize', '100');
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': document.cookie
},
body: params
})
.then(response => {
responsePanel.style.display = 'block';
response.text().then(text => {
responsePanel.innerHTML = text;
});
})
.catch(error => {
console.error('Error:', error);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment