Register the client application with the FHIR authorization server using asymmetric key registration (public/private key pair); store the private key securely and register the JWKS or JWKS URL with the authorization server.
Obtain a system-level access token via the SMART Backend Services client credentials flow: create a signed JWT client assertion and POST it to the token endpoint to receive a bearer token with the required system-level scopes (e.g., system/Group.read, system/Patient.read, and the resource type scopes needed).
Identify or create the FHIR Group resource representing the patient cohort; note the Group resource id.
Initiate the group-level bulk export: GET [base]/Group/[id]/$export with the Prefer: respond-async header and optionally _type, _since, or _typeFilter parameters to scope the export.
Receive the 202 Accepted response with a Content-Location header containing the polling URL; poll the polling URL periodically until a 200 response is returned with the export manifest (a JSON object listing output file URLs).
Download each NDJSON file from the output URLs using the access token; each file contains one resource type per line and represents the data for all members of the group.
Known gotchas
SMART Backend Services requires the authorization server to support the client_credentials grant with JWT assertion — verify this capability in the server's .well-known/smart-configuration before implementation.
The group-level $export exports data for all current members of the Group at the time of the request — ensure the Group resource membership is accurate and up to date before initiating the export.
Export jobs may run for extended periods for large groups; implement robust polling with appropriate retry intervals and handle 202 responses that include X-Progress headers indicating job status.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp