# Account data API

> Purge an account's captured data by kind, close the account now or at the end of the paid period, cancel a scheduled close, and read the history of both.

Source: https://www.apitraffic.io/docs/api-reference/account-data

These operations are what the **Danger zone** in the app calls. See [Purge data or close your account](https://www.apitraffic.io/docs/account-data) for what each one deletes and keeps.

**Permissions:** purging, closing and cancelling a close need the account **owner**, signed in to the app. A request made with an API token, by another member or admin, or from a support session is refused with `403`. Each one also needs the account name typed back in `confirm`, exactly as it appears in the app. Any member can read the history.

> **Warning:** A purge cannot be undone, and a closed account's data is permanently deleted 30 days after it closes.

## Purge data

`POST https://api.apitraffic.io/v1/accounts/{accountSid}/data/purge`

Starts deleting the kinds of data in `scopes`: captured traffic by default, or any mix up to a complete reset. The account stays open and keeps capturing new traffic. The work runs in the background; follow it in [Purge history](#purge-history).

A purge never reduces usage: requests already received still count toward the plan and are billed.

### Path parameters

- **accountSid (path, string, required)**:
  The account identifier.

### Body parameters

- **confirm (body, string, required)**:
  The account name, exactly as shown in the app.

- **scopes (body, string[], default ["traffic"])**:
  What to delete. Any of:

- `traffic`: captured requests, spans and server samples, and what was learned from them (API inventory, endpoint baselines, drift findings, issues, APM fingerprints)
- `saved`: collections, share links and stream views (views a workflow runs from are kept unless `automations` is chosen too)
- `settings`: exclusions, redaction rules, endpoint rules, WAF policies and block responses, events
- `automations`: workflows (with their webhooks and flows) and Git integrations

Buckets, environments, tokens, the team, and billing and activity history are always kept.

### Response

- **successful (boolean, required)**:
  `true` when the purge started.

- **accountSid (string, required)**:
  The account.

- **purgeSid (string, required)**:
  The purge's history record (`adp_…`).

- **status (string, required)**:
  `running`.

- **scopes (string[], required)**:
  What is being deleted.

- **purgedAt (string | null, required)**:
  The cutoff (ISO 8601): traffic captured at or before it is deleted. `null` when `traffic` is not in `scopes`.

```bash cURL
curl -X POST https://api.apitraffic.io/v1/accounts/acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa/data/purge \
  -H "Authorization: Bearer $APITRAFFIC_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "confirm": "Acme Store", "scopes": ["traffic", "saved"] }'
```

```js Node.js
const accountSid = 'acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa';
const response = await fetch(`https://api.apitraffic.io/v1/accounts/${accountSid}/data/purge`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.APITRAFFIC_SESSION_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ confirm: 'Acme Store', scopes: ['traffic', 'saved'] }),
});
const { purgeSid } = await response.json();
```

```json 200
{
  "successful": true,
  "accountSid": "acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa",
  "purgeSid": "adp_2hN5bV7cX9zL1kJ3gF6dS8aQ4wE",
  "status": "running",
  "scopes": ["traffic", "saved"],
  "purgedAt": "2026-10-20T10:02:11.000Z"
}
```

## Close account

`POST https://api.apitraffic.io/v1/accounts/{accountSid}/close`

Closes the account now, or when its paid period ends. A closed account stops capturing, nobody can sign in to it, every request for it answers `410`, and its data is permanently deleted 30 days after it closes.

### Path parameters

- **accountSid (path, string, required)**:
  The account identifier.

### Body parameters

- **when (body, string, required)**:
  `now` cancels the subscription and closes the account immediately, with a final invoice for usage over the plan this period (unused time is not refunded). `period_end` closes it when the paid period ends; an account in its trial has no paid period and gets `409`.

- **confirm (body, string, required)**:
  The account name, exactly as shown in the app.

### Response

- **successful (boolean, required)**:
  `true`.

- **accountSid (string, required)**:
  The account.

- **purgeSid (string, required)**:
  The close's history record.

- **status (string, required)**:
  `closed` (with `when: "now"`) or `scheduled` (with `when: "period_end"`).

- **closesAt (string)**:
  When a scheduled close takes effect (ISO 8601). Only for `scheduled`.

- **closedAt (string)**:
  When the account closed. Only for `closed`.

- **dataDeletedAfter (string)**:
  When the account's data is deleted. Only for `closed`.

```bash cURL
curl -X POST https://api.apitraffic.io/v1/accounts/acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa/close \
  -H "Authorization: Bearer $APITRAFFIC_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "when": "period_end", "confirm": "Acme Store" }'
```

```js Node.js
const accountSid = 'acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa';
const response = await fetch(`https://api.apitraffic.io/v1/accounts/${accountSid}/close`, {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.APITRAFFIC_SESSION_TOKEN}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ when: 'period_end', confirm: 'Acme Store' }),
});
const { status, closesAt } = await response.json();
```

```json 200
{
  "successful": true,
  "accountSid": "acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa",
  "purgeSid": "adp_2rF6tG8yH1uJ3iK5oL7pZ9xC4vB",
  "status": "scheduled",
  "closesAt": "2026-11-01T00:00:00.000Z"
}
```

## Keep the account

`DELETE https://api.apitraffic.io/v1/accounts/{accountSid}/close`

Cancels a close scheduled for the end of the paid period. The subscription renews as before. Refused with `409` once the close has started.

### Path parameters

- **accountSid (path, string, required)**:
  The account identifier.

### Response

- **successful (boolean, required)**:
  `true`.

- **accountSid (string, required)**:
  The account.

- **status (string, required)**:
  `open`.

```bash cURL
curl -X DELETE https://api.apitraffic.io/v1/accounts/acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa/close \
  -H "Authorization: Bearer $APITRAFFIC_SESSION_TOKEN"
```

```js Node.js
const accountSid = 'acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa';
await fetch(`https://api.apitraffic.io/v1/accounts/${accountSid}/close`, {
  method: 'DELETE',
  headers: { Authorization: `Bearer ${process.env.APITRAFFIC_SESSION_TOKEN}` },
});
```

```json 200
{
  "successful": true,
  "accountSid": "acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa",
  "status": "open"
}
```

## Purge history

`GET https://api.apitraffic.io/v1/accounts/{accountSid}/data/purges`

Lists every purge and close on the account, newest first: when, who asked, and how much was removed.

**Permissions:** any member, or a `user` or `administrator` API token.

### Path parameters

- **accountSid (path, string, required)**:
  The account identifier.

### Query parameters

- **limit (query, integer, default 20)**:
  Records to return, 1 to 100.

- **offset (query, integer, default 0)**:
  Records to skip.

### Response

- **limit (integer, required)**:
  The limit applied.

- **offset (integer, required)**:
  The offset applied.

- **records (object[], required)**:
  The history records.

**record**

- **sid (string)**: Record identifier.

- **operation (string)**: `purge` or `close`.

- **status (string)**: `scheduled`, `running`, `completed`, `partial` (completed with errors), `failed` or `cancelled`.

- **requestedBy (object)**: Who asked: `type` (`customer`, `staff` or `system`), `userSid` and `label`. Both are `null` when ApiTraffic support ran it.

- **closeWhen (string)**: For a close: `now` or `period_end`.

- **scopes (string[])**: What it deleted (a close deletes every kind).

- **records (object)**: Records deleted, by kind, for example `{"collections": 3, "exclusions": 2, "driftFindings": 14}`.

- **requestsDeleted (number)**: Captured requests deleted.

- **hostSamplesDeleted (number)**: Server sample files deleted.

- **bytesDeleted (number)**: Stored data deleted, in bytes.

- **objectsFailed (number)**: Stored objects that could not be deleted.

- **oldestDataAt (string)**: The oldest data removed (ISO 8601).

- **newestDataAt (string)**: The newest data removed (ISO 8601).

- **error (string | null)**: A short note for `partial` and `failed` records. Contact support for details.

- **scheduledFor (string)**: When scheduled work runs: a period-end close, or a closed account's data deletion.

- **startedAt (string)**: When it started.

- **completedAt (string)**: When it finished.

```bash cURL
curl "https://api.apitraffic.io/v1/accounts/acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa/data/purges?limit=20" \
  -H "Authorization: Bearer $APITRAFFIC_TOKEN"
```

```js Node.js
const accountSid = 'acc_2mXq7RbT4kPz9WvN3cHd8LsYfQa';
const response = await fetch(`https://api.apitraffic.io/v1/accounts/${accountSid}/data/purges?limit=20`, {
  headers: { Authorization: `Bearer ${process.env.APITRAFFIC_TOKEN}` },
});
const { records } = await response.json();
```

```json 200
{
  "records": [
    {
      "sid": "adp_2hN5bV7cX9zL1kJ3gF6dS8aQ4wE",
      "operation": "purge",
      "status": "completed",
      "requestedBy": { "type": "customer", "userSid": "usr_2jL4kM6nB8vC1xZ3aS5dF7gH9qW", "label": "Jordan Lee" },
      "scopes": ["traffic", "saved"],
      "records": { "collections": 2, "driftFindings": 14 },
      "requestsDeleted": 291040,
      "hostSamplesDeleted": 40210,
      "bytesDeleted": 1873200311,
      "objectsFailed": 0,
      "oldestDataAt": "2026-07-20T00:00:04.000Z",
      "newestDataAt": "2026-10-20T10:02:11.000Z",
      "error": null,
      "startedAt": "2026-10-20T10:02:11.000Z",
      "completedAt": "2026-10-20T10:19:40.000Z"
    }
  ],
  "limit": 20,
  "offset": 0
}
```

## Errors

| Status | Code | Meaning |
| --- | --- | --- |
| `400` | `2642` | `confirm` does not match the account name. |
| `400` | `2649` | `scopes` is empty or names an unknown kind. |
| `403` | `2010` | A member, or a `user` API token, tried to purge or close. |
| `403` | `2216` | Not the account owner, or not a signed-in session (for example an `administrator` API token). |
| `403` | `2070` | Made from a support (impersonated) session. |
| `409` | `2641` | The account cannot be closed that way: already scheduled, no paid period to run out, or already closing. |
| `409` | `2644` | The account's data is on hold. Contact support. |
| `409` | `2646` | A purge is already running. |
| `410` | `2640` | The account is already closed. |
| `503` | `2643` | The purge could not be started. Nothing was deleted; retry. |
| `503` | `2645` | Billing could not be reached, so the account was not closed. Retry in a few minutes. |

## Related

- [Purge data or close your account](https://www.apitraffic.io/docs/account-data):
    What each option deletes, and doing it in the app.

- [Plan, usage and billing](https://www.apitraffic.io/docs/account/billing):
    Plans, invoices and what happens at the end of a period.
