# Hospitality CDR Anonymization

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

At guest check-out, a hotel property management system (PMS) calls this API to remove the guest's personal data from the call records of the stay. QVOICE Platform scrubs the call detail records (CDRs) of every call the room's user took part in and deletes the SIP logs of those calls.

## What it does

For each call the room user made or received in the stay window, every leg of the call is processed: the room'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 room's own extension | Kept, so the record still shows which room 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`. A later call for the same stay 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 hotel's 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 PMS
    participant API as QVOICE Platform API
    PMS->>API: POST /api/v2/hospitality/cdrs/anonymize
    API-->>PMS: 202 {job_id, status: queued}
    loop until completed or failed
        PMS->>API: GET /api/v2/reports/jobs/{job_id}/status
        API-->>PMS: 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 room's 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 room's extension. If both fields are sent, they must belong to the same user. |
| `start_date` | integer | Yes | Start of the stay, Unix time in seconds (UTC). |
| `end_date` | integer | Yes | End of the stay (check-out), Unix time in seconds (UTC). At most 93 days after `start_date`. |
| `stay_id` | string | No | Your reservation or stay reference, 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 stay 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: HOTEL_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: HOTEL_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 stay is anonymized. |
| `failed` | Part of the stay could not be anonymized. `job_error` says why. Send the same request again. |

| `anonymize_summary` field | Meaning |
| --- | --- |
| `scanned` | Call records found for the stay (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 stay is fully anonymized. Treat `failed` as not done, and retry.
