> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usehatchapp.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bulk Export API

> Export BI-ready Hatch datasets for analytics and data warehouses.

> [card] [Bulk Export Schema Overview](https://docs.usehatchapp.com/integrations/hatch-api/bulk-export/bulk-export-schema-overview.md)

## Authentication & onboarding

* Access is limited to **Enterprise** tier customers. Contact a Hatch Account Manager to enable the Bulk Export API for the organization.
* A **Manager** must create a reporting API key in **Settings → API Keys**.
* Every request must include the key in an `Authorization: Bearer <api-key>` header.

## How it works

The Bulk Export API is **asynchronous**. A client submits an export job, then
polls for its status until the file is ready to download:

**1. Submit an export job**

Send the dataset and date range. The response returns a `task_id`.

**2. Poll for status**

Request the job by its `task_id` until the `status` is `completed` (or `failed`).

**3. Download the export**

On completion, the response includes `file.url`, a short-lived presigned download URL for a compressed file. Fetch it before it expires.

## Filtering and incremental loads

Each dataset is filtered on one timestamp column. The date range you submit
selects rows whose filter column falls inside it, inclusive, in UTC.

| Dataset | Filter column | Row key | Load pattern |
| - | - | - | - |
| `contact_history` | `updated_at` | `contact_history_id` | Upsert. |
| `contact_history_v2` | `updated_at` | `contact_history_id` | Upsert. |
| `conversation_items` | `updated_at` | `id` | Upsert. |
| `leads` | `updated_at` | `lead_id` | Upsert. A lead re-appears whenever an outcome on it changes. |
| `attributions` | `event_at` | `attribution_id` | Append or upsert. |

A daily pull of yesterday's range therefore returns new rows and changed rows.
Do not treat it as "created yesterday."

`updated_at` moves only when one of the row's own timestamps moves. When Hatch
changes how a derived field is calculated, existing rows are recomputed in
place without a new `updated_at`. Hatch announces every such change; re-pull
the affected history after an announcement rather than relying on the daily
increment.

## Rate limits & constraints

* Data is refreshed nightly and is complete through the previous UTC day.
  Schedule pulls after **10:00 UTC**.
* Date ranges may not exceed **180 days**.
* Each dataset supports **one export per organization in any rolling 24
  hours**, counted from the accepted submission: one each for
  `contact_history`, `contact_history_v2`, `conversation_items`, `leads` and
  `attributions`. A job that ends `failed` releases the slot immediately.
  Re-submitting the identical request returns the original job rather than
  starting a new one. To load history, run one 180-day job per dataset at
  least 24 hours apart.
* **The job submission endpoint** is limited to **10 requests per minute** and
  **100 requests per day**, per organization.
* **The job retrieval endpoint** is limited to **1 request per second** and
  **300 requests per day**, per job.
* Retention: `contact_history` holds one year of history; `contact_history_v2`
  and `leads` hold two years; `conversation_items` and `attributions` hold
  full history.

### Rate-limit headers

Every authenticated response from the export-job endpoints includes the
current limit state. The values reflect the tightest active window (the one
with the fewest remaining requests). The headers are absent on `401`
responses.

| Header | Description |
| - | - |
| `RateLimit-Limit` | Maximum requests allowed in the active window. |
| `RateLimit-Remaining` | Requests remaining in the active window. |
| `RateLimit-Reset` | Seconds until the active window resets. |
| `Retry-After` | Sent only on `429` responses: seconds to wait before retrying. |

### Errors

Every error response carries a JSON body of the form
`{"detail": "<message>"}`. Validation failures (`422`) carry FastAPI's
field-level detail list instead of a single string.

| Status | `detail` |
| - | - |
| `401` | `invalid or missing API key` |
| `404` | `task not found` |
| `409` | `export already completed today for this data source` |
| `429` | `export request rate limit exceeded` (per-minute or per-second limit) or `daily export request limit reached` |

## Step 1 — Submit an export job

**Method & Path:** `POST /api/v2/exports/export-jobs`

Submit a JSON body describing the dataset, date range, and output format. The
endpoint is idempotent: an identical request returns the existing job instead of
creating a duplicate.

### Request body

| Field | Required | Description |
| - | - | - |
| `data_source` | Yes | Dataset to export. Allowed values: `contact_history`, `contact_history_v2`, `conversation_items`, `leads`, `attributions`. |
| `start_date` | Yes | Inclusive start date in `YYYY-MM-DD`. |
| `end_date` | Yes | Inclusive end date in `YYYY-MM-DD`. Must be on/after `start_date` and within 180 days of it. |
| `output_format` | No | `csv` for a CSV file (default), or `json` for newline-delimited JSON. |

### Example request

```bash theme={null}
curl -X POST "https://bulk-export-api.usehatchapp.com/api/v2/exports/export-jobs" \
  -H "Authorization: Bearer <api-key>" \
  -H "Content-Type: application/json" \
  -d '{
    "data_source": "contact_history",
    "start_date": "2025-10-30",
    "end_date": "2025-11-04",
    "output_format": "csv"
  }'
```

### Response

```json theme={null}
{ "task_id": "a1b2c3d4-..." }
```

| Status | Meaning |
| - | - |
| `202` | Job accepted. Poll the status endpoint with the returned `task_id`. |
| `200` | An identical request (same dataset, dates and format) is still running or completed within the last 24 hours. The original `task_id` is returned. |
| `422` | Invalid body (bad date format, `end_date` before `start_date`, range over 180 days, unsupported dataset or format). |
| `401` | Missing or invalid API key. |
| `409` | Another export of this dataset was accepted within the last 24 hours and has not failed. |
| `429` | Submitting too frequently. Retry after the `Retry-After` interval. |
| `500` | Unexpected server error. Retry with backoff. |

## Step 2 — Poll for status

**Method & Path:** `GET /api/v2/exports/export-jobs/{task_id}`

Poll this endpoint until the job reaches `completed` or `failed`. The endpoint
allows at most one request per second and 300 requests per day per job. When
the job is `completed`, the response includes `file.url`, a presigned download
URL.

### Example request

```bash theme={null}
curl "https://bulk-export-api.usehatchapp.com/api/v2/exports/export-jobs/a1b2c3d4-..." \
  -H "Authorization: Bearer <api-key>"
```

### Example response (completed)

```json theme={null}
{
  "task_id": "a1b2c3d4-...",
  "status": "completed",
  "data_source": "contact_history",
  "output_format": "csv",
  "created_at": "2025-11-05T09:00:00Z",
  "completed_at": "2025-11-05T09:00:12Z",
  "file": {
    "url": "https://...presigned-s3-url...",
    "size_bytes": 1048576,
    "row_count": 4096,
    "expired_at": null
  },
  "error": null
}
```

### Response fields

| Field | Description |
| - | - |
| `task_id` | The job identifier. |
| `status` | Job state. One of `in_progress`, `processing`, `completed`, `failed`. |
| `data_source` | The dataset being exported. |
| `output_format` | `csv` or `json`. |
| `created_at` | When the job was submitted. |
| `completed_at` | When the job finished (`null` until then). |
| `file` | Present when `completed`: `url` (presigned download URL; `null` once no more can be issued), `size_bytes`, `row_count` (data rows, excluding the CSV header), `expired_at` (informational; `null` until all 10 presigned download URLs have been used or 24 hours have passed since completion). |
| `error` | `"export failed"` when `status` is `failed`. On a `completed` job, `"presigned url issuance limit reached for export"` when all presigned download URLs have been used, or `"another request is in progress"` when two requests for the same job overlap. |

### Status values

| `status` | Meaning |
| - | - |
| `in_progress` / `processing` | The export is still running. Continue polling. |
| `completed` | The file is ready. Download it from `file.url`. |
| `failed` | The export failed. Submit a new job. |

| Status | Meaning |
| - | - |
| `200` | Returns the current job state (and `file.url` when completed). |
| `404` | No job exists for that `task_id` under your organization, or more than 48 hours have passed since the job's last activity. |
| `429` | Polling too frequently. Leave at least one second between requests. |

## Step 3 — Download the export

`file.url` points to a **gzip-compressed** file
(`Content-Type: application/gzip`): a CSV file (`.csv.gz`) by default, or
newline-delimited JSON (`.json.gz`) when `output_format` is `json`.

```bash theme={null}
curl -L "<file.url>" -o contact_history_2025-10-30_2025-11-04.csv.gz
gunzip contact_history_2025-10-30_2025-11-04.csv.gz
```

> [!WARNING]
>
> `file.url` is valid for roughly **60 seconds**. Polling again within that
> minute returns the same `file.url`; after it, a new one is issued. **At most 10
> presigned download URLs are issued per job.** Once they are used, `file.url`
> is `null` and the same request cannot be re-submitted until 24 hours after the
> original completed. The job, and with it the download, is available for 48
> hours after the last `file.url` was issued. Download promptly.

### File format

* **CSV:** UTF-8, header row, RFC 4180 quoting. Timestamp columns are
  RFC 3339 / ISO 8601 in UTC with six fractional digits,
  `YYYY-MM-DDTHH:MM:SS.ffffffZ`. Date columns are ISO 8601 `YYYY-MM-DD`.
  Booleans are `true` / `false`. Nulls are empty cells. An export with no
  matching rows produces an empty file with no header row.
* **JSON (newline-delimited):** one object per line. Timestamps and dates as
  above. Booleans `true` / `false`. Nulls `null`.

### Operational guidance

* Review the schema overview to inspect columns before mapping the export into a warehouse.
* Submit a job once, then poll `GET /api/v2/exports/export-jobs/{task_id}` with the returned `task_id` until the status is `completed` or `failed`.
* Plan for **one export per dataset in any rolling 24 hours**, and schedule pulls after 10:00 UTC.

## Deprecated: `GET /api/v1/export-data`

> [!WARNING]
>
> **v1 exports will be disabled on January 15, 2027.** After that date,
> `GET /api/v1/export-data` will stop returning data. Migrate existing
> integrations to the asynchronous v2 flow above before then.

> [accordion] Legacy synchronous endpoint (deprecated; use the v2 flow above)
>
> The original v1 endpoint returned the export synchronously as a ZIP archive.
> It is **deprecated** and will be disabled on January 15, 2027; new
> integrations should use the asynchronous v2 flow above. It remains
> documented here for existing integrations until then.
>
> v1 supports `contact_history` and `conversation_items` only. `contact_history_v2`,
> `leads` and `attributions` are v2-only.
>
> **Method & Path:** `GET https://bulk-export-api.usehatchapp.com/api/v1/export-data`
>
> Query parameters: `data_source` (required), `start_date` (required),
> `end_date` (required), and `output_format` (optional; defaults to `json` on v1).
>
> ```bash theme={null}
> curl -L "https://bulk-export-api.usehatchapp.com/api/v1/export-data?data_source=contact_history&start_date=2025-10-30&end_date=2025-11-04&output_format=csv" \
>   -H "Authorization: Bearer <api-key>" \
>   -o contact_history_2025-10-30_2025-11-04.zip
> ```
>
> The response body is a binary ZIP archive containing one data file,
> `{data_source}_{start_date}_{end_date}.csv` (or `.json` for newline-delimited JSON).
>
> **v1 file format differs from v2.** v1 CSV booleans are `True` / `False`, and
> v1 timestamps use a `+00:00` offset with fractional seconds present only when
> non-zero. Consumers moving from v1 CSV to v2 CSV should expect both to change.

### Next steps

1. Review the [Bulk Export schema overview](https://docs.usehatchapp.com/integrations/hatch-api/bulk-export/bulk-export-schema-overview.md) for the available export columns.
2. Request the Bulk Export API to be enabled for the organization through the Hatch Account Team.
3. Confirm API keys exist under **Settings → API Keys**.
4. Submit an export job, poll for completion, and download the export, planning for one export per dataset in any rolling 24 hours.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.