# Async bulk contact import

`POST /v1/contacts/bulk`

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

Submits a batch of up to 5 000 contacts for asynchronous upsert.
The endpoint returns immediately with a job id and `202 Accepted`;
poll `GET /v1/contacts/bulk/{job_id}` until `status` is `completed`
or `failed`.

Each row is processed independently — a single row's validation
failure (unknown attribute, bad email) marks that row `failed` while
the rest of the batch continues.  The overall job never returns `failed`
due to per-row errors.

Supports the `Idempotency-Key` header: a duplicate key within 24 h
replays the original 202.

## Request body

Content type: `application/json`

```json
{
  "contacts": [
    {
      "email": "user@example.com",
      "attributes": {},
      "unsubscribe_all": true,
      "topic_preferences": [
        {
          "topic_name": "string",
          "subscription_status": "OPT_IN"
        }
      ],
      "lists": {
        "add": [
          "00000000-0000-0000-0000-000000000000"
        ],
        "remove": [
          "00000000-0000-0000-0000-000000000000"
        ],
        "set": [
          "00000000-0000-0000-0000-000000000000"
        ]
      }
    }
  ]
}
```

## Example request

```bash
curl -X POST 'https://api.sendops.dev/v1/contacts/bulk' \
  -H "Authorization: Bearer $SENDOPS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contacts":[{"email":"user@example.com","attributes":{},"unsubscribe_all":true,"topic_preferences":[{"topic_name":"string","subscription_status":"OPT_IN"}],"lists":{"add":["00000000-0000-0000-0000-000000000000"],"remove":["00000000-0000-0000-0000-000000000000"],"set":["00000000-0000-0000-0000-000000000000"]}}]}'
```

## Responses

### 202 — Batch accepted for async processing

Content type: `application/json`

```json
{
  "job_id": "00000000-0000-0000-0000-000000000000",
  "status": "string",
  "total": 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"
    }
  ]
}
```

### 403 — Key lacks the required scope or plan limit violated

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"
    }
  ]
}
```

### 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"
    }
  ]
}
```

### 422 — Query parameter or path value failed validation

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"
    }
  ]
}
```

### 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"
    }
  ]
}
```

### 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"
    }
  ]
}
```
