# Archive contacts in bulk

`POST /v1/contacts/bulk-archive`

- Authentication: required (Bearer token)
- Required scope: `api.contacts.manage`

Archives every contact that ONE selector names, each exactly as
`DELETE /v1/contacts/{email}` would: the contact leaves every List and
Segment and stops receiving mail, its visitor id stops resolving, and
the record is kept (an archive, not an erasure).

Send exactly one of:

- `emails` — up to 5 000 addresses;
- `external_ids` — up to 5 000 of your external ids;
- `list` — a static List, by id or key: its current members;
- `segment` — a Segment, by id or key: its members as of this request.
  A contact that enters the Segment afterwards is not archived;
- `ownership: "probable_copy"` — every probable copy in the contact
  ownership report (see `ownership` on `GET /v1/contacts`), with no
  cap. Available only to workspaces on SendOps-owned contacts; any
  other gets `422 ownership_report_unavailable`.

**Dry run first.** With `dry_run: true` the selector is resolved and
the answer is `200 {dry_run: true, matched}`; nothing is archived and
no job is recorded.

`matched` counts the contacts the selector names that exist in this
workspace, including ones already archived (only `emails` and
`external_ids` can name those). Addresses or ids with no contact are
not counted. At most 100 live contacts are archived inline and the
answer is `200` with the final counts; more are queued and the answer
is `202` with the job to poll on
`GET /v1/contacts/bulk-archive/{job_id}`.

Archiving frees plan capacity, so no plan limit applies. Counts
against this key's ordinary rate limit, once per request.

Supports the `Idempotency-Key` header: a duplicate key within 24 h
replays the original response and archives nothing more.

## Request body

Content type: `application/json`

```json
{
  "emails": [
    "user@example.com"
  ],
  "external_ids": [
    "string"
  ],
  "list": "string",
  "segment": "string",
  "ownership": "probable_copy",
  "dry_run": false
}
```

## Example request

```bash
curl -X POST 'https://api.sendops.dev/v1/contacts/bulk-archive' \
  -H "Authorization: Bearer $SENDOPS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"emails":["user@example.com"],"external_ids":["string"],"list":"string","segment":"string","ownership":"probable_copy","dry_run":false}'
```

## Responses

### 200 — Dry-run count, or the job when it ran inline

Content type: `application/json`

```json
{
  "dry_run": true,
  "matched": 0
}
```

### 202 — Archive queued; poll the job

Content type: `application/json`

```json
{
  "job_id": "00000000-0000-0000-0000-000000000000",
  "state": "pending",
  "matched": 0,
  "archived": 0,
  "already_archived": 0,
  "failed": 0
}
```

### 401 — Missing, malformed, or unknown API key

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 403 — Either the credential lacks the required scope (`code: invalid_scope`), or it is bound to the `test` environment and this operation is irreversible (`code: test_environment_forbidden`). Branch on `code`: the first is fixed by granting the scope, the second only by using a live credential. See the "Live and test credentials" section of the API description.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 404 — Resource not found

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 422 — A query parameter, path value or body field failed validation.

The body is a `validation_failed` Problem. When the refusal is about a
reference — a segment key, template slug, topic or attribute name the
organization does not have — it additionally carries `validation_code`,
`field`, `line`/`column`, `missing`, `candidates` and `next_step`, so a
client can correct the call without a second round of guessing. See
`ValidationProblem`.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ],
  "validation_code": "invalid_syntax",
  "field": "string",
  "line": 0,
  "column": 0,
  "missing": [
    {
      "kind": "segment",
      "key": "string"
    }
  ],
  "candidates": {},
  "next_step": "string"
}
```

### 429 — Per-org rate limit exceeded

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```

### 500 — Unexpected server-side failure. The `code` is `internal_error`. The
`request_id` field can be quoted to SendOps support to investigate.

Content type: `application/problem+json`

```json
{
  "type": "https://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "code": "invalid_key",
  "request_id": "string",
  "retry_after": 0,
  "retention_days": 0,
  "scope": "string",
  "resource": "string",
  "errors": [
    {
      "field": "string",
      "reason": "string"
    }
  ],
  "attribute_id": "00000000-0000-0000-0000-000000000000",
  "content_hash": "string",
  "differs": [
    "string"
  ]
}
```
