# CDR Anonymization

Source: https://docs.qvoice.net/api/cdr-anonymize/

This API removes personal data from the call records of one user over a time window. QVOICE Platform scrubs the call detail records (CDRs) of every call the user took part in during the window and deletes the SIP logs of those calls. An integration calls it when the person behind a shared extension changes, so the next person cannot see who the previous one called.

## What it does

For each call the user made or received in the window, every leg of the call is processed: the user's own leg, the carrier leg and any other leg of the same call.

| Data | Result |
| --- | --- |
| Party names (`caller_id_name`, `callee_id_name`, other-leg names) | Replaced with a label (default `Guest`). A name that is a number is masked like a number. |
| Party numbers (caller, callee, dialed number, E.164 destination, the user part of `to` / `from` / `request` / `presence_id`, the dialed number in `channel_name`) | Every digit replaced with `*`, for example `+14155550123` becomes `+***********`. |
| The user's own extension | Kept, so the record still shows which extension it belongs to. |
| Timing, duration, billing seconds, rates | Kept, so usage charges still reconcile. |
| SIP logs of the call | Deleted. A SIP trace carries the numbers in many headers, so it is removed rather than edited. |
| Call recordings | Not changed. |

Each scrubbed CDR gets a `fonouc_anonymized` object with the time, the job id and your `stay_id` reference. A later call for the same window skips these records, and rating jobs no longer touch them.

**Note:**

The database keeps older revisions of a changed or deleted document until the account's monthly database is compacted. Compaction removes them for good.

## Authentication

The endpoint needs an account admin user (`Authorization: Bearer <token>`) or an API key (`X-API-Key`). See [API Key Authentication](https://docs.qvoice.net/api/api-key-auth/).

| Header | Value |
| --- | --- |
| `X-API-Key` or `Authorization` | Your API key, or `Bearer <token>` of an admin user |
| `X-Account-ID` | The account ID. A reseller key can name one of its sub-accounts. |
| `Content-Type` | `application/json` |

## Flow

The request starts a background job. Poll the job until it ends.

```mermaid
sequenceDiagram
    participant App as Your integration
    participant API as QVOICE Platform API
    App->>API: POST /api/v2/hospitality/cdrs/anonymize
    API-->>App: 202 {job_id, status: queued}
    loop until completed or failed
        App->>API: GET /api/v2/reports/jobs/{job_id}/status
        API-->>App: status, anonymize_summary
    end
```

## Start an anonymization job

`POST /api/v2/hospitality/cdrs/anonymize`

### Request body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `user_id` | string | One of `user_id` or `user_ext` | The user ID. A disabled or deleted user still works, because the CDRs keep the user ID. |
| `user_ext` | string | One of `user_id` or `user_ext` | The user's extension. If both fields are sent, they must belong to the same user. |
| `start_date` | integer | Yes | Start of the window, Unix time in seconds (UTC). |
| `end_date` | integer | Yes | End of the window, Unix time in seconds (UTC). At most 93 days after `start_date`. |
| `stay_id` | string | No | Your own reference for this request (for example a booking or ticket number), up to 128 characters. Saved on every scrubbed record. |
| `label` | string | No | Text that replaces names, up to 64 characters. Default `Guest`. |
| `dry_run` | boolean | No | `true` counts what would change and writes nothing. Default `false`. |

A call belongs to the window when it ended between `start_date` and `end_date`.

### Example

```
curl -X POST "https://your-domain.com:9443/api/v2/hospitality/cdrs/anonymize" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "X-Account-ID: ACCOUNT_ID" \
  -H "Content-Type: application/json" \
  -d '{
    "user_ext": "4440",
    "start_date": 1764547200,
    "end_date": 1764763200,
    "stay_id": "RES-2026-118842"
  }'
```

### Response: 202 Accepted

```
{
  "job_id": "0c18664e-5171-4256-811e-ccd309984e37",
  "status": "queued",
  "estimated_time_seconds": 60,
  "created_at": 1764763210
}
```

### Errors

| Status | When | Body |
| --- | --- | --- |
| 400 | Invalid JSON, no `user_id` / `user_ext`, unknown `user_ext`, `user_ext` not matching `user_id`, missing or reversed dates, window over 93 days, `stay_id` or `label` too long | `{"error": "<reason>"}` |
| 401 | No valid credentials, or the user is not an account admin | empty |
| 500 | The job could not be created or queued; retry | text |

## Get the job status

`GET /api/v2/reports/jobs/{job_id}/status`

Use the same headers as the request that started the job.

```
curl "https://your-domain.com:9443/api/v2/reports/jobs/0c18664e-5171-4256-811e-ccd309984e37/status" \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "X-Account-ID: ACCOUNT_ID"
```

### Response: completed

```
{
  "job_id": "0c18664e-5171-4256-811e-ccd309984e37",
  "status": "completed",
  "progress": 100,
  "message": "CDR anonymization complete: 5 scanned, 5 anonymized, 0 already anonymized, 4 SIP logs deleted, 0 errors",
  "created_at": 1764763210,
  "anonymize_summary": {
    "scanned": 5,
    "anonymized": 5,
    "skipped": 0,
    "errors": 0,
    "dryRun": false,
    "sipLogsDeleted": 4
  }
}
```

| `status` | Meaning |
| --- | --- |
| `queued`, `processing` | Still running. Poll again in a few seconds. |
| `completed` | Every record of the window is anonymized. |
| `failed` | Part of the window could not be anonymized. `job_error` says why. Send the same request again. |

| `anonymize_summary` field | Meaning |
| --- | --- |
| `scanned` | Call records found for the window (all legs) |
| `anonymized` | Records scrubbed by this job (with `dryRun`: records that would be scrubbed) |
| `skipped` | Records already anonymized by an earlier job |
| `sipLogsDeleted` | SIP logs deleted (with `dryRun`: SIP logs that would be deleted) |
| `errors` | Records or SIP logs that could not be read, saved or deleted |
| `dryRun` | `true` when nothing was written |

## Retries

The job is safe to repeat. When a job ends `failed`, everything it could process is already anonymized; sending the same request again finishes the rest and skips what is done. A repeat after a `completed` job reports `anonymized: 0` and every record as `skipped`.

**Warning:**

Only `completed` means the window is fully anonymized. Treat `failed` as not done, and retry.
