Skip to content

Bulk Data

OctoFHIR implements the FHIR Bulk Data Access IG in both directions:

  • $export writes resources to NDJSON files that a client downloads.
  • $bulk-submit and $bulk-submit-status let a data provider hand this server a manifest; the server fetches the files, validates each resource and stores it.

Both run as background jobs and follow the FHIR asynchronous request pattern. All paths below are under the FHIR base, /fhir.

bulk_export.spec_version selects which version of the IG $export follows. STU 4 removes parts of STU 3, so one endpoint cannot be exact for both.

[bulk_export]
spec_version = "stu3" # "stu3" (3.0.0, the default) or "stu4" (4.0.0-ballot)
stu3 stu4
Kick-off GET and POST POST only; GET is 405
Repeated values repeated or comma-delimited repeated; a comma is 400
includeAssociatedData in POST code (a Coding is accepted too) Coding
Manifest messages error outcome, with countSeverity
request in the manifest present absent
manifestType, outputFormat, fileSize in the manifest absent present

STU 3 is the published version. STU 4 is a ballot, not normative. $bulk-submit exists only in STU 4, but it works with either setting, and its status manifest always has the STU 4 shape.

The default file store is the local directory configured as bulk_export.export_path. To store system, Patient and Group exports in S3, select a bucket and a database-backed StorageProvider in the server configuration:

[bulk_export.s3]
provider = "fhir-exports"
bucket = "clinical-exports"

The provider holds the endpoint, region, addressing style and credential references. Set its exportBuckets array in the storage provider editor or /admin/StorageProvider to the private buckets that can receive exports. Existing exports keep the destination selected at kick-off.

To select an allowed destination for one export, provide both _storageProvider and _storageBucket. They override the optional default above. With neither a request destination nor a default, output goes to the local directory. The existing FHIR export permissions still apply.

GET /fhir/$export?_storageProvider=fhir-exports&_storageBucket=clinical-exports
Prefer: respond-async

For POST, send the same two names as valueString entries in FHIR Parameters. Changes to the provider’s allowed buckets apply to new exports without a restart. Create a private bucket and grant the provider PutObject, GetObject, DeleteObject and ListBucket for the bulk-export/ prefix. For RustFS use a path-style provider with the RustFS endpoint. For an internal HTTP endpoint, set allowHttp on that provider and allow its hostname in server.outbound_allowlist.

Finished files are uploaded before they appear in the manifest. The manifest still uses OctoFHIR URLs. OctoFHIR authorizes downloads and streams the objects from the bucket. Keep the configured local directory writable for temporary NDJSON files and partial manifest pages. Configure a bucket expiration policy for bulk-export/ to match the export retention period and remove objects left by interrupted jobs. A DELETE on the status URL also attempts to remove the job’s objects.

Export is available at three levels:

GET /fhir/$export
GET /fhir/Patient/$export
GET /fhir/Group/{id}/$export

Every level takes the same parameters, in the query of a GET or as a Parameters body of a POST. A stu4 server accepts only the POST.

GET /fhir/Patient/$export?_type=Patient,Observation&_since=2026-01-01T00:00:00Z
Authorization: Bearer {token}
Accept: application/fhir+json
Prefer: respond-async
POST /fhir/Group/cohort-1/$export
Authorization: Bearer {token}
Accept: application/fhir+json
Content-Type: application/fhir+json
Prefer: respond-async
{
"resourceType": "Parameters",
"parameter": [
{"name": "_type", "valueString": "Patient"},
{"name": "_type", "valueString": "Observation"},
{"name": "_typeFilter", "valueString": "Observation?status=final"},
{"name": "patient", "valueReference": {"reference": "Patient/123"}},
{"name": "includeAssociatedData", "valueCoding": {"code": "LatestProvenanceResources"}},
{"name": "allowPartialManifests", "valueBoolean": true}
]
}

The server answers 202 Accepted with the status URL in Content-Location:

HTTP/1.1 202 Accepted
Content-Location: https://fhir.example.org/fhir/_async-status/550e8400-e29b-41d4-a716-446655440000

The caller’s search grants decide what is exported. Without _type, the export covers every standard resource type the token may search. A _type value the token may not search is an error. If no type is left, the request is 403.

Parameter Value Behaviour
_outputFormat application/fhir+ndjson, application/ndjson or ndjson NDJSON is the only format; anything else is 400. One value.
_since instant Resources updated after this time. With system level exports it also fills deleted. One value.
_until instant Resources updated before this time. Must be later than _since. One value.
_type resource types Limits the export. A type the server does not know, or a non-standard type, is 400. At Patient and Group level a type outside the Patient compartment is 400.
_typeFilter Type?criteria Search criteria per type. Repeats for one type are OR. See below.
_elements element or Type.element Root elements to keep. See below.
patient Patient reference Limits a Patient or Group export to these patients. An absent patient, or one who is not a member of the Group, is 400. At system level the parameter is 400.
includeAssociatedData LatestProvenanceResources, RelevantProvenanceResources Adds Provenance of the exported resources. When both are given, Relevant wins. Other values are 400. Needs a search grant on Provenance.
organizeOutputBy Patient Output files of per-patient blocks. Other values are 400. One value.
allowPartialManifests boolean Manifest pages, available while the job runs. One value.

Any other parameter is 400. _since and _until compare with _lastUpdated, and a resource changed after the job started is left out, so the export stays consistent with transactionTime.

_typeFilter. The type must be one of the exported types, and the criteria must use search parameters known for that type (or _has). Parameters that shape a search response are refused: _sort, _count, _offset, _total, _summary, _elements, _format, _include and _revinclude.

GET /fhir/$export?_type=Observation&_typeFilter=Observation%3Fcode%3D8867-4

_elements. Only root elements are allowed, so Patient.name is valid and Patient.name.family is not. Patient.name applies to Patient, and name applies to every type that has it. The server always keeps resourceType, id, meta and the elements the type requires, and adds the SUBSETTED tag to each resource.

Provenance. A Patient or Group export that includes Provenance alongside other types follows the exported resources: it writes the Provenance that targets them, as RelevantProvenanceResources does, rather than searching Provenance on its own.

Unsupported input is refused by default. With Prefer: handling=lenient the job drops it and continues, and reports each item as a warning OperationOutcome in the error (or outcome) file of the manifest. This covers unknown parameters, unknown types, types outside the compartment, _elements, includeAssociatedData and organizeOutputBy values the server does not support, patient at system level, and absent patients. A request that leaves no patient to export is still 400.

Prefer: respond-async, handling=lenient
Status When Headers
202 Accepted The job is queued or running X-Progress (Processing: 40% complete), Retry-After: 10
429 Too Many Requests Polled again within bulk_export.min_poll_interval_ms Retry-After
200 OK Complete; the body is the manifest (application/json) Expires, Cache-Control: no-store
500 The job failed; the body is an OperationOutcome (application/fhir+json)
404 The job was deleted, expired or belongs to another caller

The 429 check applies to running jobs and counts per job. min_poll_interval_ms = 0 turns it off.

GET /fhir/_async-status/550e8400-e29b-41d4-a716-446655440000
Authorization: Bearer {token}

To cancel a job, or to say the files are no longer needed, send DELETE to the same URL. The server answers 202, removes the output files, and every later request to the URL is 404 with an OperationOutcome.

DELETE /fhir/_async-status/550e8400-e29b-41d4-a716-446655440000

With Prefer: respond-async, separate-export-status on the kick-off, the server confirms with Preference-Applied: respond-async, separate-export-status. From then on the status URL and manifest pages answer 200 OK, and the state of the job moves to the X-Export-Status header, for example X-Export-Status: 202 Accepted. HTTP status codes then describe the poll, not the job. A 429 is still a 429.

requiresAccessToken is true when the export was started with a token. Files are then read with a token of the same caller. Take file URLs from the manifest: file names carry a prefix of the job attempt, and only a type with at least one resource gets a file.

STU 3:

{
"transactionTime": "2026-11-06T10:15:00.123456+00:00",
"request": "https://fhir.example.org/fhir/$export?_type=Patient,Observation",
"requiresAccessToken": true,
"output": [
{"type": "Observation", "url": "https://fhir.example.org/fhir/_bulk-files/550e8400-.../...-Observation.ndjson", "count": 45000},
{"type": "Patient", "url": "https://fhir.example.org/fhir/_bulk-files/550e8400-.../...-Patient.ndjson", "count": 1500}
],
"error": []
}

STU 4:

{
"manifestType": "http://hl7.org/fhir/uv/bulkdata/StructureDefinition/BulkDataManifest",
"transactionTime": "2026-11-06T10:15:00.123456+00:00",
"requiresAccessToken": true,
"outputFormat": "application/fhir+ndjson",
"output": [
{"type": "Patient", "url": "https://fhir.example.org/fhir/_bulk-files/550e8400-.../...-Patient.ndjson", "count": 1500, "fileSize": 812345}
],
"outcome": [
{
"type": "OperationOutcome",
"url": "https://fhir.example.org/fhir/_bulk-files/550e8400-.../...-outcome.ndjson",
"count": 1,
"fileSize": 143,
"countSeverity": [{"code": "warning", "count": 1}]
}
]
}

With organizeOutputBy=Patient, both versions add "outputOrganizedBy": "Patient" and the items of output have no type. deleted appears only when there is something to list.

With allowPartialManifests=true the files spread over numbered pages of at most bulk_export.max_files_per_manifest output files, and a client can start downloading before the job ends.

  • While the job runs, the status URL answers 202 with the first page as soon as it exists.

  • A page that has a successor carries a link:

    {"link": [{"relation": "next", "url": "https://fhir.example.org/fhir/_async-status/550e8400-.../manifest/2"}]}
  • GET /fhir/_async-status/{id}/manifest/{page} reads a later page. The last page of a running job is 202, because it may still gain a next link; every other page is 200.

  • A published page only ever changes by gaining its next link. deleted and the message files are on the last page.

  • If a job is interrupted after publishing a page, it fails rather than rewrite what a client may already hold. Run the export again.

An export with _since lists resources deleted since then in deleted, as NDJSON files of transaction Bundles with one DELETE entry each:

{"resourceType": "Bundle", "type": "transaction", "entry": [{"request": {"method": "DELETE", "url": "Patient/123"}}]}

History keeps no search values for a deleted resource, so deleted is written only where the server can tell that the deletion matches the request: at system level, without organizeOutputBy, for types with no _typeFilter, and when the caller’s grant is not filtered. A resource written again after its deletion is in output and not here.

Files hold one JSON document per line and are served as application/fhir+ndjson:

GET /fhir/_bulk-files/{job}/{file}
Authorization: Bearer {token}

Only the caller that started the job can read them. With server.compression = true the server gzips a file for a client that asks for it.

Each resource type gets its own files, and a new file starts after bulk_export.max_resources_per_file resources. A type with more resources has several items in output.

organizeOutputBy=Patient writes blocks instead. A block is a Parameters header, then the Patient, then what references that Patient:

{"resourceType": "Parameters", "parameter": [{"name": "header", "valueReference": {"reference": "Patient/123"}}]}
{"resourceType": "Patient", "id": "123"}
{"resourceType": "Observation", "id": "obs-1", "subject": {"reference": "Patient/123"}}

A block stays in one file, so a file can pass the limit: the next file starts between blocks. A resource that references several exported patients is in each of their blocks. Resources that reference no exported Patient directly are left out, and the message file says how many. Types outside the Patient compartment are left out too, and those named in _type are reported. The caller needs a search grant on Patient.

The asynchronous pattern only defines per-job URLs. To find jobs started elsewhere, list the unexpired jobs of the caller, newest first:

GET /fhir/_async-status
Authorization: Bearer {token}
{
"jobs": [
{
"jobId": "550e8400-e29b-41d4-a716-446655440000",
"status": "in_progress",
"progress": 0.4,
"requestType": "bulk_export",
"requestMethod": "GET",
"requestUrl": "https://fhir.example.org/fhir/Patient/$export?_type=Observation",
"createdAt": "2026-10-31T18:55:42+00:00",
"expiresAt": "2026-11-01T18:55:42+00:00"
}
]
}

The Bulk data page of the web console is built on this list.

[bulk_export]
enabled = true
spec_version = "stu3"
export_path = "./exports" # where files are written
retention_hours = 24 # files older than this are removed
max_resources_per_file = 100000 # a new file starts after this many resources
max_files_per_manifest = 100 # output files per manifest page
batch_size = 1000 # rows per database read
min_poll_interval_ms = 1000 # 0 turns the 429 check off

Keep the transactionTime of each manifest and pass it as _since to the next export:

GET /fhir/$export?_type=Patient&_since=2026-11-06T10:15:00.123456Z
  • includeAssociatedData values other than the two Provenance codes.
  • organizeOutputBy with anything but Patient.
  • _minimumFileSize and _maximumFileSize.
  • Group export of a Group with actual=false or characteristic cohorts, and the Bulk Cohort API.
  • Capability URLs: a protected server always sets requiresAccessToken=true.
  • 429 on a second export from one client: export jobs queue.

$bulk-submit is the other direction. A data provider prepares a manifest in the shape $export produces and gives this server its URL. The server fetches the manifest and its files, validates each resource as a normal write would, and stores it. These operations are defined in STU 4 of the IG, at maturity level 2.

Submitters are agreed out of band. With no entries in bulk_submit.submitters, every submission is refused.

[bulk_submit]
enabled = true
[[bulk_submit.submitters]]
system = "https://example.org/submitters"
value = "provider-a"
client_id = "provider-a-backend" # optional: only this client may act as the submitter
provider_client_id = "octofhir-at-a" # optional: this server's client id at the provider
provider_scope = "system/*.read" # optional: scope requested from the provider
Key Meaning
system, value Must match the submitter identifier of a request, or the request is 403.
client_id The OAuth client allowed to act as this submitter. Without it, any client with the right grant may. A submission always stays with the client that opened it.
provider_client_id This server’s client id at the provider’s authorization server. Needed for oauthMetadataUrl.
provider_scope Scope this server requests from the provider. Default system/*.read.

Download and batch limits come from [bulk_import]: max_source_bytes, max_line_bytes, max_sources, max_errors, batch_size, max_batch_bytes and max_parallel_resources. Manifest and file URLs pass through the outbound policy (server.allow_private_outbound, server.outbound_allowlist), as $import sources do.

A token with the scope system/bulk-submit may run both operations and writes without per-resource grants: types are known only once a manifest is read. Add the scope to the client’s scopes and request it at the token endpoint. See SMART Backend Services.

A token without that scope but with some write permission may also submit, and each resource is then checked against its own grants. Any other token is 403.

POST /fhir/$bulk-submit
Authorization: Bearer {token}
Content-Type: application/fhir+json
{
"resourceType": "Parameters",
"parameter": [
{"name": "submitter", "valueIdentifier": {"system": "https://example.org/submitters", "value": "provider-a"}},
{"name": "submissionId", "valueString": "batch-2026-11"},
{"name": "manifestUrl", "valueUrl": "https://provider.example.org/exports/42/manifest.json"},
{"name": "fhirBaseUrl", "valueUrl": "https://provider.example.org/fhir"}
]
}

The answer is 200 OK with an informational OperationOutcome. The work runs in a background job, one per manifest.

Parameter Behaviour
submitter Identifier listed in bulk_submit.submitters. Required.
submissionId Unique per submitter. Several requests with the same id form one submission. Required.
submissionStatus Coding from http://hl7.org/fhir/event-status: in-progress (the default), completed or stopped.
manifestUrl Manifest to fetch. Unique within a submission; a repeat is 400.
fhirBaseUrl Base URL of the provider. Required with manifestUrl. References under it become local references.
replacesManifestUrl A manifest of this submission to take back.
outputFormat NDJSON only; anything else is 400.
fileRequestHeader Parts headerName and headerValue: a header sent when fetching the manifest and its files. Repeats.
oauthMetadataUrl Where to discover the provider’s token endpoint. Repeats. See below.
fileEncryptionKey Refused with 400.
metadata, import Accepted and ignored; the outcome file carries a warning. Only use-case IGs define them.

At least one of manifestUrl and submissionStatus is required. The server follows link in a manifest, so a paged manifest is read as one.

A submission stays open until the provider closes it:

{"name": "submissionStatus", "valueCoding": {"system": "http://hl7.org/fhir/event-status", "code": "completed"}}
  • completed says no more manifests will come. Manifests still running finish.
  • stopped cancels the running manifests and takes back what the submission wrote: created resources are deleted, and changed resources return to the version they had. A resource someone changed after the submission stays as it is, with a warning in the outcome file.

After either, further $bulk-submit requests for that submission are 409.

replacesManifestUrl takes back what that manifest wrote, the way stopped does. With a manifestUrl in the same request, the new manifest then runs. Without one, the old manifest is simply discarded. An unknown URL is 400.

fileRequestHeader sends fixed headers, such as an API key. The values are removed from the job when it ends.

{
"name": "fileRequestHeader",
"part": [
{"name": "headerName", "valueString": "Authorization"},
{"name": "headerValue", "valueString": "Bearer provider-issued-token"}
]
}

oauthMetadataUrl makes this server a SMART Backend Services client of the provider. It needs provider_client_id on the submitter; without it the request is 400.

  1. The server reads each metadata document until one names a token_endpoint.
  2. It signs a client assertion with its own key (auth.signing) and asks for provider_scope.
  3. It sends the token with the manifest requests, and with the file requests when a manifest sets requiresAccessToken. A token close to expiry is renewed.

SMART Backend Services assertions use RS384 or ES384, so set auth.signing.algorithm to one of them. The provider registers this server’s public keys, published at /auth/jwks.

  • Each resource is validated like a normal write. A reference to a resource in another file of the same manifest counts as present, so file order does not matter.
  • An invalid resource costs only itself. It is reported, and the rest is stored.
  • Resources keep the sender’s ids and are written with PUT. A submission can therefore change a local resource with the same id, and stopped restores it.
  • A file that cannot be downloaded is an error in the outcome file; the other files continue.
  • deleted files of a submitted manifest are not processed, and a warning says so.
  • Writes checkpoint, so an interrupted job resumes.

$bulk-submit-status starts a status request for a submission. The answer is 202 with Content-Location, like an export kick-off.

POST /fhir/$bulk-submit-status
Authorization: Bearer {token}
Content-Type: application/fhir+json
{
"resourceType": "Parameters",
"parameter": [
{"name": "submitter", "valueIdentifier": {"system": "https://example.org/submitters", "value": "provider-a"}},
{"name": "submissionId", "valueString": "batch-2026-11"}
]
}

Polling that URL gives the status manifest. It is 202 with what is known so far, with Retry-After: 10 and X-Progress: 1 of 2 manifests, until the submission is closed and every manifest is processed, then 200 with Expires. A submission never closed stays at 202. Prefer: separate-export-status and min_poll_interval_ms apply here as well.

{
"manifestType": "http://hl7.org/fhir/uv/bulkdata/StructureDefinition/BulkSubmitStatusManifest",
"submissionId": "batch-2026-11",
"transactionTime": "2026-11-06T11:02:10.481+00:00",
"requiresAccessToken": true,
"outputFormat": "application/fhir+ndjson",
"output": [],
"outcome": [
{
"url": "https://fhir.example.org/fhir/_bulk-files/7c9e6679-.../...-outcome.ndjson",
"count": 2,
"fileSize": 640,
"countSeverity": [{"code": "error", "count": 1}, {"code": "information", "count": 1}],
"manifestUrl": "https://provider.example.org/exports/42/manifest.json"
}
]
}

Each item is the outcome file of one manifest. A rejected resource is a line with its issues and the operationoutcome-sourceResource extension naming it under fhirBaseUrl. The last line of a file sums up the manifest: Manifest ...: 1200 resources stored, 3 rejected.

DELETE on the status URL ends that status request (202, then 404). The submission is not affected.

  • fileEncryptionKey.
  • 429 to delay a new submission.

The server is tested with the Inferno Bulk Data test kit (scripts/inferno/run-bulk.ts):

Suite Result
Bulk Data v2.0.0 export 48 of 48 pass
$bulk-submit consumer 15 of 18 pass

The three remaining $bulk-submit tests expect requests only during the kit’s wait step, while the server fetches files right after submission.