# Bulk Data export

> Export a group of patients' records as NDJSON files with FHIR Bulk Data Access 2.0 (Group/$export).

Backend Services apps can export a whole group of patients at once with **FHIR Bulk Data Access 2.0**. The export runs in the background; when it's done you download one or more **NDJSON** files per resource type. The files hold the same US Core resources the [API reference](/reference/patient.md) describes, limited to what the practice lets your app read.

## Before you start

- Your app must be a **Backend Services** app and sign in with [client_credentials](/authentication.md) and `system/` scopes, for example `system/*.read` or `system/Patient.rs system/Observation.rs`.
- Every request below, including downloading the files, needs your access token (`Authorization: Bearer`). Tokens last 5 minutes, so get a new one while you poll.

## Groups

`GET /Group` — The groups your app may export.

`GET /Group/{id}` — A group and its members (Patient references).

| Group id | Patients |
| --- | --- |
| `all` | Every patient your app may see (the practice's patients, narrowed to your app's location and provider limits). |
| `location-{Location id}` | Patients with a visit at that location. |
| `provider-{Practitioner id}` | Patients with a visit with that provider. |

## 1. Kick off

`GET /Group/{id}/$export` — Starts an export of the group's records.

*Request*

```text
https://qa3.somahealth.com/api/fhir/r4/{practice}/Group/all/$export?_type=Patient,Condition,Observation&_since=2026-01-01T00:00:00Z
Accept: application/fhir+json
Prefer: respond-async
Authorization: Bearer {access token}
```

| Parameter | What it does |
| --- | --- |
| `_type` | Resource types to export, comma-separated. Leave it out for every type your app may read (Schedule and Slot aren't exported). |
| `_since` | Only resources updated at or after this instant (resources without a last-updated time are always included). |
| `_outputFormat` | `application/fhir+ndjson` (the default; `application/ndjson` and `ndjson` are accepted). |

The answer is **202 Accepted** with a `Content-Location` header: your status URL. `Prefer: respond-async` is required. `_typeFilter`, `_elements`, `patient` and `includeAssociatedData` aren't supported and answer 400 unless you also send `Prefer: handling=lenient`. An app can have two exports running at once; a third answers **429** with `Retry-After`.

## 2. Check the status

`GET /bulk-status/{job}` — 202 while the export runs, 200 with the manifest when it's done.

While it runs you get **202** with `X-Progress` (for example `Observation (6 of 24 types): 40 of 120 patients`) and `Retry-After: 5`. When it's done you get **200** and the manifest; an export that failed answers 500 with an OperationOutcome.

*200 OK*

```json
{
  "transactionTime": "2026-12-03T15:04:05.000Z",
  "request": "{base}/Group/all/$export?_type=Patient,Condition",
  "requiresAccessToken": true,
  "output": [
    { "type": "Patient", "url": "{base}/bulk-files/{job}/Patient-1.ndjson", "count": 120 },
    { "type": "Condition", "url": "{base}/bulk-files/{job}/Condition-1.ndjson", "count": 342 }
  ],
  "error": []
}
```

## 3. Download the files

`GET /bulk-files/{job}/{file}` — One NDJSON file (application/fhir+ndjson): one resource per line.

Send your access token with each download. Large types are split into several files (about 20 MB each). Problems with part of an export (for example a type that couldn't be read) are listed under `error` as OperationOutcome files.

## 4. Finish or cancel

`DELETE /bulk-status/{job}` — Cancels a running export, or deletes a finished one's files now.

Files are kept for **24 hours** after the export finishes (the manifest's `Expires` header), then deleted; the status URL then answers 404. Files are encrypted at rest, and every kick-off, status check, download and cancel is in the practice's FHIR access log.

---
Last updated 2026-12-04 · Soma Health FHIR API
