# Export conversation history

> Export a BloomText conversation's messages on a schedule and file them with the patient's record.

Source: https://www.bloomtext.com/developers/api/guides/export-history/

Exports package a conversation's messages into a downloadable file. Use them to archive texting history with the patient's chart or to meet a records request.

**You'll need:** an app user with `exports:write` and `exports:read` that participates in the conversations you export.

### Start the export

```bash filename="Request"
curl -X POST https://api.bloomtext.com/v1/conversations/e5c3b7b8-8f08-4d5a-9af1-0d11b0f4b7a0/exports \
  -H "Authorization: Bearer $BLOOMTEXT_API_KEY" \
  -H "Idempotency-Key: export:e5c3b7b8:2026-09" \
  -H "Content-Type: application/json" \
  -d '{"projection": "messages", "from": "2026-09-01T00:00:00Z", "to": "2026-09-30T23:59:59Z"}'
```

The response is `202 Accepted` with an [Export object](https://www.bloomtext.com/developers/api/reference/export-object/) in `queued` status.

### Wait for it to finish

Either listen for the [`export.ready`](https://www.bloomtext.com/developers/api/reference/webhook-events/#exportready) webhook, or poll [Retrieve an export](https://www.bloomtext.com/developers/api/reference/get-chat-export/) every 15 seconds until `status` is `ready`.

```js filename="wait-for-export.mjs"
async function waitForExport(exportId) {
  for (;;) {
    const exp = await fetch(`https://api.bloomtext.com/v1/exports/${exportId}`, {
      headers: { Authorization: `Bearer ${process.env.BLOOMTEXT_API_KEY}` },
    }).then((r) => r.json())

    if (exp.status === 'ready') return exp.download_url
    if (exp.status === 'failed') throw new Error(`Export ${exportId} failed`)
    await new Promise((r) => setTimeout(r, 15_000))
  }
}
```

```python filename="wait_for_export.py"
import os
import time

import requests


def wait_for_export(export_id: str) -> str:
    while True:
        exp = requests.get(
            f"https://api.bloomtext.com/v1/exports/{export_id}",
            headers={"Authorization": f"Bearer {os.environ['BLOOMTEXT_API_KEY']}"},
        ).json()
        if exp["status"] == "ready":
            return exp["download_url"]
        if exp["status"] == "failed":
            raise RuntimeError(f"Export {export_id} failed")
        time.sleep(15)
```

### Download and file it

The `download_url` is short-lived. Download it right away and upload the file to your EMR's document store with the patient's record.

> **Warning:** Exports contain PHI. Store downloaded files in the same protected systems as the rest of your patient records, and delete temporary copies.
