Every Sitecore XP instance has a junk drawer. It’s called xDB, and in it you’ll find millions of anonymous contacts from 2019, bots that visited 40,000 times, and that one load test somebody ran against production “just to be sure.” Today we’re going to clean out that drawer, and we won’t need a single curl command to do it.
Meet the Sitecore API Console: a small, open-source (MIT) web app that runs on your machine and puts friendly forms, confirmations and live progress bars in front of Sitecore’s xConnect Data Tools Web API. You sign in once per environment, then estimate, purge and export xDB data with buttons instead of hand-built bearer tokens.
This post walks through everything: installing it, connecting to your instances, running your first estimate, purging safely, splitting huge jobs into slices, and peeking inside individual contacts. Grab a coffee. (The demo data in the screenshots is coffee-themed, so it’ll feel right.)

Why does this exist?
Since Sitecore 10.2, the platform has shipped a very capable REST API for xDB housekeeping, the xConnect Data Tools (/sitecore/api/datatools). It can count contacts, purge old data and export to storage. It’s great. Using it by hand is less great:
- You need an OAuth token from Sitecore Identity Server first, so it’s off to Postman to fiddle with grant types.
- Purge tasks return a GUID, and you then poll a progress endpoint by hand, like a person refreshing a parcel-tracking page.
- Big purges can run for hours, and the SQL cursor can expire halfway with the dreaded “A cursor with the specified unique identifier does not exist.”
- And the scariest part: a request against Production looks exactly like one against Local. One wrong tab, one very bad afternoon.
The API Console fixes all four. The forms are generated from a typed registry of operations, every request is previewed before it’s sent, destructive actions make you type the environment’s name, and long-running work is tracked with live progress until it’s done.
What you’ll need
- Node.js 20 LTS or later (with npm).
- A Sitecore XP 10.2+ instance with the xConnect Data Tools Web API. Exports need a version that includes the Data Export Tool.
- A Sitecore user who is an administrator or a member of
sitecore\Sitecore XConnect Data Admin. - Network access from your machine to the CM and its Identity Server.
Notice what’s not on the list: no CM deployments, no config patches, no Identity Server changes. The core tools use APIs Sitecore already ships.
Install and run (about two minutes)
git clone <repository-url> sitecore-api-console
cd sitecore-api-console
npm install
npm run dev
Open http://127.0.0.1:3000. That’s it. The server listens only on 127.0.0.1, so your coworkers can’t use your console from across the office, however much they’d like to.
Prefer an optimized build? Use npm run build and then npm run start.
Windows tip: start the app from a path with the same letter casing as on disk (
D:\Projects\..., notd:\projects\...). Mismatched casing makes Next.js load its modules twice, so the app stops at startup and tells you the correct path. It’s very polite about it.
Step 1: Add an environment
An environment is one Sitecore instance: Local, QA, Production, “Dave’s VM that nobody is allowed to touch.” Click Add an environment and fill in:
- Name: shown everywhere, and it’s what you’ll type to confirm destructive actions.
- Color: purely a visual cue, but please make Production red. Future you will be grateful.
- CM URL: e.g.
https://xp.cm.local. All API calls go here. - Identity Server URL: the same “authority” you’d pass to
dotnet sitecore login. - Sign-in method, Client ID and Scope: the defaults work out of the box (more on that in a moment).
- Allow untrusted TLS certificates: for local dev instances with self-signed certs. Never tick this for Production.
Shortcut: import from the Sitecore CLI
Already logged in with the Sitecore CLI? On the Environments page, click Import from Sitecore CLI and pick your project’s .sitecore/user.json. The console picks up the endpoints and your existing login. Less typing all round.
Step 2: Sign in (no Identity Server changes, promise)
The default sign-in method is Browser sign-in. It uses the same OAuth device flow as dotnet sitecore login, with Sitecore’s built-in Device client. Because that client already exists on every Identity Server, you don’t need to register anything new.
Click Sign in, open the sign-in page, check the code matches, approve, and the console finishes automatically. It’s the “approve on your TV” experience, minus the TV.
Other options, for when the device flow doesn’t suit:
- Username & password: the OAuth password grant. Needs a client on Identity Server that allows it.
- Client credentials: non-interactive, e.g. the client you configured for CI with the Sitecore CLI.
Tick Stay signed in (or Save credentials) and the refresh token, password or secret is encrypted with AES-256-GCM and stored on your machine. Next time you open the app, it reconnects on its own.
The environment switcher in the sidebar decides where every request goes. It always shows the active environment’s name, colour and connection status, so you know where you’re pointing before you click anything.
Step 3: Take the tour
The xConnect Data Tools category is organised the way you’d actually work: Estimate → Purge → Export → Tasks. Destructive operations get a red dot in the sidebar and a red badge on their card. Subtle? No. Effective? Yes.
Before we push buttons, here’s a little vocabulary. You’ll see these fields across most forms:
| Field | What it means |
|---|---|
| Cutoff days | Contacts whose last activity (LastModified) was at least this many days ago. |
| Started days cutoff | Interactions that started at least this many days ago. |
| Start / End percentile | A sampling range from 0 to 1. 0–1 is everything; 0–0.1 is roughly 10%. Great for processing in chunks. |
| Batch size | Records read per cursor read. Smaller means gentler on SQL and quicker to cancel. |
| Default split item count | How the Processing Engine splits work between workers. Leave it at 100 unless someone wiser tells you otherwise. |
| Expires after (hours) | How long Sitecore keeps a finished task before tidying it away. |
| Conditions | Extra filters registered in the Cortex Processing Engine. All must pass (AND). They filter in memory, so they don’t reduce database reads. |
Step 4: Estimate first, then purge
Rule number one of data deletion: measure twice, cut once. Estimate contacts and Estimate interactions count what a filter matches without touching anything.
On the right of every form is a live Request preview: the method, full URL and JSON body that will be sent, updated as you type. It doubles as a learning tool. After a week you’ll know the Data Tools API by heart, whether you wanted to or not.
On a big database an estimate can take several minutes, so you’ll get a progress bar and a Stop waiting button meanwhile. One subtlety: estimates don’t accept conditions, so a purge with conditions will remove the same number or fewer.
Purge contacts ⚠️
Purge contacts registers a task that permanently deletes matching contacts along with their interactions. Useful knobs:
- Cutoff days is required, and it can’t go below the purge minimum (180 days by default). Sitecore’s Processing Engine enforces this in
sc.XConnect.DataPurge.Validation.xml, and the console checks it in the form too, so you find out before you send anything rather than after. - Conditions includes the built-in Anonymous contacts (
AnonymousCondition), which targets contacts without a known identifier. That’s the bot-cleanup special. You can add your own registered condition keys, and the console remembers them in your browser. - Batch size defaults to 100. Seeing SQL timeouts? Drop it to 25 and let the database breathe.
When you hit the big red button, the console shows you exactly what’s about to happen and asks you to type the environment name. Muscle memory can’t click through this one.
Once the task is registered, a live card tracks it: status (Pending → Processing → Completed), items processed, percentage, and a Cancel task button. Cancelling takes effect after the current batch, and anything already deleted stays deleted. There’s no undo in xDB, so bring snacks, not regrets.
Purge interactions ⚠️
Purge interactions removes old interactions but keeps the contacts. It adds some handy precision filters, each accepting up to 20 names or GUIDs:
- Delete if has events / Skip if has events: e.g. purge everything except interactions that triggered your “Purchase” outcome.
- Delete if has channels / Skip if has channels: e.g. purge only referral traffic and keep email campaigns.
Step 5: Run in slices (the headline feature)
Here’s the problem with purging 10 million interactions in one task: it runs for ages, it hammers SQL, and the cursor can expire partway through. That’s when you meet “A cursor with the specified unique identifier does not exist” and lose part of your day.
Run in slices is the console’s answer. Tick it under either purge form, and instead of one huge task the app registers a series of small tasks over consecutive percentile ranges, one at a time, with a breather between each.
| Setting | Default | Why you’d change it |
|---|---|---|
| Number of slices | 20 | More slices give smaller, safer tasks (20 slices means 0–0.05, 0.05–0.1, …). |
| Range start / end | 0 / 1 | Cover only part of the data today and the rest tomorrow. |
| Pause between slices (s) | 60 | Gives SQL time to recover between slices. |
| Retries per slice | 2 | Failed slices are registered again automatically. |
| Halve batch size on each retry | On | Retries get gentler: 50 → 25 → 12. |
| On repeated failure | Stop the run | Or skip the slice and carry on. |
The best part is that sliced runs are managed by the app’s server, not your browser tab. Close the browser, go to lunch, even restart the app: progress is saved to disk and the run picks up where it left off. You can Pause (the current slice finishes, then it waits), Resume, Retry failed slice, or Cancel, which also cancels the Sitecore task that’s currently running. To stop two runs fighting over the same database, only one sliced run can be active per environment.
Step 6: Watch it all on the Tasks page
The Tasks page collects everything in flight. Sliced runs come first, with a per-slice table (range, status, items, duration, attempts and task ID), followed by individually tracked tasks. Tasks registered from purge and export forms are tracked automatically. Got a task ID from somewhere else? Paste it into Task progress and click Track this task live.
Filter by Active or Finished, and use Clear finished when you want a clean slate. The sidebar badge shows how many things are running, and a toast pops up when a task completes, so you can safely work in another tab.
Step 7: Export before you delete (or just to keep a copy)
Export contacts and Export interactions use Sitecore’s Data Export Tool to write data, facets included, to a configured storage profile: a network share, Azure Blob or Azure File storage, as set up in sc.XConnect.DataTools.Workers.xml on your processing roles. The console remembers the last profile that worked. The age filters are optional here, and no purge minimum applies, because exporting never deleted anything.
Need a parameter the form doesn’t have? Click Edit JSON and send the raw request body yourself. The console doesn’t get in the way of power users.
Bonus round: xDB Contacts (opt-in)
Sometimes you don’t want to purge a million contacts. You want to look at one: the one Support asked about, or the “visitor” with 14,000 sessions. Sitecore has no built-in Web API for that, so this feature needs a small custom CM module (the xDB Contact Tools module) that exposes the xConnect Client API over HTTP. It’s off by default. Once the module is installed, enable it in .env.local:
NEXT_PUBLIC_FEATURE_XDB_CONTACTS=true
# Only if your module uses a different route:
NEXT_PUBLIC_XDB_CONTACTS_API_PATH=/sitecore/api/xdbtools/contacts
Restart the app (NEXT_PUBLIC_* values are applied at build time) and a new xDB Contacts section appears. View contact shows a whole profile on one page: name, emails, phones, identifiers (Known or Anonymous), merge history, raw facets, and a filterable list of interactions. Click an interaction to see its page views, goals and outcomes.
Delete contact removes one contact completely using xConnect DeleteContact, which is handy for “right to be forgotten” requests. A few things to know before you use it: deleting the root of a merge tree also deletes every contact merged into it (the viewer warns you), a contact with an active web session gets partly recreated when the session ends, device profiles are not removed, and the reporting database keeps the data until it’s rebuilt.
“But is it safe?” Glad you asked
- Your browser never talks to Sitecore directly. The app’s server gets the OAuth tokens and forwards the requests, so tokens and secrets never reach client-side JavaScript.
- Secrets are encrypted at rest with AES-256-GCM in the
data/folder and are never sent to the browser. Bring your own key withSITECORE_APIS_SECRET_KEY, or let the app generate one. - It only listens locally on
127.0.0.1, and middleware rejects unexpectedHostheaders (blocking DNS rebinding) and cross-origin writes. - Redirects aren’t followed on outbound calls, so your bearer token can’t be bounced off to somewhere unexpected.
- Destructive operations need you to type the environment name. Use distinct names and colours, and the app does the rest.
Configuration cheat sheet
Everything is optional and goes in .env.local. Start by copying .env.example.
| Variable | Default | Purpose |
|---|---|---|
SITECORE_APIS_SECRET_KEY | generated | Base64 32-byte key for encrypting stored secrets. |
SITECORE_APIS_DATA_DIR | ./data | Where environments, the key and sliced-run state live. |
SITECORE_APIS_ALLOWED_HOSTS | localhost,127.0.0.1,[::1] | Host names allowed to call the local API. |
NEXT_PUBLIC_PURGE_MIN_DAYS | 180 | Purge minimum. Match it to your Processing Engine setting. |
NEXT_PUBLIC_FEATURE_XDB_CONTACTS | false | Turns on the xDB Contacts tools. |
NEXT_PUBLIC_XDB_CONTACTS_API_PATH | /sitecore/api/xdbtools/contacts | CM route of the contact module. |
Generate a key with:
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
For the tinkerers: add your own APIs
Under the hood, every tool is a plain TypeScript definition in src/lib/api-registry. The sidebar, category pages, forms, validation, request previews, confirmations and server execution are all generated from those definitions. Adding a category goes like this:
- Create
src/lib/api-registry/categories/<name>.tsexporting anApiCategorywith sections, operations and fields. - Add it to the
categoriesarray insrc/lib/api-registry/index.ts(optionally behind a feature flag insrc/lib/config.ts). - Using a new icon? Map it in
src/components/icon.tsx.
Define a taskMonitor and operations that return a task ID are tracked live. Add a slicing setting and you get Run in slices for free. The stack is Next.js (App Router), TypeScript and Tailwind CSS, nothing exotic.
A sensible first-cleanup recipe
- Add QA first, not Production. Practise there.
- Run Estimate contacts with a 365-day cutoff to see how much is sitting there.
- Optionally Export contacts to a storage profile, just in case.
- Run Purge contacts with the Anonymous contacts condition, Run in slices ticked, 20 slices and a 60-second pause.
- Watch it on the Tasks page (or close the tab and go do something more fun).
- When you’re happy, repeat on Production. Carefully. It’s the red one.
Wrapping up
xDB housekeeping is one of those jobs everyone agrees is important and nobody wants to do, mostly because the tooling made it awkward and a little scary. The Sitecore API Console makes it less awkward and much less scary: you sign in once, estimate before you delete, confirm by name, slice big jobs into small ones, and watch it all happen live.
It’s MIT-licensed, so clone it, try it against a dev instance, and add your own APIs to the registry. And if it saves you from one accidental Friday-afternoon purge on Production, it’s done its job.
Happy purging! 🧹☕
How do I get started?
Visit the GitHub repo to use these tools today.
https://github.com/MasterToWeb/sitecore-api-console
Screenshots were taken against a local demo instance with fictional data. No real contacts (or baristas) were harmed.