Master To Web
Sitecore, xDB

Meet the Sitecore API Console: Purging xDB Without Fear (or Postman)

A technician sorts through a cable-filled drawer labeled for xDB cleanup, surrounded by playful database-related notes.

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.)

The Sitecore API Console dashboard with the environment switcher open, showing Local, QA and Production environments and a sliced purge run at 60%
The dashboard: pick an environment, see what’s running, and get on with your day.

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:

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

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\..., not d:\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.

First launch: a blank slate with one very obvious button.

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:

Production gets red. This is the law.

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.

Recycle the login you already have.

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.

Browser sign-in: open the page, match the code, done.

Other options, for when the device flow doesn’t suit:

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.

All your instances in one place, each with its own connection status and token expiry.

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.

Every operation shows its HTTP method and endpoint, so there’s no guessing what it calls.

Before we push buttons, here’s a little vocabulary. You’ll see these fields across most forms:

FieldWhat it means
Cutoff daysContacts whose last activity (LastModified) was at least this many days ago.
Started days cutoffInteractions that started at least this many days ago.
Start / End percentileA sampling range from 0 to 1. 0–1 is everything; 0–0.1 is roughly 10%. Great for processing in chunks.
Batch sizeRecords read per cursor read. Smaller means gentler on SQL and quicker to cancel.
Default split item countHow 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.
ConditionsExtra 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.

1.28 million contacts inactive for a year. Somebody’s been busy. (Spoiler: it was bots.)

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:

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.

The “are you really, really sure” dialog. It’ll save you one day, maybe on a Friday at 4:55 PM.

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.

Live progress, no F5 required.

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:

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.

Big job, small bites.
SettingDefaultWhy you’d change it
Number of slices20More slices give smaller, safer tasks (20 slices means 0–0.05, 0.05–0.1, …).
Range start / end0 / 1Cover only part of the data today and the rest tomorrow.
Pause between slices (s)60Gives SQL time to recover between slices.
Retries per slice2Failed slices are registered again automatically.
Halve batch size on each retryOnRetries get gentler: 50 → 25 → 12.
On repeated failureStop the runOr 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.

Nine slices down, one to go. Very satisfying to watch.

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.

Back it up, then clean it up.

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.

Meet Jamie, our (entirely fictional) demo contact and Head of Espresso.

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

Configuration cheat sheet

Everything is optional and goes in .env.local. Start by copying .env.example.

VariableDefaultPurpose
SITECORE_APIS_SECRET_KEYgeneratedBase64 32-byte key for encrypting stored secrets.
SITECORE_APIS_DATA_DIR./dataWhere environments, the key and sliced-run state live.
SITECORE_APIS_ALLOWED_HOSTSlocalhost,127.0.0.1,[::1]Host names allowed to call the local API.
NEXT_PUBLIC_PURGE_MIN_DAYS180Purge minimum. Match it to your Processing Engine setting.
NEXT_PUBLIC_FEATURE_XDB_CONTACTSfalseTurns on the xDB Contacts tools.
NEXT_PUBLIC_XDB_CONTACTS_API_PATH/sitecore/api/xdbtools/contactsCM 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:

  1. Create src/lib/api-registry/categories/<name>.ts exporting an ApiCategory with sections, operations and fields.
  2. Add it to the categories array in src/lib/api-registry/index.ts (optionally behind a feature flag in src/lib/config.ts).
  3. 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

  1. Add QA first, not Production. Practise there.
  2. Run Estimate contacts with a 365-day cutoff to see how much is sitting there.
  3. Optionally Export contacts to a storage profile, just in case.
  4. Run Purge contacts with the Anonymous contacts condition, Run in slices ticked, 20 slices and a 60-second pause.
  5. Watch it on the Tasks page (or close the tab and go do something more fun).
  6. 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.

Related posts

Bug: Sitecore 8.1 Workflow Commands Do Not Work When Item Is Not Saved

Amir Setoudeh
11 years ago

Sitecore SXA partial design cache does not clear on publish

Amir Setoudeh
8 years ago

Create a View Component for Sitecore XM Cloud, using the ASP.NET Core SDK 

Amir Setoudeh
2 years ago
Exit mobile version